|
4 | 4 | * See COPYING.txt for license details.
|
5 | 5 | */
|
6 | 6 |
|
7 |
| -namespace Magento\Developer\Test\Unit\Console\Command; |
| 7 | +// @codingStandardsIgnoreStart |
8 | 8 |
|
9 |
| -use Magento\Developer\Console\Command\DevTestsRunCommand; |
10 |
| -use Symfony\Component\Console\Tester\CommandTester; |
| 9 | +namespace Magento\Developer\Console\Command { |
| 10 | + use Symfony\Component\Console\Tester\CommandTester; |
11 | 11 |
|
12 |
| -/** |
13 |
| - * Class DevTestsRunCommandTest |
14 |
| - * |
15 |
| - * Tests dev:tests:run command. Only tests error case because DevTestsRunCommand calls phpunit with |
16 |
| - * passthru, so there is no good way to mock out running the tests. |
17 |
| - */ |
18 |
| -class DevTestsRunCommandTest extends \PHPUnit\Framework\TestCase |
19 |
| -{ |
| 12 | + $devTestsRunCommandTestPassthruReturnVar = null; |
20 | 13 |
|
21 | 14 | /**
|
22 |
| - * @var DevTestsRunCommand |
| 15 | + * Mock for PHP builtin passthtru function |
| 16 | + * |
| 17 | + * @param string $command |
| 18 | + * @param int|null $return_var |
| 19 | + * @return void |
23 | 20 | */
|
24 |
| - private $command; |
25 |
| - |
26 |
| - protected function setUp() |
| 21 | + function passthru($command, &$return_var = null) |
27 | 22 | {
|
28 |
| - $this->command = new DevTestsRunCommand(); |
| 23 | + global $devTestsRunCommandTestPassthruReturnVar; |
| 24 | + $return_var = $devTestsRunCommandTestPassthruReturnVar; |
29 | 25 | }
|
30 | 26 |
|
31 |
| - public function testExecuteBadType() |
| 27 | + /** |
| 28 | + * Class DevTestsRunCommandTest |
| 29 | + * |
| 30 | + * Tests dev:tests:run command. Only tests error case because DevTestsRunCommand calls phpunit with |
| 31 | + * passthru, so there is no good way to mock out running the tests. |
| 32 | + */ |
| 33 | + class DevTestsRunCommandTest extends \PHPUnit\Framework\TestCase |
32 | 34 | {
|
33 |
| - $commandTester = new CommandTester($this->command); |
34 |
| - $commandTester->execute([DevTestsRunCommand::INPUT_ARG_TYPE => 'bad']); |
35 |
| - $this->assertContains('Invalid type: "bad"', $commandTester->getDisplay()); |
36 |
| - } |
37 | 35 |
|
38 |
| - public function testPassArgumentsToPHPUnit() |
39 |
| - { |
40 |
| - $commandTester = new CommandTester($this->command); |
41 |
| - $commandTester->execute( |
42 |
| - [ |
43 |
| - DevTestsRunCommand::INPUT_ARG_TYPE => 'unit', |
44 |
| - '-' . DevTestsRunCommand::INPUT_OPT_COMMAND_ARGUMENTS_SHORT => '--list-suites', |
45 |
| - ] |
46 |
| - ); |
47 |
| - $this->assertContains( |
48 |
| - 'phpunit --list-suites', |
49 |
| - $commandTester->getDisplay(), |
50 |
| - 'Parameters should be passed to PHPUnit' |
51 |
| - ); |
| 36 | + /** |
| 37 | + * @var DevTestsRunCommand |
| 38 | + */ |
| 39 | + private $command; |
| 40 | + |
| 41 | + protected function setUp() |
| 42 | + { |
| 43 | + $this->command = new DevTestsRunCommand(); |
| 44 | + } |
| 45 | + |
| 46 | + public function testExecuteBadType() |
| 47 | + { |
| 48 | + $commandTester = new CommandTester($this->command); |
| 49 | + $commandTester->execute([DevTestsRunCommand::INPUT_ARG_TYPE => 'bad']); |
| 50 | + $this->assertContains('Invalid type: "bad"', $commandTester->getDisplay()); |
| 51 | + } |
| 52 | + |
| 53 | + public function testPassArgumentsToPHPUnit() |
| 54 | + { |
| 55 | + global $devTestsRunCommandTestPassthruReturnVar; |
| 56 | + |
| 57 | + $devTestsRunCommandTestPassthruReturnVar = 0; |
| 58 | + |
| 59 | + $commandTester = new CommandTester($this->command); |
| 60 | + $commandTester->execute( |
| 61 | + [ |
| 62 | + DevTestsRunCommand::INPUT_ARG_TYPE => 'unit', |
| 63 | + '-' . DevTestsRunCommand::INPUT_OPT_COMMAND_ARGUMENTS_SHORT => '--list-suites', |
| 64 | + ] |
| 65 | + ); |
| 66 | + $this->assertContains( |
| 67 | + 'phpunit --list-suites', |
| 68 | + $commandTester->getDisplay(), |
| 69 | + 'Parameters should be passed to PHPUnit' |
| 70 | + ); |
| 71 | + $this->assertContains( |
| 72 | + 'PASSED (', |
| 73 | + $commandTester->getDisplay(), |
| 74 | + 'PHPUnit runs should have passed' |
| 75 | + ); |
| 76 | + } |
| 77 | + |
| 78 | + public function testPassArgumentsToPHPUnitNegative() |
| 79 | + { |
| 80 | + global $devTestsRunCommandTestPassthruReturnVar; |
| 81 | + |
| 82 | + $devTestsRunCommandTestPassthruReturnVar = 255; |
| 83 | + |
| 84 | + $commandTester = new CommandTester($this->command); |
| 85 | + $commandTester->execute( |
| 86 | + [ |
| 87 | + DevTestsRunCommand::INPUT_ARG_TYPE => 'unit', |
| 88 | + '-' . DevTestsRunCommand::INPUT_OPT_COMMAND_ARGUMENTS_SHORT => '--list-suites', |
| 89 | + ] |
| 90 | + ); |
| 91 | + $this->assertContains( |
| 92 | + 'phpunit --list-suites', |
| 93 | + $commandTester->getDisplay(), |
| 94 | + 'Parameters should be passed to PHPUnit' |
| 95 | + ); |
| 96 | + $this->assertContains( |
| 97 | + 'FAILED - ', |
| 98 | + $commandTester->getDisplay(), |
| 99 | + 'PHPUnit runs should have passed' |
| 100 | + ); |
| 101 | + } |
52 | 102 | }
|
53 | 103 | }
|
0 commit comments