|
| 1 | +<?php |
| 2 | + |
| 3 | +namespace Http\HttplugBundle\Tests\Functional; |
| 4 | + |
| 5 | +use Http\Client\Common\PluginClient; |
| 6 | +use Http\Client\HttpAsyncClient; |
| 7 | +use Http\Client\HttpClient; |
| 8 | +use Http\HttplugBundle\Collector\StackPlugin; |
| 9 | +use Nyholm\NSA; |
| 10 | +use Symfony\Bundle\FrameworkBundle\Test\WebTestCase; |
| 11 | + |
| 12 | +class DiscoveredClientsTest extends WebTestCase |
| 13 | +{ |
| 14 | + public function testDiscoveredClient() |
| 15 | + { |
| 16 | + $container = $this->getContainer(false); |
| 17 | + |
| 18 | + $this->assertTrue($container->has('httplug.auto_discovery.auto_discovered_client')); |
| 19 | + |
| 20 | + $service = $container->get('httplug.auto_discovery.auto_discovered_client'); |
| 21 | + |
| 22 | + $this->assertInstanceOf(PluginClient::class, $service); |
| 23 | + $this->assertInstanceOf(HttpClient::class, NSA::getProperty($service, 'client')); |
| 24 | + $this->assertEmpty(NSA::getProperty($service, 'plugins')); |
| 25 | + } |
| 26 | + |
| 27 | + public function testDiscoveredAsyncClient() |
| 28 | + { |
| 29 | + $container = $this->getContainer(false); |
| 30 | + |
| 31 | + $this->assertTrue($container->has('httplug.auto_discovery.auto_discovered_async')); |
| 32 | + |
| 33 | + $service = $container->get('httplug.auto_discovery.auto_discovered_async'); |
| 34 | + |
| 35 | + $this->assertInstanceOf(PluginClient::class, $service); |
| 36 | + $this->assertInstanceOf(HttpAsyncClient::class, NSA::getProperty($service, 'client')); |
| 37 | + $this->assertEmpty(NSA::getProperty($service, 'plugins')); |
| 38 | + } |
| 39 | + |
| 40 | + public function testDiscoveredClientWithProfilingEnabled() |
| 41 | + { |
| 42 | + $container = $this->getContainer(true); |
| 43 | + |
| 44 | + $this->assertTrue($container->has('httplug.auto_discovery.auto_discovered_client')); |
| 45 | + |
| 46 | + $service = $container->get('httplug.auto_discovery.auto_discovered_client'); |
| 47 | + |
| 48 | + $this->assertInstanceOf(PluginClient::class, $service); |
| 49 | + $this->assertInstanceOf(HttpClient::class, NSA::getProperty($service, 'client')); |
| 50 | + |
| 51 | + $plugins = NSA::getProperty($service, 'plugins'); |
| 52 | + $this->assertCount(1, $plugins); |
| 53 | + $this->assertInstanceOf(StackPlugin::class, $plugins[0]); |
| 54 | + $this->assertEquals('auto_discovered_client', NSA::getProperty($plugins[0], 'client')); |
| 55 | + } |
| 56 | + |
| 57 | + public function testDiscoveredAsyncClientWithProfilingEnabled() |
| 58 | + { |
| 59 | + $container = $this->getContainer(true); |
| 60 | + |
| 61 | + $this->assertTrue($container->has('httplug.auto_discovery.auto_discovered_async')); |
| 62 | + |
| 63 | + $service = $container->get('httplug.auto_discovery.auto_discovered_async'); |
| 64 | + |
| 65 | + $this->assertInstanceOf(PluginClient::class, $service); |
| 66 | + $this->assertInstanceOf(HttpAsyncClient::class, NSA::getProperty($service, 'client')); |
| 67 | + |
| 68 | + $plugins = NSA::getProperty($service, 'plugins'); |
| 69 | + $this->assertCount(1, $plugins); |
| 70 | + $this->assertInstanceOf(StackPlugin::class, $plugins[0]); |
| 71 | + $this->assertEquals('auto_discovered_async', NSA::getProperty($plugins[0], 'client')); |
| 72 | + } |
| 73 | + |
| 74 | + private function getContainer($debug) |
| 75 | + { |
| 76 | + static::bootKernel(['debug' => $debug]); |
| 77 | + |
| 78 | + return static::$kernel->getContainer(); |
| 79 | + } |
| 80 | +} |
0 commit comments