Passed
Push — master ( d82328...2285e3 )
by Kevin
01:54
created

CommandTaskTest::has_default_description()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 2
c 0
b 0
f 0
dl 0
loc 4
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 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('my:command', (string) $task1);
33
        $this->assertSame('', $task1->getArguments());
34
35
        $task2 = new CommandTask('my:command arg');
36
        $this->assertSame('my:command', (string) $task2);
37
        $this->assertSame('arg', $task2->getArguments());
38
39
        $task3 = new CommandTask('my:command arg', '--option1 --option2', '--option3');
40
        $this->assertSame('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('my:command', (string) $task4);
46
        $this->assertSame('--option1', $task4->getArguments());
47
    }
48
49
    /**
50
     * @test
51
     * @dataProvider commandNameProvider
52
     */
53
    public function can_create_input($commandName)
54
    {
55
        $application = new Application();
56
        $application->add(new DummyCommand());
57
58
        $task = new CommandTask($commandName, '--option');
59
        $input = $task->createCommandInput($application);
60
61
        $this->assertInstanceOf(StringInput::class, $input);
62
        $this->assertSame("'dummy:command' --option", (string) $input);
63
    }
64
65
    public static function commandNameProvider()
66
    {
67
        return [
68
            ['dummy:command'],
69
            [DummyCommand::class],
70
        ];
71
    }
72
73
    /**
74
     * @test
75
     */
76
    public function unregistered_command_throws_exception()
77
    {
78
        $task = new CommandTask('invalid:command');
79
80
        $this->expectExceptionMessage(CommandNotFoundException::class);
81
        $this->expectExceptionMessage('Command "invalid:command" not found.');
82
83
        $task->createCommandInput(new Application());
84
    }
85
}
86
87
final class DummyCommand extends Command
88
{
89
    protected static $defaultName = 'dummy:command';
90
}
91