Skip to content
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
2 changes: 1 addition & 1 deletion Collector/ProfileClientFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ public function __construct($factory, Collector $collector, Formatter $formatter
*/
public function createClient(array $config = [])
{
$client = is_callable($this->factory) ? $this->factory($config) : $this->factory->createClient($config);
$client = is_callable($this->factory) ? call_user_func($this->factory, $config) : $this->factory->createClient($config);

if (!($client instanceof HttpClient && $client instanceof HttpAsyncClient)) {
$client = new FlexibleHttpClient($client);
Expand Down
56 changes: 56 additions & 0 deletions Tests/Unit/Collector/ProfileClientFactoryTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
<?php

namespace Http\HttplugBundle\Tests\Unit\Collector;

use Http\Client\HttpClient;
use Http\HttplugBundle\ClientFactory\ClientFactory;
use Http\HttplugBundle\Collector\Collector;
use Http\HttplugBundle\Collector\Formatter;
use Http\HttplugBundle\Collector\ProfileClient;
use Http\HttplugBundle\Collector\ProfileClientFactory;

class ProfileClientFactoryTest extends \PHPUnit_Framework_TestCase
{
/**
* @var Collector
*/
private $collector;

/**
* @var Formatter
*/
private $formatter;

/**
* @var HttpClient
*/
private $client;

public function setUp()
{
$this->collector = $this->getMockBuilder(Collector::class)->disableOriginalConstructor()->getMock();
$this->formatter = $this->getMockBuilder(Formatter::class)->disableOriginalConstructor()->getMock();
$this->client = $this->getMockBuilder(HttpClient::class)->getMock();
}

public function testCreateClientFromClientFactory()
{
$factory = $this->getMockBuilder(ClientFactory::class)->getMock();
$factory->method('createClient')->willReturn($this->client);

$subject = new ProfileClientFactory($factory, $this->collector, $this->formatter);

$this->assertInstanceOf(ProfileClient::class, $subject->createClient());
}

public function testCreateClientFromCallable()
{
$factory = function ($config) {
return $this->client;
};

$subject = new ProfileClientFactory($factory, $this->collector, $this->formatter);

$this->assertInstanceOf(ProfileClient::class, $subject->createClient());
}
}