Passed
Push — master ( 18c542...46352d )
by Kevin
02:34
created

CommandTaskTest::commandNameProvider()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 3
c 0
b 0
f 0
dl 0
loc 5
rs 10
cc 1
nc 1
nop 0
1
<?php
2
3
namespace Zenstruck\ScheduleBundle\Tests\Schedule\Task;
4
5
use PHPUnit\Framework\TestCase;
0 ignored issues
show
Bug introduced by
The type PHPUnit\Framework\TestCase was not found. Maybe you did not declare it correctly or list all dependencies?

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:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
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 can_create_with_arguments()
21
    {
22
        $task1 = new CommandTask('my:command');
23
        $this->assertSame('my:command', (string) $task1);
24
        $this->assertSame('', $task1->getArguments());
25
26
        $task2 = new CommandTask('my:command arg');
27
        $this->assertSame('my:command', (string) $task2);
28
        $this->assertSame('arg', $task2->getArguments());
29
30
        $task3 = new CommandTask('my:command arg', '--option1 --option2', '--option3');
31
        $this->assertSame('my:command', (string) $task3);
32
        $this->assertSame('arg --option1 --option2 --option3', $task3->getArguments());
33
34
        $task4 = new CommandTask('my:command arg', '--option1 --option2', '--option3');
35
        $task4->arguments('--option1');
36
        $this->assertSame('my:command', (string) $task4);
37
        $this->assertSame('--option1', $task4->getArguments());
38
    }
39
40
    /**
41
     * @test
42
     * @dataProvider commandNameProvider
43
     */
44
    public function can_create_input($commandName)
45
    {
46
        $application = new Application();
47
        $application->add(new DummyCommand());
48
49
        $task = new CommandTask($commandName, '--option');
50
        $input = $task->createCommandInput($application);
51
52
        $this->assertInstanceOf(StringInput::class, $input);
53
        $this->assertSame("'dummy:command' --option", (string) $input);
54
    }
55
56
    public static function commandNameProvider()
57
    {
58
        return [
59
            ['dummy:command'],
60
            [DummyCommand::class],
61
        ];
62
    }
63
64
    /**
65
     * @test
66
     */
67
    public function unregistered_command_throws_exception()
68
    {
69
        $task = new CommandTask('invalid:command');
70
71
        $this->expectExceptionMessage(CommandNotFoundException::class);
72
        $this->expectExceptionMessage('Command "invalid:command" not found.');
73
74
        $task->createCommandInput(new Application());
75
    }
76
}
77
78
final class DummyCommand extends Command
79
{
80
    protected static $defaultName = 'dummy:command';
81
}
82