1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Glooby\TaskBundle\Tests\Schedule; |
4
|
|
|
|
5
|
|
|
use Doctrine\Common\Annotations\Reader; |
6
|
|
|
use Glooby\TaskBundle\Annotation\Schedule; |
7
|
|
|
use Glooby\TaskBundle\Schedule\ScheduleRegistry; |
8
|
|
|
use Prophecy\Argument; |
9
|
|
|
use Symfony\Component\DependencyInjection\ContainerInterface; |
10
|
|
|
|
11
|
|
|
/** |
12
|
|
|
* @author Emil Kilhage |
13
|
|
|
*/ |
14
|
|
|
class ScheduleRegistryTest extends \PHPUnit_Framework_TestCase |
15
|
|
|
{ |
16
|
|
|
public function testOne() |
17
|
|
|
{ |
18
|
|
|
$container = $this->prophesize(ContainerInterface::class); |
19
|
|
|
$reader = $this->prophesize(Reader::class); |
20
|
|
|
|
21
|
|
|
$registry = new ScheduleRegistry(); |
22
|
|
|
$registry->setContainer($container->reveal()); |
23
|
|
|
$registry->setReader($reader->reveal()); |
24
|
|
|
|
25
|
|
|
$registry->addTask('task.foo.a'); |
26
|
|
|
$registry->addTask('task.foo.b'); |
27
|
|
|
|
28
|
|
|
$container->get('task.foo.a')->willReturn(new \stdClass()); |
29
|
|
|
$container->get('task.foo.b')->willReturn(new \stdClass()); |
30
|
|
|
|
31
|
|
|
$schedule1 = new Schedule(['value' => '@daily']); |
32
|
|
|
|
33
|
|
|
$reader->getClassAnnotation(Argument::type(\ReflectionObject::class), ScheduleRegistry::ANNOTATION_CLASS) |
34
|
|
|
->shouldBeCalled() |
35
|
|
|
->willReturn($schedule1); |
36
|
|
|
|
37
|
|
|
$schedules = $registry->getSchedules(); |
38
|
|
|
|
39
|
|
|
$this->assertTrue(isset($schedules['task.foo.a'])); |
40
|
|
|
$this->assertSame($schedule1, $schedules['task.foo.a']); |
41
|
|
|
|
42
|
|
|
$this->assertTrue(isset($schedules['task.foo.b'])); |
43
|
|
|
$this->assertSame($schedule1, $schedules['task.foo.b']); |
44
|
|
|
} |
45
|
|
|
|
46
|
|
|
public function testEmpty() |
47
|
|
|
{ |
48
|
|
|
$container = $this->prophesize(ContainerInterface::class); |
49
|
|
|
$reader = $this->prophesize(Reader::class); |
50
|
|
|
|
51
|
|
|
$registry = new ScheduleRegistry(); |
52
|
|
|
$registry->setContainer($container->reveal()); |
53
|
|
|
$registry->setReader($reader->reveal()); |
54
|
|
|
|
55
|
|
|
$reader->getClassAnnotation(Argument::type(\ReflectionObject::class), ScheduleRegistry::ANNOTATION_CLASS) |
56
|
|
|
->shouldNotBeCalled() |
57
|
|
|
->willReturn(null); |
58
|
|
|
|
59
|
|
|
$schedules = $registry->getSchedules(); |
60
|
|
|
|
61
|
|
|
$this->assertEmpty($schedules); |
62
|
|
|
} |
63
|
|
|
|
64
|
|
|
public function testMissingScheduleAnnotation() |
65
|
|
|
{ |
66
|
|
|
$container = $this->prophesize(ContainerInterface::class); |
67
|
|
|
$reader = $this->prophesize(Reader::class); |
68
|
|
|
|
69
|
|
|
$registry = new ScheduleRegistry(); |
70
|
|
|
$registry->setContainer($container->reveal()); |
71
|
|
|
$registry->setReader($reader->reveal()); |
72
|
|
|
|
73
|
|
|
$registry->addTask('task.foo.a'); |
74
|
|
|
$registry->addTask('task.foo.b'); |
75
|
|
|
|
76
|
|
|
$container->get('task.foo.a')->willReturn(new \stdClass()); |
77
|
|
|
$container->get('task.foo.b')->willReturn(new \stdClass()); |
78
|
|
|
|
79
|
|
|
$reader->getClassAnnotation(Argument::type(\ReflectionObject::class), ScheduleRegistry::ANNOTATION_CLASS) |
80
|
|
|
->shouldBeCalled() |
81
|
|
|
->willReturn(null); |
82
|
|
|
|
83
|
|
|
$this->setExpectedException('\InvalidArgumentException'); |
84
|
|
|
|
85
|
|
|
$registry->getSchedules(); |
86
|
|
|
} |
87
|
|
|
} |
88
|
|
|
|