1+ <?php
2+
3+ namespace ChrisHalbert \PhpBCC \VCS ;
4+
5+ use ChrisHalbert \Git \Git ;
6+ use ChrisHalbert \PhpBCC \Exceptions \InvalidArrayFormatException ;
7+
8+ class GitVCSTest extends \PHPUnit_Framework_TestCase
9+ {
10+ protected $ git ;
11+
12+ protected $ gitVCS ;
13+
14+ public function setUp ()
15+ {
16+ $ this ->git = $ this ->getMockBuilder (Git::class)
17+ ->setMethods (['blameBus ' ])
18+ ->getMock ();
19+
20+ $ this ->gitVCS = new GitVCS ([], $ this ->git );
21+ }
22+
23+ public function testGetAuthorAndDate ()
24+ {
25+ $ this ->setValidMocks ();
26+ $ this ->gitVCS ->setEntries ($ this ->getEntries ());
27+ $ this ->assertEquals ($ this ->getExpectedEntriesWithHistory (), $ this ->gitVCS ->getEntries ());
28+ }
29+
30+ /**
31+ * @dataProvider dataProviderValidationFails
32+ */
33+ public function testValidationFails ($ entries , $ expectedException , $ exceptionMessage )
34+ {
35+ $ this ->setExpectedException ($ expectedException , $ exceptionMessage );
36+ $ this ->gitVCS ->setEntries ($ entries );
37+ }
38+
39+ public function dataProviderValidationFails ()
40+ {
41+ return [
42+ [
43+ [['1pair ' => 1 , '2pair ' => 2 , '3pair ' => 3 ]],
44+ InvalidArrayFormatException::class,
45+ 'Each entry should have only 2 key value pairs. '
46+ ],
47+ [
48+ [['1pair ' => 1 , '2pair ' => 2 ]],
49+ InvalidArrayFormatException::class,
50+ 'Each entry must have a `file` and a `line` key. '
51+ ]
52+ ];
53+ }
54+
55+ protected function setValidMocks ()
56+ {
57+ $ this ->git ->expects ($ this ->exactly (2 ))
58+ ->method ('blameBus ' )
59+ ->will (
60+ $ this ->onConsecutiveCalls (
61+ [
62+ "a1b2c3d4e5f6 " ,
63+ "author John " ,
64+ "author-mail <> " ,
65+ "author-time 1477980000 " ,
66+ "author-tz -0500 " ,
67+ "committer John " ,
68+ "committer-mail <> " ,
69+ "committer-time 1477980000 " ,
70+ "committer-tz -0500 " ,
71+ "summary Manufacture a test. " ,
72+ "previous f6e5d4c3d2a1 " ,
73+ "filename src/Foo.php " ,
74+ ],
75+ [
76+ "a1b2c3d4e5f6 " ,
77+ "author Kelly " ,
78+ "author-mail <> " ,
79+ "author-time 1478066400 " ,
80+ "author-tz -0500 " ,
81+ "committer Kelly " ,
82+ "committer-mail <> " ,
83+ "committer-time 1478066400 " ,
84+ "committer-tz -0500 " ,
85+ "summary Carve out instructions. " ,
86+ "previous f6e5d4c3d2a1 " ,
87+ "filename src/Foo.php " ,
88+ ]
89+ )
90+ );
91+ }
92+
93+ protected function getExpectedEntriesWithHistory ()
94+ {
95+ return [
96+ [
97+ 'author ' => 'John ' , 'date ' => '2016-11-01 ' , 'file ' => 'Foo.php ' , 'line ' => 1
98+ ],
99+ [
100+ 'author ' => 'Kelly ' , 'date ' => '2016-11-02 ' , 'file ' => 'Bar.php ' , 'line ' => 2
101+ ]
102+ ];
103+ }
104+
105+ protected function getEntries ()
106+ {
107+ return [
108+ [
109+ 'file ' => 'Foo.php ' ,
110+ 'line ' => 1
111+ ],
112+ [
113+ 'file ' => 'Bar.php ' ,
114+ 'line ' => 2
115+ ]
116+ ];
117+ }
118+ }
0 commit comments