|
3 | 3 | namespace SimpleBus\SymfonyBridge\Tests\SymfonyBundle\DependencyInjection\Compiler; |
4 | 4 |
|
5 | 5 | use SimpleBus\SymfonyBridge\DependencyInjection\Compiler\ConfigureMiddlewares; |
| 6 | +use SimpleBus\SymfonyBridge\Tests\Functional\SmokeTest\Auto\AuteEvent1; |
| 7 | +use SimpleBus\SymfonyBridge\Tests\Functional\SmokeTest\Auto\AuteEvent2; |
| 8 | +use SimpleBus\SymfonyBridge\Tests\Functional\SmokeTest\Auto\AuteEvent3; |
6 | 9 | use Symfony\Component\DependencyInjection\ContainerBuilder; |
7 | 10 | use Symfony\Component\DependencyInjection\Definition; |
| 11 | +use Symfony\Component\HttpKernel\Kernel; |
8 | 12 |
|
9 | 13 | class ConfigureMiddlewaresTest extends \PHPUnit_Framework_TestCase |
10 | 14 | { |
@@ -35,41 +39,57 @@ protected function setUp() |
35 | 39 | */ |
36 | 40 | public function it_configures_a_chain_of_buses_according_to_the_given_priorities() |
37 | 41 | { |
38 | | - $this->createBusDefinition('middleware100', 100); |
39 | | - $this->createBusDefinition('middleware-100', -100); |
40 | | - $this->createBusDefinition('middleware200', 200); |
| 42 | + $classes = [ |
| 43 | + AuteEvent1::class => 100, |
| 44 | + AuteEvent2::class => -100, |
| 45 | + AuteEvent3::class => 200, |
| 46 | + ]; |
| 47 | + |
| 48 | + foreach ($classes as $class => $priority) { |
| 49 | + $this->createBusDefinition($class, $priority); |
| 50 | + } |
41 | 51 |
|
42 | 52 | $this->container->compile(); |
43 | 53 |
|
44 | | - $this->commandBusContainsMiddlewares(array('middleware200', 'middleware100', 'middleware-100')); |
| 54 | + $this->commandBusContainsMiddlewares($classes); |
45 | 55 | } |
46 | 56 |
|
47 | | - private function createBusDefinition($id, $priority) |
| 57 | + private function createBusDefinition($class, $priority) |
48 | 58 | { |
49 | | - $definition = new Definition('stdClass'); |
| 59 | + $definition = new Definition($class); |
50 | 60 | $definition->addTag($this->middlewareTag, array('priority' => $priority)); |
51 | 61 |
|
52 | | - $this->container->setDefinition($id, $definition); |
| 62 | + $this->container->setDefinition($class, $definition); |
53 | 63 |
|
54 | 64 | return $definition; |
55 | 65 | } |
56 | 66 |
|
57 | | - private function commandBusContainsMiddlewares($expectedMiddlewareIds) |
| 67 | + private function commandBusContainsMiddlewares($expectedMiddlewareclasses) |
58 | 68 | { |
59 | | - $actualMiddlewareIds = []; |
| 69 | + $actualMiddlewareClasses = []; |
60 | 70 |
|
61 | 71 | foreach ($this->mainBusDefinition->getMethodCalls() as $methodCall) { |
62 | 72 | list($method, $arguments) = $methodCall; |
63 | 73 | $this->assertSame('appendMiddleware', $method); |
64 | 74 | $this->assertCount(1, $arguments); |
65 | 75 | $referencedService = $arguments[0]; |
66 | | - $this->assertInstanceOf( |
67 | | - 'Symfony\Component\DependencyInjection\Reference', |
68 | | - $referencedService |
69 | | - ); |
70 | | - $actualMiddlewareIds[] = (string) $referencedService; |
| 76 | + |
| 77 | + if (Kernel::VERSION_ID >= 40000) { |
| 78 | + $this->assertInstanceOf( |
| 79 | + 'Symfony\Component\DependencyInjection\Definition', |
| 80 | + $referencedService |
| 81 | + ); |
| 82 | + } else { |
| 83 | + $this->assertInstanceOf( |
| 84 | + 'Symfony\Component\DependencyInjection\Reference', |
| 85 | + $referencedService |
| 86 | + ); |
| 87 | + $referencedService = $this->container->getDefinition((string) $referencedService); |
| 88 | + } |
| 89 | + |
| 90 | + $actualMiddlewareClasses[$referencedService->getClass()] = $referencedService->getTag('middleware')[0]['priority']; |
71 | 91 | } |
72 | 92 |
|
73 | | - $this->assertEquals($expectedMiddlewareIds, $actualMiddlewareIds); |
| 93 | + $this->assertEquals($expectedMiddlewareclasses, $actualMiddlewareClasses); |
74 | 94 | } |
75 | 95 | } |
0 commit comments