From f358ae674529024bae1d83f4ef61d480ff3809bc Mon Sep 17 00:00:00 2001 From: David Buchmann Date: Fri, 12 Aug 2016 11:29:37 +0200 Subject: [PATCH] test that journal is set up correctly --- Tests/Functional/ServiceInstantiationTest.php | 27 +++++++++++++++++-- Tests/Resources/app/AppKernel.php | 9 ++++++- Tests/Resources/app/config/config.yml | 8 ++++-- Tests/Resources/app/config/config_debug.yml | 5 ++++ 4 files changed, 44 insertions(+), 5 deletions(-) create mode 100644 Tests/Resources/app/config/config_debug.yml diff --git a/Tests/Functional/ServiceInstantiationTest.php b/Tests/Functional/ServiceInstantiationTest.php index 1bd5abd9..7cefc810 100644 --- a/Tests/Functional/ServiceInstantiationTest.php +++ b/Tests/Functional/ServiceInstantiationTest.php @@ -2,7 +2,11 @@ namespace Http\HttplugBundle\Tests\Functional; +use Http\Client\HttpClient; +use Http\HttplugBundle\Collector\DebugPluginCollector; +use Http\HttplugBundle\Collector\PluginJournal; use Symfony\Bundle\FrameworkBundle\Test\WebTestCase; +use Symfony\Component\HttpKernel\Profiler\Profiler; class ServiceInstantiationTest extends WebTestCase { @@ -12,7 +16,7 @@ public function testHttpClient() $container = static::$kernel->getContainer(); $this->assertTrue($container->has('httplug.client')); $client = $container->get('httplug.client'); - $this->assertInstanceOf('Http\Client\HttpClient', $client); + $this->assertInstanceOf(HttpClient::class, $client); } public function testHttpClientNoDebug() @@ -21,6 +25,25 @@ public function testHttpClientNoDebug() $container = static::$kernel->getContainer(); $this->assertTrue($container->has('httplug.client')); $client = $container->get('httplug.client'); - $this->assertInstanceOf('Http\Client\HttpClient', $client); + $this->assertInstanceOf(HttpClient::class, $client); + } + + public function testDebugToolbar() + { + static::bootKernel(['debug' => true]); + $container = static::$kernel->getContainer(); + $this->assertTrue($container->has('profiler')); + $profiler = $container->get('profiler'); + $this->assertInstanceOf(Profiler::class, $profiler); + $this->assertTrue($profiler->has('httplug')); + $collector = $profiler->get('httplug'); + $this->assertInstanceOf(DebugPluginCollector::class, $collector); + /** @var PluginJournal $journal */ + $journal = $collector->getJournal(); + $plugins = $journal->getPlugins('acme'); + $this->assertEquals([ + 'httplug.plugin.stopwatch', + 'httplug.plugin.redirect', + ], $plugins); } } diff --git a/Tests/Resources/app/AppKernel.php b/Tests/Resources/app/AppKernel.php index 7446ce0d..baaf932e 100644 --- a/Tests/Resources/app/AppKernel.php +++ b/Tests/Resources/app/AppKernel.php @@ -12,9 +12,14 @@ public function registerBundles() { $bundles = [ new \Symfony\Bundle\FrameworkBundle\FrameworkBundle(), + new \Symfony\Bundle\TwigBundle\TwigBundle(), new \Http\HttplugBundle\HttplugBundle(), ]; + if (in_array($this->getEnvironment(), array('dev', 'test'))) { + $bundles[] = new Symfony\Bundle\WebProfilerBundle\WebProfilerBundle(); + } + return $bundles; } @@ -23,7 +28,9 @@ public function registerBundles() */ public function registerContainerConfiguration(LoaderInterface $loader) { - $loader->load(__DIR__.'/config/config.yml'); + $this->isDebug() + ? $loader->load(__DIR__.'/config/config_debug.yml') + : $loader->load(__DIR__.'/config/config.yml'); } /** diff --git a/Tests/Resources/app/config/config.yml b/Tests/Resources/app/config/config.yml index a333a0cb..c97ad0fe 100644 --- a/Tests/Resources/app/config/config.yml +++ b/Tests/Resources/app/config/config.yml @@ -2,5 +2,9 @@ framework: secret: php-http test: ~ -# Use auto discovery -httplug: ~ +httplug: + clients: + acme: + factory: httplug.factory.curl + plugins: + - httplug.plugin.redirect diff --git a/Tests/Resources/app/config/config_debug.yml b/Tests/Resources/app/config/config_debug.yml new file mode 100644 index 00000000..35cf1186 --- /dev/null +++ b/Tests/Resources/app/config/config_debug.yml @@ -0,0 +1,5 @@ +imports: + - { resource: config.yml } + +framework: + profiler: ~