|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Zenstruck\ScheduleBundle\Tests\Functional; |
|
4
|
|
|
|
|
5
|
|
|
use PHPUnit\Framework\TestCase; |
|
|
|
|
|
|
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
|
|
|
|
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:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths