A
last analyzed

Complexity

Total Complexity 1

Size/Duplication

Total Lines 3
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 1
dl 0
loc 3
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace Zenstruck\ScheduleBundle\Tests\Schedule;
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\Command\Command;
7
use Zenstruck\ScheduleBundle\EventListener\SelfSchedulingCommandSubscriber;
8
use Zenstruck\ScheduleBundle\Schedule\SelfSchedulingCommand;
9
use Zenstruck\ScheduleBundle\Schedule\Task\CommandTask;
10
use Zenstruck\ScheduleBundle\Tests\Fixture\MockScheduleBuilder;
11
12
/**
13
 * @author Kevin Bond <[email protected]>
14
 */
15
final class SelfSchedulingCommandTest extends TestCase
16
{
17
    /**
18
     * @test
19
     */
20
    public function commands_can_self_schedule()
21
    {
22
        $command = new class() extends Command implements SelfSchedulingCommand {
23
            protected static $defaultName = 'my:command';
24
25
            public function schedule(CommandTask $task): void
26
            {
27
            }
28
        };
29
30
        $tasks = (new MockScheduleBuilder())
31
            ->addSubscriber(new SelfSchedulingCommandSubscriber([$command]))
32
            ->getRunner()
33
            ->buildSchedule()
34
            ->all()
35
        ;
36
37
        $this->assertInstanceOf(CommandTask::class, $tasks[0]);
38
        $this->assertSame('CommandTask: my:command', (string) $tasks[0]);
39
    }
40
41
    /**
42
     * @test
43
     */
44
    public function throws_exception_if_not_a_command()
45
    {
46
        $command = new class() implements SelfSchedulingCommand {
47
            public function schedule(CommandTask $task): void
48
            {
49
            }
50
        };
51
52
        $this->expectException(\InvalidArgumentException::class);
53
        $this->expectExceptionMessageMatches('/is not a console command/');
54
55
        (new MockScheduleBuilder())
56
            ->addSubscriber(new SelfSchedulingCommandSubscriber([$command]))
57
            ->run()
58
        ;
59
    }
60
}
61