use GuzzleHttp\HandlerStack;
use GuzzleHttp\Psr7\Response as GuzzleResponse;
use GuzzleHttp\Middleware;
+use PHPUnit\Framework\TestCase;
use Symfony\Component\BrowserKit\Cookie;
/**
* @author Michael Dowling <michael@guzzlephp.org>
* @author Charles Sarrazin <charles@sarraz.in>
*/
-class ClientTest extends \PHPUnit_Framework_TestCase
+class ClientTest extends TestCase
{
protected $history;
/** @var MockHandler */
protected $mock;
- protected function getGuzzle(array $responses = [])
+ protected function getGuzzle(array $responses = [], array $extraConfig = [])
{
if (empty($responses)) {
$responses = [new GuzzleResponse(200, [], '<html><body><p>Hi</p></body></html>')];
$handlerStack = HandlerStack::create($this->mock);
$this->history = [];
$handlerStack->push(Middleware::history($this->history));
- $guzzle = new GuzzleClient(array('redirect.disable' => true, 'base_uri' => '', 'handler' => $handlerStack));
+ $guzzle = new GuzzleClient(array_merge(array('redirect.disable' => true, 'base_uri' => '', 'handler' => $handlerStack), $extraConfig));
return $guzzle;
}
$this->assertInternalType('array', array_shift($headers), 'Header not converted from Guzzle\Http\Message\Header to array');
}
+ /**
+ * @expectedException \GuzzleHttp\Exception\RequestException
+ */
public function testNullResponseException()
{
- $this->setExpectedException('GuzzleHttp\Exception\RequestException');
$guzzle = $this->getGuzzle([
- new RequestException('', $this->getMock('Psr\Http\Message\RequestInterface')),
+ new RequestException('', $this->getMockBuilder('Psr\Http\Message\RequestInterface')->getMock()),
]);
$client = new Client();
$client->setClient($guzzle);
$this->assertEquals([], $headersReflectionProperty->getValue($client));
$this->assertNull($authReflectionProperty->getValue($client));
}
+
+ public function testSetBaseUri()
+ {
+ $guzzle = $this->getGuzzle([], ['base_uri' => 'http://example.com/']);
+ $client = new Client();
+ $client->setClient($guzzle);
+
+ $this->assertNull($client->getServerParameter('HTTPS', null));
+ $this->assertSame('example.com', $client->getServerParameter('HTTP_HOST'));
+
+ $client->request('GET', '/foo');
+ $this->assertSame('http://example.com/foo', (string) end($this->history)['request']->getUri());
+ }
+
+ public function testSetHttpsBaseUri()
+ {
+ $guzzle = $this->getGuzzle([], ['base_uri' => 'https://example.com:1234']);
+ $client = new Client();
+ $client->setClient($guzzle);
+
+ $this->assertSame('on', $client->getServerParameter('HTTPS'));
+ $this->assertSame('example.com:1234', $client->getServerParameter('HTTP_HOST'));
+
+ $client->request('GET', '/foo');
+ $this->assertSame('https://example.com:1234/foo', (string) end($this->history)['request']->getUri());
+ }
+
+ /**
+ * @expectedException \InvalidArgumentException
+ * @expectedExceptionMessage Setting a path in the Guzzle "base_uri" config option is not supported by Goutte yet.
+ */
+ public function testSetBaseUriWithPath()
+ {
+ $guzzle = $this->getGuzzle([], ['base_uri' => 'http://example.com/foo/']);
+ $client = new Client();
+ $client->setClient($guzzle);
+ }
}