1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Zenstruck\ScheduleBundle\Tests\Schedule\Task\Runner; |
4
|
|
|
|
5
|
|
|
use PHPUnit\Framework\TestCase; |
|
|
|
|
6
|
|
|
use Symfony\Component\Console\Application; |
7
|
|
|
use Symfony\Component\Console\Command\Command; |
8
|
|
|
use Symfony\Component\Console\Input\InputInterface; |
9
|
|
|
use Symfony\Component\Console\Output\OutputInterface; |
10
|
|
|
use Zenstruck\ScheduleBundle\Schedule\Task\CommandTask; |
11
|
|
|
use Zenstruck\ScheduleBundle\Schedule\Task\Runner\CommandTaskRunner; |
12
|
|
|
|
13
|
|
|
/** |
14
|
|
|
* @author Kevin Bond <[email protected]> |
15
|
|
|
*/ |
16
|
|
|
final class CommandTaskRunnerTest extends TestCase |
17
|
|
|
{ |
18
|
|
|
/** |
19
|
|
|
* @test |
20
|
|
|
*/ |
21
|
|
|
public function creates_successful_result() |
22
|
|
|
{ |
23
|
|
|
$application = new Application(); |
24
|
|
|
$application->add($this->createCommand()); |
25
|
|
|
$runner = new CommandTaskRunner($application); |
26
|
|
|
|
27
|
|
|
$result = $runner(new CommandTask('my:command')); |
28
|
|
|
|
29
|
|
|
$this->assertTrue($result->isSuccessful()); |
30
|
|
|
$this->assertSame('some output...', $result->getOutput()); |
31
|
|
|
} |
32
|
|
|
|
33
|
|
|
/** |
34
|
|
|
* @test |
35
|
|
|
*/ |
36
|
|
|
public function creates_exception_result() |
37
|
|
|
{ |
38
|
|
|
$application = new Application(); |
39
|
|
|
$application->add($this->createCommand()); |
40
|
|
|
$runner = new CommandTaskRunner($application); |
41
|
|
|
|
42
|
|
|
$result = $runner(new CommandTask('my:command --exception')); |
43
|
|
|
|
44
|
|
|
$this->assertTrue($result->isFailure()); |
45
|
|
|
$this->assertTrue($result->isException()); |
46
|
|
|
$this->assertInstanceOf(\RuntimeException::class, $result->getException()); |
47
|
|
|
$this->assertSame('RuntimeException: exception message', $result->getDescription()); |
48
|
|
|
$this->assertSame('some output...', $result->getOutput()); |
49
|
|
|
} |
50
|
|
|
|
51
|
|
|
/** |
52
|
|
|
* @test |
53
|
|
|
*/ |
54
|
|
|
public function creates_failure_result() |
55
|
|
|
{ |
56
|
|
|
$application = new Application(); |
57
|
|
|
$application->add($this->createCommand()); |
58
|
|
|
$runner = new CommandTaskRunner($application); |
59
|
|
|
|
60
|
|
|
$result = $runner(new CommandTask('my:command --fail')); |
61
|
|
|
|
62
|
|
|
$this->assertTrue($result->isFailure()); |
63
|
|
|
$this->assertSame('Exit 1: General error', $result->getDescription()); |
64
|
|
|
$this->assertSame('some output...', $result->getOutput()); |
65
|
|
|
} |
66
|
|
|
|
67
|
|
|
/** |
68
|
|
|
* @test |
69
|
|
|
*/ |
70
|
|
|
public function supports_command_task() |
71
|
|
|
{ |
72
|
|
|
$this->assertTrue((new CommandTaskRunner(new Application()))->supports(new CommandTask('my:command'))); |
73
|
|
|
} |
74
|
|
|
|
75
|
|
|
private function createCommand(): Command |
76
|
|
|
{ |
77
|
|
|
return new class() extends Command { |
78
|
|
|
protected static $defaultName = 'my:command'; |
79
|
|
|
|
80
|
|
|
protected function configure() |
81
|
|
|
{ |
82
|
|
|
$this |
83
|
|
|
->addOption('fail') |
84
|
|
|
->addOption('exception') |
85
|
|
|
; |
86
|
|
|
} |
87
|
|
|
|
88
|
|
|
protected function execute(InputInterface $input, OutputInterface $output) |
89
|
|
|
{ |
90
|
|
|
$output->write('some output...'); |
91
|
|
|
|
92
|
|
|
if ($input->getOption('exception')) { |
93
|
|
|
throw new \RuntimeException('exception message'); |
94
|
|
|
} |
95
|
|
|
|
96
|
|
|
return $input->getOption('fail') ? 1 : 0; |
97
|
|
|
} |
98
|
|
|
}; |
99
|
|
|
} |
100
|
|
|
} |
101
|
|
|
|
The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g.
excluded_paths: ["lib/*"]
, you can move it to the dependency path list as follows:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths