1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Symnedi\EventDispatcher\Tests\DI; |
4
|
|
|
|
5
|
|
|
use Nette\DI\Compiler; |
6
|
|
|
use Nette\DI\ContainerBuilder; |
7
|
|
|
use PHPUnit_Framework_TestCase; |
8
|
|
|
use Symfony\Component\EventDispatcher\EventDispatcher; |
9
|
|
|
use Symfony\Component\EventDispatcher\EventDispatcherInterface; |
10
|
|
|
use Symnedi\EventDispatcher\DI\EventDispatcherExtension; |
11
|
|
|
use Symnedi\EventDispatcher\Tests\DI\EventDispatcherExtensionSource\SomeEventSubscriber; |
12
|
|
|
|
13
|
|
|
|
14
|
|
|
final class EventDispatcherExtensionTest extends PHPUnit_Framework_TestCase |
15
|
|
|
{ |
16
|
|
|
|
17
|
|
|
public function testGetEventDispatcher() |
18
|
|
|
{ |
19
|
|
|
$extension = $this->getExtension(); |
20
|
|
|
$extension->loadConfiguration(); |
21
|
|
|
|
22
|
|
|
$containerBuilder = $extension->getContainerBuilder(); |
23
|
|
|
|
24
|
|
|
// Emulates life cycle from Nette\DI\Compiler. |
25
|
|
|
// @link https://github.com/nette/di/blob/9b0f8150f823ca22813ba9871156dabb20a911fa/src/DI/Compiler.php#L202-L207 |
26
|
|
|
$containerBuilder->prepareClassList(); |
27
|
|
|
|
28
|
|
|
$eventDispatcherDefinition = $containerBuilder->getDefinition( |
29
|
|
|
$containerBuilder->getByType(EventDispatcherInterface::class) |
30
|
|
|
); |
31
|
|
|
$this->assertSame(EventDispatcher::class, $eventDispatcherDefinition->getClass()); |
32
|
|
|
} |
33
|
|
|
|
34
|
|
|
|
35
|
|
|
public function testLoadSubscribers() |
36
|
|
|
{ |
37
|
|
|
$extension = $this->getExtension(); |
38
|
|
|
$containerBuilder = $extension->getContainerBuilder(); |
39
|
|
|
|
40
|
|
|
$extension->loadConfiguration(); |
41
|
|
|
|
42
|
|
|
$containerBuilder->addDefinition('eventSubscriber') |
43
|
|
|
->setClass(SomeEventSubscriber::class); |
44
|
|
|
|
45
|
|
|
// Emulates life cycle from Nette\DI\Compiler. |
46
|
|
|
// @link https://github.com/nette/di/blob/9b0f8150f823ca22813ba9871156dabb20a911fa/src/DI/Compiler.php#L202-L207 |
47
|
|
|
$containerBuilder->prepareClassList(); |
48
|
|
|
|
49
|
|
|
$extension->beforeCompile(); |
50
|
|
|
|
51
|
|
|
$eventDispatcherDefinition = $containerBuilder->getDefinition( |
52
|
|
|
$containerBuilder->getByType(EventDispatcherInterface::class) |
53
|
|
|
); |
54
|
|
|
|
55
|
|
|
$this->assertCount(1, $eventDispatcherDefinition->getSetup()); |
56
|
|
|
} |
57
|
|
|
|
58
|
|
|
|
59
|
|
|
/** |
60
|
|
|
* @return EventDispatcherExtension |
61
|
|
|
*/ |
62
|
|
|
private function getExtension() |
63
|
|
|
{ |
64
|
|
|
$extension = new EventDispatcherExtension; |
65
|
|
|
$extension->setCompiler(new Compiler(new ContainerBuilder), 'events'); |
66
|
|
|
return $extension; |
67
|
|
|
} |
68
|
|
|
|
69
|
|
|
} |
70
|
|
|
|