11<?php declare (strict_types = 1 );
22
3- /**
4- * Test: DI\EventDispatcherExtensions
5- */
6-
73use Contributte \EventDispatcher \DI \EventDispatcherExtension ;
4+ use Contributte \Tester \Toolkit ;
5+ use Contributte \Tester \Utils \ContainerBuilder ;
86use Nette \DI \Compiler ;
9- use Nette \DI \Container ;
10- use Nette \DI \ContainerLoader ;
117use Symfony \Component \EventDispatcher \EventDispatcherInterface ;
128use Symfony \Component \EventDispatcher \EventSubscriberInterface ;
139use Symfony \Contracts \EventDispatcher \Event ;
@@ -20,18 +16,15 @@ use Tests\Fixtures\PrioritizedSubscriber;
2016require_once __DIR__ . '/../../bootstrap.php ' ;
2117
2218// Dispatch event with NO defined subscriber for event
23- test (function (): void {
24- $ loader = new ContainerLoader (TEMP_DIR , true );
25- $ class = $ loader ->load (function (Compiler $ compiler ): void {
26- $ compiler ->addExtension ('events ' , new EventDispatcherExtension ());
27- $ compiler ->loadConfig (FileMock ::create ('
28- services:
29- foo: Tests\Fixtures\FooSubscriber
30- ' , 'neon ' ));
31- }, 1 );
32-
33- /** @var Container $container */
34- $ container = new $ class ();
19+ Toolkit ::test (function (): void {
20+ $ container = ContainerBuilder ::of ()
21+ ->withCompiler (function (Compiler $ compiler ): void {
22+ $ compiler ->addExtension ('events ' , new EventDispatcherExtension ());
23+ $ compiler ->loadConfig (FileMock ::create ('
24+ services:
25+ foo: Tests\Fixtures\FooSubscriber
26+ ' , 'neon ' ));
27+ })->build ();
3528
3629 /** @var EventDispatcherInterface $em */
3730 $ em = $ container ->getByType (EventDispatcherInterface::class);
@@ -57,18 +50,15 @@ test(function (): void {
5750});
5851
5952// Dispatch event with defined subscriber
60- test (function (): void {
61- $ loader = new ContainerLoader ( TEMP_DIR , true );
62- $ class = $ loader -> load (function (Compiler $ compiler ): void {
63- $ compiler ->addExtension ('events ' , new EventDispatcherExtension ());
64- $ compiler ->loadConfig (FileMock ::create ('
53+ Toolkit :: test (function (): void {
54+ $ container = ContainerBuilder :: of ()
55+ -> withCompiler (function (Compiler $ compiler ): void {
56+ $ compiler ->addExtension ('events ' , new EventDispatcherExtension ());
57+ $ compiler ->loadConfig (FileMock ::create ('
6558 services:
6659 foo: Tests\Fixtures\FooSubscriber
6760 ' , 'neon ' ));
68- }, 2 );
69-
70- /** @var Container $container */
71- $ container = new $ class ();
61+ })->build ();
7262
7363 /** @var EventDispatcherInterface $em */
7464 $ em = $ container ->getByType (EventDispatcherInterface::class);
@@ -101,36 +91,30 @@ test(function (): void {
10191});
10292
10393// Register multiple subscribers
104- test (function (): void {
105- $ loader = new ContainerLoader ( TEMP_DIR , true );
106- $ class = $ loader -> load (function (Compiler $ compiler ): void {
107- $ compiler ->addExtension ('events ' , new EventDispatcherExtension ());
108- $ compiler ->loadConfig (FileMock ::create ('
94+ Toolkit :: test (function (): void {
95+ $ container = ContainerBuilder :: of ()
96+ -> withCompiler (function (Compiler $ compiler ): void {
97+ $ compiler ->addExtension ('events ' , new EventDispatcherExtension ());
98+ $ compiler ->loadConfig (FileMock ::create ('
10999 services:
110100 foo: Tests\Fixtures\FooSubscriber
111101 bar: Tests\Fixtures\BarSubscriber
112102 ' , 'neon ' ));
113- }, 3 );
114-
115- /** @var Container $container */
116- $ container = new $ class ();
103+ })->build ();
117104
118105 Assert ::count (2 , $ container ->findByType (EventSubscriberInterface::class));
119106});
120107
121108// Register subscriber with more events
122- test (function (): void {
123- $ loader = new ContainerLoader ( TEMP_DIR , true );
124- $ class = $ loader -> load (function (Compiler $ compiler ): void {
125- $ compiler ->addExtension ('events ' , new EventDispatcherExtension ());
126- $ compiler ->loadConfig (FileMock ::create ('
109+ Toolkit :: test (function (): void {
110+ $ container = ContainerBuilder :: of ()
111+ -> withCompiler (function (Compiler $ compiler ): void {
112+ $ compiler ->addExtension ('events ' , new EventDispatcherExtension ());
113+ $ compiler ->loadConfig (FileMock ::create ('
127114 services:
128115 multi: Tests\Fixtures\MultiSubscriber
129116 ' , 'neon ' ));
130- }, 4 );
131-
132- /** @var Container $container */
133- $ container = new $ class ();
117+ })->build ();
134118
135119 /** @var EventDispatcherInterface $em */
136120 $ em = $ container ->getByType (EventDispatcherInterface::class);
@@ -154,18 +138,15 @@ test(function (): void {
154138});
155139
156140// Register prioritized subscriber
157- test (function (): void {
158- $ loader = new ContainerLoader ( TEMP_DIR , true );
159- $ class = $ loader -> load (function (Compiler $ compiler ): void {
160- $ compiler ->addExtension ('events ' , new EventDispatcherExtension ());
161- $ compiler ->loadConfig (FileMock ::create ('
141+ Toolkit :: test (function (): void {
142+ $ container = ContainerBuilder :: of ()
143+ -> withCompiler (function (Compiler $ compiler ): void {
144+ $ compiler ->addExtension ('events ' , new EventDispatcherExtension ());
145+ $ compiler ->loadConfig (FileMock ::create ('
162146 services:
163147 prioritized: Tests\Fixtures\PrioritizedSubscriber
164148 ' , 'neon ' ));
165- }, 5 );
166-
167- /** @var Container $container */
168- $ container = new $ class ();
149+ })->build ();
169150
170151 /** @var EventDispatcherInterface $em */
171152 $ em = $ container ->getByType (EventDispatcherInterface::class);
@@ -186,15 +167,12 @@ test(function (): void {
186167});
187168
188169// Dispatch event with NO subscribers at all
189- test (function (): void {
190- $ loader = new ContainerLoader (TEMP_DIR , true );
191- $ class = $ loader ->load (function (Compiler $ compiler ): void {
192- $ compiler ->addExtension ('events ' , new EventDispatcherExtension ());
193- $ compiler ->loadConfig (FileMock ::create ('' , 'neon ' ));
194- }, 6 );
195-
196- /** @var Container $container */
197- $ container = new $ class ();
170+ Toolkit ::test (function (): void {
171+ $ container = ContainerBuilder ::of ()
172+ ->withCompiler (function (Compiler $ compiler ): void {
173+ $ compiler ->addExtension ('events ' , new EventDispatcherExtension ());
174+ $ compiler ->loadConfig (FileMock ::create ('' , 'neon ' ));
175+ })->build ();
198176
199177 /** @var EventDispatcherInterface $em */
200178 $ em = $ container ->getByType (EventDispatcherInterface::class);
0 commit comments