|
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 shell_verbosity_is_reset(): void |
|
71
|
|
|
{ |
|
72
|
|
|
$preShellVerbosity = [ |
|
73
|
|
|
\getenv('SHELL_VERBOSITY'), |
|
74
|
|
|
$_ENV['SHELL_VERBOSITY'] ?? false, |
|
75
|
|
|
$_SERVER['SHELL_VERBOSITY'] ?? false, |
|
76
|
|
|
]; |
|
77
|
|
|
|
|
78
|
|
|
$application = new Application(); |
|
79
|
|
|
$application->add($this->createCommand()); |
|
80
|
|
|
$runner = new CommandTaskRunner($application); |
|
81
|
|
|
|
|
82
|
|
|
$result = $runner(new CommandTask('my:command -vv')); |
|
83
|
|
|
|
|
84
|
|
|
$this->assertTrue($result->isSuccessful()); |
|
85
|
|
|
$this->assertSame('some output... is very verbose', $result->getOutput()); |
|
86
|
|
|
$this->assertSame($preShellVerbosity, [ |
|
87
|
|
|
\getenv('SHELL_VERBOSITY'), |
|
88
|
|
|
$_ENV['SHELL_VERBOSITY'] ?? false, |
|
89
|
|
|
$_SERVER['SHELL_VERBOSITY'] ?? false, |
|
90
|
|
|
]); |
|
91
|
|
|
} |
|
92
|
|
|
|
|
93
|
|
|
/** |
|
94
|
|
|
* @test |
|
95
|
|
|
*/ |
|
96
|
|
|
public function supports_command_task() |
|
97
|
|
|
{ |
|
98
|
|
|
$this->assertTrue((new CommandTaskRunner(new Application()))->supports(new CommandTask('my:command'))); |
|
99
|
|
|
} |
|
100
|
|
|
|
|
101
|
|
|
private function createCommand(): Command |
|
102
|
|
|
{ |
|
103
|
|
|
return new class() extends Command { |
|
104
|
|
|
protected static $defaultName = 'my:command'; |
|
105
|
|
|
|
|
106
|
|
|
protected function configure() |
|
107
|
|
|
{ |
|
108
|
|
|
$this |
|
109
|
|
|
->addOption('fail') |
|
110
|
|
|
->addOption('exception') |
|
111
|
|
|
; |
|
112
|
|
|
} |
|
113
|
|
|
|
|
114
|
|
|
protected function execute(InputInterface $input, OutputInterface $output) |
|
115
|
|
|
{ |
|
116
|
|
|
$output->write('some output...'); |
|
117
|
|
|
|
|
118
|
|
|
if ($output->isVeryVerbose()) { |
|
119
|
|
|
$output->write(' is very verbose'); |
|
120
|
|
|
} |
|
121
|
|
|
|
|
122
|
|
|
if ($input->getOption('exception')) { |
|
123
|
|
|
throw new \RuntimeException('exception message'); |
|
124
|
|
|
} |
|
125
|
|
|
|
|
126
|
|
|
return $input->getOption('fail') ? 1 : 0; |
|
127
|
|
|
} |
|
128
|
|
|
}; |
|
129
|
|
|
} |
|
130
|
|
|
} |
|
131
|
|
|
|
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