Issues (91)

Schedule/Extension/EnvironmentExtensionTest.php (1 issue)

Labels
Severity
1
<?php
2
3
namespace Zenstruck\ScheduleBundle\Tests\Schedule\Extension;
4
5
use PHPUnit\Framework\TestCase;
0 ignored issues
show
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 Zenstruck\ScheduleBundle\Schedule\Extension\EnvironmentExtension;
7
use Zenstruck\ScheduleBundle\Schedule\Extension\Handler\EnvironmentHandler;
8
use Zenstruck\ScheduleBundle\Tests\Fixture\MockScheduleBuilder;
9
10
/**
11
 * @author Kevin Bond <[email protected]>
12
 */
13
final class EnvironmentExtensionTest extends TestCase
14
{
15
    /**
16
     * @test
17
     */
18
    public function does_not_run_when_environment_does_not_match()
19
    {
20
        $context = (new MockScheduleBuilder())
21
            ->addHandler(new EnvironmentHandler('dev'))
22
            ->addExtension(new EnvironmentExtension(['prod', 'stage']))
23
            ->run()
24
        ;
25
26
        $this->assertTrue($context->isSkipped());
27
        $this->assertTrue($context->isSuccessful());
28
        $this->assertSame('Schedule configured not to run in [dev] environment (only [prod, stage]).', $context->getSkipReason());
29
    }
30
31
    /**
32
     * @test
33
     */
34
    public function allows_schedule_to_run_if_environment_matches()
35
    {
36
        $context = (new MockScheduleBuilder())
37
            ->addHandler(new EnvironmentHandler('prod'))
38
            ->addExtension(new EnvironmentExtension(['prod', 'stage']))
39
            ->run()
40
        ;
41
42
        $this->assertFalse($context->isSkipped());
43
    }
44
45
    /**
46
     * @test
47
     */
48
    public function requires_at_least_one_environment()
49
    {
50
        $this->expectException(\InvalidArgumentException::class);
51
        $this->expectExceptionMessage('At least one environment must be configured.');
52
53
        new EnvironmentExtension([]);
54
    }
55
}
56