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