|
| 1 | +<?php declare(strict_types=1); |
| 2 | + |
| 3 | +namespace BabDev\WebSocketBundle\Tests\DependencyInjection\Compiler; |
| 4 | + |
| 5 | +use BabDev\WebSocketBundle\DependencyInjection\Compiler\ConfigureHttpFactoriesCompilerPass; |
| 6 | +use GuzzleHttp\Psr7\HttpFactory; |
| 7 | +use Matthias\SymfonyDependencyInjectionTest\PhpUnit\AbstractCompilerPassTestCase; |
| 8 | +use Psr\Http\Message\ResponseFactoryInterface; |
| 9 | +use Ratchet\RFC6455\Handshake\RequestVerifier; |
| 10 | +use Ratchet\RFC6455\Handshake\ServerNegotiator; |
| 11 | +use Symfony\Component\DependencyInjection\Argument\AbstractArgument; |
| 12 | +use Symfony\Component\DependencyInjection\ContainerBuilder; |
| 13 | +use Symfony\Component\DependencyInjection\Definition; |
| 14 | +use Symfony\Component\DependencyInjection\Reference; |
| 15 | + |
| 16 | +final class ConfigureHttpFactoriesCompilerPassTest extends AbstractCompilerPassTestCase |
| 17 | +{ |
| 18 | + /** |
| 19 | + * @testdox Uses the PSR-17 factory defined by the application |
| 20 | + */ |
| 21 | + public function testUsesThePsr17FactoryDefinedByTheApplication(): void |
| 22 | + { |
| 23 | + $this->container->register('babdev_websocket_server.rfc6455.server_negotiator', ServerNegotiator::class) |
| 24 | + ->setArguments([ |
| 25 | + new Definition(RequestVerifier::class), |
| 26 | + new AbstractArgument('response factory'), |
| 27 | + ]) |
| 28 | + ; |
| 29 | + |
| 30 | + $this->container->setAlias(ResponseFactoryInterface::class, HttpFactory::class); |
| 31 | + |
| 32 | + $this->compile(); |
| 33 | + |
| 34 | + $this->assertContainerBuilderHasServiceDefinitionWithArgument('babdev_websocket_server.rfc6455.server_negotiator', 1, new Reference(ResponseFactoryInterface::class)); |
| 35 | + } |
| 36 | + |
| 37 | + public function testUsesTheGuzzleFactoryWhenNoFactoryIsDefinedByTheApplication(): void |
| 38 | + { |
| 39 | + $this->container->register('babdev_websocket_server.rfc6455.server_negotiator', ServerNegotiator::class) |
| 40 | + ->setArguments([ |
| 41 | + new Definition(RequestVerifier::class), |
| 42 | + new AbstractArgument('response factory'), |
| 43 | + ]) |
| 44 | + ; |
| 45 | + |
| 46 | + $this->compile(); |
| 47 | + |
| 48 | + $this->assertContainerBuilderHasService('.babdev_websocket_server.psr17_response_factory'); |
| 49 | + $this->assertContainerBuilderHasServiceDefinitionWithArgument('babdev_websocket_server.rfc6455.server_negotiator', 1, $this->container->getDefinition('.babdev_websocket_server.psr17_response_factory')); |
| 50 | + } |
| 51 | + |
| 52 | + protected function registerCompilerPass(ContainerBuilder $container): void |
| 53 | + { |
| 54 | + $container->addCompilerPass(new ConfigureHttpFactoriesCompilerPass()); |
| 55 | + } |
| 56 | +} |
0 commit comments