Skip to content

Add discovered clients functional tests #182

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jul 7, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
80 changes: 80 additions & 0 deletions Tests/Functional/DiscoveredClientsTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
<?php

namespace Http\HttplugBundle\Tests\Functional;

use Http\Client\Common\PluginClient;
use Http\Client\HttpAsyncClient;
use Http\Client\HttpClient;
use Http\HttplugBundle\Collector\StackPlugin;
use Nyholm\NSA;
use Symfony\Bundle\FrameworkBundle\Test\WebTestCase;

class DiscoveredClientsTest extends WebTestCase
{
public function testDiscoveredClient()
{
$container = $this->getContainer(false);

$this->assertTrue($container->has('httplug.auto_discovery.auto_discovered_client'));

$service = $container->get('httplug.auto_discovery.auto_discovered_client');

$this->assertInstanceOf(PluginClient::class, $service);
$this->assertInstanceOf(HttpClient::class, NSA::getProperty($service, 'client'));
$this->assertEmpty(NSA::getProperty($service, 'plugins'));
}

public function testDiscoveredAsyncClient()
{
$container = $this->getContainer(false);

$this->assertTrue($container->has('httplug.auto_discovery.auto_discovered_async'));

$service = $container->get('httplug.auto_discovery.auto_discovered_async');

$this->assertInstanceOf(PluginClient::class, $service);
$this->assertInstanceOf(HttpAsyncClient::class, NSA::getProperty($service, 'client'));
$this->assertEmpty(NSA::getProperty($service, 'plugins'));
}

public function testDiscoveredClientWithProfilingEnabled()
{
$container = $this->getContainer(true);

$this->assertTrue($container->has('httplug.auto_discovery.auto_discovered_client'));

$service = $container->get('httplug.auto_discovery.auto_discovered_client');

$this->assertInstanceOf(PluginClient::class, $service);
$this->assertInstanceOf(HttpClient::class, NSA::getProperty($service, 'client'));

$plugins = NSA::getProperty($service, 'plugins');
$this->assertCount(1, $plugins);
$this->assertInstanceOf(StackPlugin::class, $plugins[0]);
$this->assertEquals('auto_discovered_client', NSA::getProperty($plugins[0], 'client'));
}

public function testDiscoveredAsyncClientWithProfilingEnabled()
{
$container = $this->getContainer(true);

$this->assertTrue($container->has('httplug.auto_discovery.auto_discovered_async'));

$service = $container->get('httplug.auto_discovery.auto_discovered_async');

$this->assertInstanceOf(PluginClient::class, $service);
$this->assertInstanceOf(HttpAsyncClient::class, NSA::getProperty($service, 'client'));

$plugins = NSA::getProperty($service, 'plugins');
$this->assertCount(1, $plugins);
$this->assertInstanceOf(StackPlugin::class, $plugins[0]);
$this->assertEquals('auto_discovered_async', NSA::getProperty($plugins[0], 'client'));
}

private function getContainer($debug)
{
static::bootKernel(['debug' => $debug]);

return static::$kernel->getContainer();
}
}
2 changes: 2 additions & 0 deletions Tests/Resources/app/config/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ framework:
test: ~

httplug:
discovery:
async_client: auto
clients:
acme:
factory: httplug.factory.curl
Expand Down
3 changes: 2 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,8 @@
"symfony/finder": "^2.7 || ^3.0",
"symfony/cache": "^3.1",
"polishsymfonycommunity/symfony-mocker-container": "^1.0",
"matthiasnoback/symfony-dependency-injection-test": "^1.0"
"matthiasnoback/symfony-dependency-injection-test": "^1.0",
"nyholm/nsa": "^1.1"
},
"conflict": {
"php-http/guzzle6-adapter": "<1.1"
Expand Down