1 | <?php |
||
5 | abstract class BaseProjectTest extends \PHPUnit_Framework_TestCase |
||
6 | { |
||
7 | /** |
||
8 | * @var string 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() |
||
33 | |||
34 | public static function tearDownAfterClass() |
||
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 = '') |
||
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 = '') |
||
105 | |||
106 | /** |
||
107 | * Returns command line to run ElderBrother. |
||
108 | * |
||
109 | * @return string |
||
110 | */ |
||
111 | protected static function getEbCmd() |
||
122 | } |
||
123 |