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

SingleServerTest   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 51
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 3
eloc 24
c 0
b 0
f 0
dl 0
loc 51
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A can_lock_schedule() 0 14 1
A can_lock_task() 0 14 1
A provides_helpful_message_if_handler_not_configured() 0 8 1
1
<?php
2
3
namespace Zenstruck\ScheduleBundle\Tests\Functional;
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 Psr\Log\Test\TestLogger;
7
use Symfony\Component\Lock\LockFactory;
8
use Symfony\Component\Lock\Store\FlockStore;
9
use Zenstruck\ScheduleBundle\Schedule\Extension\Handler\SingleServerHandler;
10
use Zenstruck\ScheduleBundle\Schedule\Extension\SingleServerExtension;
11
use Zenstruck\ScheduleBundle\Tests\Fixture\MockScheduleBuilder;
12
use Zenstruck\ScheduleBundle\Tests\Fixture\MockTask;
13
14
/**
15
 * @author Kevin Bond <[email protected]>
16
 */
17
final class SingleServerTest extends TestCase
18
{
19
    /**
20
     * @test
21
     */
22
    public function can_lock_schedule()
23
    {
24
        $logger = new TestLogger();
25
        $lockFactory = new LockFactory(new FlockStore());
26
        $lockFactory->setLogger($logger);
27
28
        (new MockScheduleBuilder())
29
            ->addHandler(new SingleServerHandler($lockFactory))
30
            ->addExtension(new SingleServerExtension())
31
            ->run()
32
        ;
33
34
        $this->assertTrue($logger->hasInfoThatContains('Successfully acquired'));
35
        $this->assertTrue($logger->hasInfoThatContains('Expiration defined'));
36
    }
37
38
    /**
39
     * @test
40
     */
41
    public function can_lock_task()
42
    {
43
        $logger = new TestLogger();
44
        $lockFactory = new LockFactory(new FlockStore());
45
        $lockFactory->setLogger($logger);
46
47
        (new MockScheduleBuilder())
48
            ->addHandler(new SingleServerHandler($lockFactory))
49
            ->addTask((new MockTask())->onSingleServer())
50
            ->run()
51
        ;
52
53
        $this->assertTrue($logger->hasInfoThatContains('Successfully acquired'));
54
        $this->assertTrue($logger->hasInfoThatContains('Expiration defined'));
55
    }
56
57
    /**
58
     * @test
59
     */
60
    public function provides_helpful_message_if_handler_not_configured()
61
    {
62
        $this->expectException(\LogicException::class);
63
        $this->expectExceptionMessage('To use "onSingleServer" you must configure a lock factory (config path: "zenstruck_schedule.single_server_handler")');
64
65
        (new MockScheduleBuilder())
66
            ->addExtension(new SingleServerExtension())
67
            ->run()
68
        ;
69
    }
70
}
71