1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace uuf6429\ElderBrother; |
4
|
|
|
|
5
|
|
|
abstract class BaseProjectTest extends \PHPUnit_Framework_TestCase |
6
|
|
|
{ |
7
|
|
|
/** |
8
|
|
|
* @var sting Temporary directory for project under test |
9
|
|
|
*/ |
10
|
|
|
protected static $projectPath; |
11
|
|
|
|
12
|
|
|
/** |
13
|
|
|
* @var string File that ensure other tests won't influence this one |
14
|
|
|
*/ |
15
|
|
|
private static $projectLockFile; |
16
|
|
|
|
17
|
|
|
/** |
18
|
|
|
* @var string |
19
|
|
|
*/ |
20
|
|
|
private static $oldWorkingDirectory; |
21
|
|
|
|
22
|
|
|
public static function setUpBeforeClass() |
23
|
|
|
{ |
24
|
|
|
parent::setUpBeforeClass(); |
25
|
|
|
|
26
|
|
|
self::$projectLockFile = tempnam(sys_get_temp_dir(), 'test'); |
27
|
|
|
self::$projectPath = self::$projectLockFile . '_dir'; |
|
|
|
|
28
|
|
|
mkdir(self::$projectPath); |
29
|
|
|
|
30
|
|
|
self::$oldWorkingDirectory = getcwd(); |
31
|
|
|
chdir(self::$projectPath); |
32
|
|
|
} |
33
|
|
|
|
34
|
|
|
public static function tearDownAfterClass2222222222() |
35
|
|
|
{ |
36
|
|
|
$files = new \RecursiveIteratorIterator( |
37
|
|
|
new \RecursiveDirectoryIterator( |
38
|
|
|
self::$projectPath, |
39
|
|
|
\RecursiveDirectoryIterator::SKIP_DOTS |
40
|
|
|
), |
41
|
|
|
\RecursiveIteratorIterator::CHILD_FIRST |
42
|
|
|
); |
43
|
|
|
foreach ($files as $file) { |
44
|
|
|
if ($file->isDir()) { |
45
|
|
|
rmdir($file->getRealPath()); |
46
|
|
|
} else { |
47
|
|
|
unlink($file->getRealPath()); |
48
|
|
|
} |
49
|
|
|
} |
50
|
|
|
|
51
|
|
|
chdir(self::$oldWorkingDirectory); |
52
|
|
|
|
53
|
|
|
if (rmdir(self::$projectPath)) { |
54
|
|
|
unlink(self::$projectLockFile); |
55
|
|
|
} |
56
|
|
|
|
57
|
|
|
parent::tearDownAfterClass(); |
|
|
|
|
58
|
|
|
} |
59
|
|
|
|
60
|
|
|
/** |
61
|
|
|
* Runs a command and compares result against expection. |
62
|
|
|
* |
63
|
|
|
* @param string $command The command to execute |
64
|
|
|
* @param mixed $expectedResult Expected exit code |
65
|
|
|
* @param string[]|null $expectedOutput Expected stdout as array of lines (null to skip check) |
66
|
|
|
* @param string $message Description of the assertion |
67
|
|
|
*/ |
68
|
|
|
protected static function assertCommand($command, $expectedResult, $expectedOutput = null, $message = '') |
69
|
|
|
{ |
70
|
|
|
$actualResult = null; |
71
|
|
|
$actualOutput = null; |
72
|
|
|
$command .= ' 2>&1'; |
73
|
|
|
|
74
|
|
|
exec($command, $actualOutput, $actualResult); |
75
|
|
|
|
76
|
|
|
if (!$message) { |
77
|
|
|
$sep = PHP_EOL . '- '; |
78
|
|
|
$message = sprintf( |
|
|
|
|
79
|
|
|
'Command:%sResult (exit: %s):%s', |
80
|
|
|
$sep . $command . PHP_EOL, |
81
|
|
|
$actualResult, |
82
|
|
|
$sep . implode($sep, $actualOutput) |
83
|
|
|
); |
84
|
|
|
} |
85
|
|
|
|
86
|
|
|
if (!is_null($expectedResult)) { |
87
|
|
|
static::assertEquals($expectedResult, $actualResult, $message); |
88
|
|
|
} |
89
|
|
|
|
90
|
|
|
if (!is_null($expectedOutput)) { |
91
|
|
|
static::assertEquals($expectedOutput, $actualOutput, $message); |
92
|
|
|
} |
93
|
|
|
} |
94
|
|
|
|
95
|
|
|
/** |
96
|
|
|
* Runs a command and asserts that it was successful. |
97
|
|
|
* |
98
|
|
|
* @param string $command The command to execute |
99
|
|
|
* @param string $message Description of the assertion |
100
|
|
|
*/ |
101
|
|
|
protected static function assertCommandSuccessful($command, $message = '') |
102
|
|
|
{ |
103
|
|
|
static::assertCommand($command, 0, null, $message); |
104
|
|
|
} |
105
|
|
|
|
106
|
|
|
/** |
107
|
|
|
* Returns command line to run ElderBrother. |
108
|
|
|
* |
109
|
|
|
* @return string |
110
|
|
|
*/ |
111
|
|
|
protected static function getEbCmd() |
112
|
|
|
{ |
113
|
|
|
static $cache = null; |
114
|
|
|
|
115
|
|
|
if (!$cache) { |
116
|
|
|
$bin = __DIR__ . '/../../../elder-brother'; |
117
|
|
|
$cache = 'php -f ' . escapeshellarg(realpath($bin)) . ' -- '; |
118
|
|
|
} |
119
|
|
|
|
120
|
|
|
return $cache; |
121
|
|
|
} |
122
|
|
|
} |
123
|
|
|
|
Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.
Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..