aboutsummaryrefslogtreecommitdiffstats
path: root/library/kzykhys/git/test/PHPGit/Command/ShortlogCommandTest.php
blob: 48967cab15b386bc528167d71bd993bb138ca7fb (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
<?php

use PHPGit\Git;
use Symfony\Component\Filesystem\Filesystem;

require_once __DIR__ . '/../BaseTestCase.php';

class ShortlogCommandTest extends BaseTestCase
{

    public function testShortlog()
    {
        $filesystem = new Filesystem();

        $git = new Git();
        $git->init($this->directory);
        $git->setRepository($this->directory);
        $git->config->set('user.name', 'Name One');
        $git->config->set('user.email', 'one@example.com');
        $filesystem->dumpFile($this->directory . '/test.txt', '');
        $git->add('test.txt');
        $git->commit('1');
        $filesystem->dumpFile($this->directory . '/test2.txt', '');
        $git->add('test2.txt');
        $git->commit('2');

        $git->config->set('user.name', 'Name Two');
        $git->config->set('user.email', 'two@example.com');
        $filesystem->dumpFile($this->directory . '/test3.txt', '');
        $git->add('test3.txt');
        $git->commit('3');

        $shortlog = $git->shortlog();

        $this->assertCount(2, $shortlog);
        $this->assertCount(2, $shortlog['Name One <one@example.com>']);
        $this->assertCount(1, $shortlog['Name Two <two@example.com>']);
        $this->assertEquals('1', $shortlog['Name One <one@example.com>'][0]['subject']);
    }

    public function testShortlogSummary()
    {
        $filesystem = new Filesystem();

        $git = new Git();
        $git->init($this->directory);
        $git->setRepository($this->directory);
        $git->config->set('user.name', 'Name One');
        $git->config->set('user.email', 'one@example.com');
        $filesystem->dumpFile($this->directory . '/test.txt', '');
        $git->add('test.txt');
        $git->commit('1');
        $filesystem->dumpFile($this->directory . '/test2.txt', '');
        $git->add('test2.txt');
        $git->commit('2');

        $git->config->set('user.name', 'Name Two');
        $git->config->set('user.email', 'two@example.com');
        $filesystem->dumpFile($this->directory . '/test3.txt', '');
        $git->add('test3.txt');
        $git->commit('3');

        $summary = $git->shortlog->summary();

        $this->assertEquals(array(
            'Name One <one@example.com>' => 2,
            'Name Two <two@example.com>' => 1
        ), $summary);
    }

}