zenstruck /
schedule-bundle
| 1 | <?php |
||
| 2 | |||
| 3 | namespace Zenstruck\ScheduleBundle\Tests\Schedule\Task; |
||
| 4 | |||
| 5 | use PHPUnit\Framework\TestCase; |
||
|
0 ignored issues
–
show
|
|||
| 6 | use Symfony\Component\Console\Application; |
||
| 7 | use Symfony\Component\Console\Command\Command; |
||
| 8 | use Symfony\Component\Console\Exception\CommandNotFoundException; |
||
| 9 | use Symfony\Component\Console\Input\StringInput; |
||
| 10 | use Zenstruck\ScheduleBundle\Schedule\Task\CommandTask; |
||
| 11 | |||
| 12 | /** |
||
| 13 | * @author Kevin Bond <[email protected]> |
||
| 14 | */ |
||
| 15 | final class CommandTaskTest extends TestCase |
||
| 16 | { |
||
| 17 | /** |
||
| 18 | * @test |
||
| 19 | */ |
||
| 20 | public function has_default_description() |
||
| 21 | { |
||
| 22 | $this->assertSame('my:command', (new CommandTask('my:command', '--option'))->getDescription()); |
||
| 23 | $this->assertSame(DummyCommand::class, (new CommandTask(DummyCommand::class, '--option'))->getDescription()); |
||
| 24 | } |
||
| 25 | |||
| 26 | /** |
||
| 27 | * @test |
||
| 28 | */ |
||
| 29 | public function can_create_with_arguments() |
||
| 30 | { |
||
| 31 | $task1 = new CommandTask('my:command'); |
||
| 32 | $this->assertSame('CommandTask: my:command', (string) $task1); |
||
| 33 | $this->assertSame('', $task1->getArguments()); |
||
| 34 | |||
| 35 | $task2 = new CommandTask('my:command arg'); |
||
| 36 | $this->assertSame('CommandTask: my:command', (string) $task2); |
||
| 37 | $this->assertSame('arg', $task2->getArguments()); |
||
| 38 | |||
| 39 | $task3 = new CommandTask('my:command arg', '--option1 --option2', '--option3'); |
||
| 40 | $this->assertSame('CommandTask: my:command', (string) $task3); |
||
| 41 | $this->assertSame('arg --option1 --option2 --option3', $task3->getArguments()); |
||
| 42 | |||
| 43 | $task4 = new CommandTask('my:command arg', '--option1 --option2', '--option3'); |
||
| 44 | $task4->arguments('--option1'); |
||
| 45 | $this->assertSame('CommandTask: my:command', (string) $task4); |
||
| 46 | $this->assertSame('--option1', $task4->getArguments()); |
||
| 47 | } |
||
| 48 | |||
| 49 | /** |
||
| 50 | * @test |
||
| 51 | */ |
||
| 52 | public function task_has_context() |
||
| 53 | { |
||
| 54 | $task = new CommandTask('my:command'); |
||
| 55 | $this->assertSame(['Command Name' => 'my:command', 'Command Arguments' => '(none)'], $task->getContext()); |
||
| 56 | |||
| 57 | $task = new CommandTask('my:command --foo bar'); |
||
| 58 | $this->assertSame(['Command Name' => 'my:command', 'Command Arguments' => '--foo bar'], $task->getContext()); |
||
| 59 | } |
||
| 60 | |||
| 61 | /** |
||
| 62 | * @test |
||
| 63 | * @dataProvider commandNameProvider |
||
| 64 | */ |
||
| 65 | public function can_create_input($commandName) |
||
| 66 | { |
||
| 67 | $application = new Application(); |
||
| 68 | $application->add(new DummyCommand()); |
||
| 69 | |||
| 70 | $task = new CommandTask($commandName, '--option'); |
||
| 71 | $input = $task->createCommandInput($application); |
||
| 72 | |||
| 73 | $this->assertInstanceOf(StringInput::class, $input); |
||
| 74 | $this->assertSame("'dummy:command' --option", (string) $input); |
||
| 75 | } |
||
| 76 | |||
| 77 | public static function commandNameProvider() |
||
| 78 | { |
||
| 79 | return [ |
||
| 80 | ['dummy:command'], |
||
| 81 | [DummyCommand::class], |
||
| 82 | ]; |
||
| 83 | } |
||
| 84 | |||
| 85 | /** |
||
| 86 | * @test |
||
| 87 | */ |
||
| 88 | public function unregistered_command_throws_exception() |
||
| 89 | { |
||
| 90 | $task = new CommandTask('invalid:command'); |
||
| 91 | |||
| 92 | $this->expectExceptionMessage(CommandNotFoundException::class); |
||
| 93 | $this->expectExceptionMessage('Command "invalid:command" not registered.'); |
||
| 94 | |||
| 95 | $task->createCommandInput(new Application()); |
||
| 96 | } |
||
| 97 | } |
||
| 98 | |||
| 99 | final class DummyCommand extends Command |
||
| 100 | { |
||
| 101 | protected static $defaultName = 'dummy:command'; |
||
| 102 | } |
||
| 103 |
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