Updated Drupal to 8.6. This goes with the following updates because it's possible...
[yaffs-website] / vendor / fabpot / goutte / Goutte / Tests / ClientTest.php
index 4a633e473e6210107cce15084788cc8e6b11a300..c57e0e24be52ee8aff0dedcb6d14e5867f1a8017 100644 (file)
@@ -18,6 +18,7 @@ use GuzzleHttp\Handler\MockHandler;
 use GuzzleHttp\HandlerStack;
 use GuzzleHttp\Psr7\Response as GuzzleResponse;
 use GuzzleHttp\Middleware;
+use PHPUnit\Framework\TestCase;
 use Symfony\Component\BrowserKit\Cookie;
 
 /**
@@ -26,13 +27,13 @@ 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>')];
@@ -41,7 +42,7 @@ class ClientTest extends \PHPUnit_Framework_TestCase
         $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;
     }
@@ -337,11 +338,13 @@ class ClientTest extends \PHPUnit_Framework_TestCase
         $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);
@@ -404,4 +407,41 @@ class ClientTest extends \PHPUnit_Framework_TestCase
         $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);
+    }
 }