1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace uuf6429\ElderBrother; |
4
|
|
|
|
5
|
|
|
class GitProjectTest extends BaseProjectTest |
6
|
|
|
{ |
7
|
|
|
public function testInstallation() |
8
|
|
|
{ |
9
|
|
|
$this->assertCommandSuccessful('git init'); |
10
|
|
|
$this->assertCommandSuccessful('git config user.email "[email protected]"'); |
11
|
|
|
$this->assertCommandSuccessful('git config user.name "John Doe"'); |
12
|
|
|
|
13
|
|
|
$this->assertNotFalse( |
14
|
|
|
file_put_contents('.git/hooks/post-commit', 'echo "OK"'), |
15
|
|
|
'Create fake "old" hook.' |
16
|
|
|
); |
17
|
|
|
|
18
|
|
|
$this->assertCommandSuccessful(self::getEbCmd() . 'install'); |
19
|
|
|
|
20
|
|
|
$this->assertTrue( |
21
|
|
|
file_exists('.git/hooks/pre-commit'), |
22
|
|
|
'Pre-commit hook was not installed successfully.' |
23
|
|
|
); |
24
|
|
|
|
25
|
|
|
$this->assertTrue( |
26
|
|
|
file_exists('.git/hooks/post-commit.bak'), |
27
|
|
|
'Ensure "old" hook has been backed up.' |
28
|
|
|
); |
29
|
|
|
|
30
|
|
|
$config = sprintf( |
31
|
|
|
'<%s return [%s => [%s]];', |
32
|
|
|
'?php', |
33
|
|
|
Event\Git::class . '::PRE_COMMIT', |
34
|
|
|
sprintf( |
35
|
|
|
'new %s( %s::getAdded() )', |
36
|
|
|
Action\PhpLinter::class, |
37
|
|
|
Change\GitChangeSet::class |
38
|
|
|
) |
39
|
|
|
); |
40
|
|
|
$this->assertNotFalse(file_put_contents('.brother.php', $config)); |
41
|
|
|
} |
42
|
|
|
|
43
|
|
|
/** |
44
|
|
|
* @depends testInstallation |
45
|
|
|
*/ |
46
|
|
|
public function testCommittingGoodCode() |
47
|
|
|
{ |
48
|
|
|
$this->assertNotFalse(file_put_contents('test1.php', '<php echo "Hi!";')); |
49
|
|
|
|
50
|
|
|
$this->assertCommandSuccessful('git add .'); |
51
|
|
|
$this->assertCommandSuccessful('git commit -m test1'); |
52
|
|
|
} |
53
|
|
|
|
54
|
|
|
/** |
55
|
|
|
* @depends testCommittingGoodCode |
56
|
|
|
*/ |
57
|
|
|
public function testCommittingBadCode() |
58
|
|
|
{ |
59
|
|
|
$this->assertNotFalse(file_put_contents('test2.php', '<?php 3ch"o')); |
60
|
|
|
|
61
|
|
|
$this->assertCommandSuccessful('git add .'); |
62
|
|
|
$this->assertCommand('git commit -m test2', 1); |
63
|
|
|
} |
64
|
|
|
|
65
|
|
|
/** |
66
|
|
|
* @depends testCommittingGoodCode |
67
|
|
|
* @depends testCommittingBadCode |
68
|
|
|
*/ |
69
|
|
|
public function testUninstallation() |
70
|
|
|
{ |
71
|
|
|
$this->assertCommandSuccessful(self::getEbCmd() . 'uninstall'); |
72
|
|
|
|
73
|
|
|
$this->assertFalse( |
74
|
|
|
file_exists('.git/hooks/pre-commit'), |
75
|
|
|
'Pre-commit hook was not uninstalled successfully.' |
76
|
|
|
); |
77
|
|
|
|
78
|
|
|
$this->assertTrue( |
79
|
|
|
file_exists('.git/hooks/post-commit'), |
80
|
|
|
'Ensure "old" hook has been restored.' |
81
|
|
|
); |
82
|
|
|
} |
83
|
|
|
} |
84
|
|
|
|