Include all vendor files in the repo to be easier for people
This commit is contained in:
67
vendor/lusitanian/oauth/tests/Unit/Common/Http/Client/AbstractClientTest.php
vendored
Normal file
67
vendor/lusitanian/oauth/tests/Unit/Common/Http/Client/AbstractClientTest.php
vendored
Normal file
@@ -0,0 +1,67 @@
|
||||
<?php
|
||||
|
||||
namespace OAuthTest\Unit\Common\Http;
|
||||
|
||||
class AbstractClientTest extends \PHPUnit_Framework_TestCase
|
||||
{
|
||||
/**
|
||||
* @covers OAuth\Common\Http\Client\AbstractClient::__construct
|
||||
*/
|
||||
public function testConstructCorrectInterface()
|
||||
{
|
||||
$client = $this->getMockForAbstractClass('\\OAuth\\Common\\Http\\Client\\AbstractClient');
|
||||
|
||||
$this->assertInstanceOf('\\OAuth\\Common\\Http\\Client\\ClientInterface', $client);
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers OAuth\Common\Http\Client\AbstractClient::__construct
|
||||
* @covers OAuth\Common\Http\Client\AbstractClient::setMaxRedirects
|
||||
*/
|
||||
public function testSetMaxRedirects()
|
||||
{
|
||||
$client = $this->getMockForAbstractClass('\\OAuth\\Common\\Http\\Client\\AbstractClient');
|
||||
|
||||
$this->assertInstanceOf('\\OAuth\\Common\\Http\\Client\\AbstractClient', $client->setMaxRedirects(10));
|
||||
$this->assertInstanceOf('\\OAuth\\Common\\Http\\Client\\ClientInterface', $client->setMaxRedirects(10));
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers OAuth\Common\Http\Client\AbstractClient::__construct
|
||||
* @covers OAuth\Common\Http\Client\AbstractClient::setTimeout
|
||||
*/
|
||||
public function testSetTimeout()
|
||||
{
|
||||
$client = $this->getMockForAbstractClass('\\OAuth\\Common\\Http\\Client\\AbstractClient');
|
||||
|
||||
$this->assertInstanceOf('\\OAuth\\Common\\Http\\Client\\AbstractClient', $client->setTimeout(25));
|
||||
$this->assertInstanceOf('\\OAuth\\Common\\Http\\Client\\ClientInterface', $client->setTimeout(25));
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers OAuth\Common\Http\Client\AbstractClient::__construct
|
||||
* @covers OAuth\Common\Http\Client\AbstractClient::normalizeHeaders
|
||||
*/
|
||||
public function testNormalizeHeaders()
|
||||
{
|
||||
$client = $this->getMockForAbstractClass('\\OAuth\\Common\\Http\\Client\\AbstractClient');
|
||||
|
||||
$original = array(
|
||||
'lowercasekey' => 'lowercasevalue',
|
||||
'UPPERCASEKEY' => 'UPPERCASEVALUE',
|
||||
'mIxEdCaSeKey' => 'MiXeDcAsEvAlUe',
|
||||
'31i71casekey' => '31i71casevalue',
|
||||
);
|
||||
|
||||
$goal = array(
|
||||
'lowercasekey' => 'Lowercasekey: lowercasevalue',
|
||||
'UPPERCASEKEY' => 'Uppercasekey: UPPERCASEVALUE',
|
||||
'mIxEdCaSeKey' => 'Mixedcasekey: MiXeDcAsEvAlUe',
|
||||
'31i71casekey' => '31i71casekey: 31i71casevalue',
|
||||
);
|
||||
|
||||
$client->normalizeHeaders($original);
|
||||
|
||||
$this->assertSame($goal, $original);
|
||||
}
|
||||
}
|
||||
378
vendor/lusitanian/oauth/tests/Unit/Common/Http/Client/CurlClientTest.php
vendored
Normal file
378
vendor/lusitanian/oauth/tests/Unit/Common/Http/Client/CurlClientTest.php
vendored
Normal file
@@ -0,0 +1,378 @@
|
||||
<?php
|
||||
|
||||
namespace OAuthTest\Unit\Common\Http\Client;
|
||||
|
||||
use OAuth\Common\Http\Client\CurlClient;
|
||||
|
||||
class CurlClientTest extends \PHPUnit_Framework_TestCase
|
||||
{
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public function testConstructCorrectInstance()
|
||||
{
|
||||
$client = new CurlClient();
|
||||
|
||||
$this->assertInstanceOf('\\OAuth\\Common\\Http\\Client\\AbstractClient', $client);
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers OAuth\Common\Http\Client\CurlClient::setForceSSL3
|
||||
*/
|
||||
public function testSetForceSSL3()
|
||||
{
|
||||
$client = new CurlClient();
|
||||
|
||||
$this->assertInstanceOf('\\OAuth\\Common\\Http\\Client\\CurlClient', $client->setForceSSL3(true));
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers OAuth\Common\Http\Client\CurlClient::retrieveResponse
|
||||
*/
|
||||
public function testRetrieveResponseThrowsExceptionOnGetRequestWithBody()
|
||||
{
|
||||
$this->setExpectedException('\\InvalidArgumentException');
|
||||
|
||||
$client = new CurlClient();
|
||||
|
||||
$client->retrieveResponse(
|
||||
$this->getMock('\\OAuth\\Common\\Http\\Uri\\UriInterface'),
|
||||
'foo',
|
||||
array(),
|
||||
'GET'
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers OAuth\Common\Http\Client\CurlClient::retrieveResponse
|
||||
*/
|
||||
public function testRetrieveResponseThrowsExceptionOnGetRequestWithBodyMethodConvertedToUpper()
|
||||
{
|
||||
$this->setExpectedException('\\InvalidArgumentException');
|
||||
|
||||
$client = new CurlClient();
|
||||
|
||||
$client->retrieveResponse(
|
||||
$this->getMock('\\OAuth\\Common\\Http\\Uri\\UriInterface'),
|
||||
'foo',
|
||||
array(),
|
||||
'get'
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers OAuth\Common\Http\Client\StreamClient::retrieveResponse
|
||||
* @covers OAuth\Common\Http\Client\StreamClient::generateStreamContext
|
||||
*/
|
||||
public function testRetrieveResponseDefaultUserAgent()
|
||||
{
|
||||
$endPoint = $this->getMock('\\OAuth\\Common\\Http\\Uri\\UriInterface');
|
||||
$endPoint->expects($this->any())
|
||||
->method('getHost')
|
||||
->will($this->returnValue('httpbin.org'));
|
||||
$endPoint->expects($this->any())
|
||||
->method('getAbsoluteUri')
|
||||
->will($this->returnValue('http://httpbin.org/get'));
|
||||
|
||||
$client = new CurlClient();
|
||||
|
||||
$response = $client->retrieveResponse(
|
||||
$endPoint,
|
||||
'',
|
||||
array(),
|
||||
'get'
|
||||
);
|
||||
|
||||
$response = json_decode($response, true);
|
||||
|
||||
$this->assertSame('PHPoAuthLib', $response['headers']['User-Agent']);
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers OAuth\Common\Http\Client\StreamClient::retrieveResponse
|
||||
* @covers OAuth\Common\Http\Client\StreamClient::generateStreamContext
|
||||
*/
|
||||
public function testRetrieveResponseCustomUserAgent()
|
||||
{
|
||||
$endPoint = $this->getMock('\\OAuth\\Common\\Http\\Uri\\UriInterface');
|
||||
$endPoint->expects($this->any())
|
||||
->method('getHost')
|
||||
->will($this->returnValue('httpbin.org'));
|
||||
$endPoint->expects($this->any())
|
||||
->method('getAbsoluteUri')
|
||||
->will($this->returnValue('http://httpbin.org/get'));
|
||||
|
||||
$client = new CurlClient('My Super Awesome Http Client');
|
||||
|
||||
$response = $client->retrieveResponse(
|
||||
$endPoint,
|
||||
'',
|
||||
array(),
|
||||
'get'
|
||||
);
|
||||
|
||||
$response = json_decode($response, true);
|
||||
|
||||
$this->assertSame('My Super Awesome Http Client', $response['headers']['User-Agent']);
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers OAuth\Common\Http\Client\CurlClient::retrieveResponse
|
||||
*/
|
||||
public function testRetrieveResponseWithCustomContentType()
|
||||
{
|
||||
$endPoint = $this->getMock('\\OAuth\\Common\\Http\\Uri\\UriInterface');
|
||||
$endPoint->expects($this->any())
|
||||
->method('getHost')
|
||||
->will($this->returnValue('httpbin.org'));
|
||||
$endPoint->expects($this->any())
|
||||
->method('getAbsoluteUri')
|
||||
->will($this->returnValue('http://httpbin.org/get'));
|
||||
|
||||
$client = new CurlClient();
|
||||
|
||||
$response = $client->retrieveResponse(
|
||||
$endPoint,
|
||||
'',
|
||||
array('Content-Type' => 'foo/bar'),
|
||||
'get'
|
||||
);
|
||||
|
||||
$response = json_decode($response, true);
|
||||
|
||||
$this->assertSame('foo/bar', $response['headers']['Content-Type']);
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers OAuth\Common\Http\Client\CurlClient::retrieveResponse
|
||||
*/
|
||||
public function testRetrieveResponseWithFormUrlEncodedContentType()
|
||||
{
|
||||
$endPoint = $this->getMock('\\OAuth\\Common\\Http\\Uri\\UriInterface');
|
||||
$endPoint->expects($this->any())
|
||||
->method('getHost')
|
||||
->will($this->returnValue('httpbin.org'));
|
||||
$endPoint->expects($this->any())
|
||||
->method('getAbsoluteUri')
|
||||
->will($this->returnValue('http://httpbin.org/post'));
|
||||
|
||||
$client = new CurlClient();
|
||||
|
||||
$response = $client->retrieveResponse(
|
||||
$endPoint,
|
||||
array('foo' => 'bar', 'baz' => 'fab'),
|
||||
array(),
|
||||
'POST'
|
||||
);
|
||||
|
||||
$response = json_decode($response, true);
|
||||
|
||||
$this->assertSame('application/x-www-form-urlencoded', $response['headers']['Content-Type']);
|
||||
$this->assertEquals(array('foo' => 'bar', 'baz' => 'fab'), $response['form']);
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers OAuth\Common\Http\Client\CurlClient::retrieveResponse
|
||||
*/
|
||||
public function testRetrieveResponseHost()
|
||||
{
|
||||
$endPoint = $this->getMock('\\OAuth\\Common\\Http\\Uri\\UriInterface');
|
||||
$endPoint->expects($this->any())
|
||||
->method('getHost')
|
||||
->will($this->returnValue('httpbin.org'));
|
||||
$endPoint->expects($this->any())
|
||||
->method('getAbsoluteUri')
|
||||
->will($this->returnValue('http://httpbin.org/post'));
|
||||
|
||||
$client = new CurlClient();
|
||||
|
||||
$response = $client->retrieveResponse(
|
||||
$endPoint,
|
||||
array('foo' => 'bar', 'baz' => 'fab'),
|
||||
array(),
|
||||
'POST'
|
||||
);
|
||||
|
||||
$response = json_decode($response, true);
|
||||
|
||||
$this->assertSame('httpbin.org', $response['headers']['Host']);
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers OAuth\Common\Http\Client\CurlClient::retrieveResponse
|
||||
*/
|
||||
public function testRetrieveResponsePostRequestWithRequestBodyAsString()
|
||||
{
|
||||
$endPoint = $this->getMock('\\OAuth\\Common\\Http\\Uri\\UriInterface');
|
||||
$endPoint->expects($this->any())
|
||||
->method('getHost')
|
||||
->will($this->returnValue('httpbin.org'));
|
||||
$endPoint->expects($this->any())
|
||||
->method('getAbsoluteUri')
|
||||
->will($this->returnValue('http://httpbin.org/post'));
|
||||
|
||||
$formData = array('baz' => 'fab', 'foo' => 'bar');
|
||||
|
||||
$client = new CurlClient();
|
||||
|
||||
$response = $client->retrieveResponse(
|
||||
$endPoint,
|
||||
$formData,
|
||||
array(),
|
||||
'POST'
|
||||
);
|
||||
|
||||
$response = json_decode($response, true);
|
||||
|
||||
$this->assertSame($formData, $response['form']);
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers OAuth\Common\Http\Client\CurlClient::retrieveResponse
|
||||
*/
|
||||
public function testRetrieveResponsePutRequestWithRequestBodyAsString()
|
||||
{
|
||||
$endPoint = $this->getMock('\\OAuth\\Common\\Http\\Uri\\UriInterface');
|
||||
$endPoint->expects($this->any())
|
||||
->method('getHost')
|
||||
->will($this->returnValue('httpbin.org'));
|
||||
$endPoint->expects($this->any())
|
||||
->method('getAbsoluteUri')
|
||||
->will($this->returnValue('http://httpbin.org/put'));
|
||||
|
||||
$formData = array('baz' => 'fab', 'foo' => 'bar');
|
||||
|
||||
$client = new CurlClient();
|
||||
|
||||
$response = $client->retrieveResponse(
|
||||
$endPoint,
|
||||
$formData,
|
||||
array(),
|
||||
'PUT'
|
||||
);
|
||||
|
||||
$response = json_decode($response, true);
|
||||
|
||||
$this->assertSame($formData, $response['form']);
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers OAuth\Common\Http\Client\CurlClient::retrieveResponse
|
||||
*/
|
||||
public function testRetrieveResponsePutRequestWithRequestBodyAsStringNoRedirects()
|
||||
{
|
||||
$endPoint = $this->getMock('\\OAuth\\Common\\Http\\Uri\\UriInterface');
|
||||
$endPoint->expects($this->any())
|
||||
->method('getHost')
|
||||
->will($this->returnValue('httpbin.org'));
|
||||
$endPoint->expects($this->any())
|
||||
->method('getAbsoluteUri')
|
||||
->will($this->returnValue('http://httpbin.org/put'));
|
||||
|
||||
$formData = array('baz' => 'fab', 'foo' => 'bar');
|
||||
|
||||
$client = new CurlClient();
|
||||
|
||||
$client->setMaxRedirects(0);
|
||||
|
||||
$response = $client->retrieveResponse(
|
||||
$endPoint,
|
||||
$formData,
|
||||
array(),
|
||||
'PUT'
|
||||
);
|
||||
|
||||
$response = json_decode($response, true);
|
||||
|
||||
$this->assertSame($formData, $response['form']);
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers OAuth\Common\Http\Client\CurlClient::retrieveResponse
|
||||
*/
|
||||
public function testRetrieveResponseWithForcedSsl3()
|
||||
{
|
||||
$endPoint = $this->getMock('\\OAuth\\Common\\Http\\Uri\\UriInterface');
|
||||
$endPoint->expects($this->any())
|
||||
->method('getHost')
|
||||
->will($this->returnValue('httpbin.org'));
|
||||
$endPoint->expects($this->any())
|
||||
->method('getAbsoluteUri')
|
||||
->will($this->returnValue('https://httpbin.org/get'));
|
||||
|
||||
$client = new CurlClient();
|
||||
|
||||
$client->setForceSSL3(true);
|
||||
|
||||
$response = $client->retrieveResponse(
|
||||
$endPoint,
|
||||
'',
|
||||
array('Content-Type' => 'foo/bar'),
|
||||
'get'
|
||||
);
|
||||
|
||||
$response = json_decode($response, true);
|
||||
|
||||
$this->assertSame('foo/bar', $response['headers']['Content-Type']);
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers OAuth\Common\Http\Client\CurlClient::retrieveResponse
|
||||
*/
|
||||
public function testRetrieveResponseThrowsExceptionOnInvalidUrl()
|
||||
{
|
||||
$this->setExpectedException('\\OAuth\\Common\\Http\\Exception\\TokenResponseException');
|
||||
|
||||
$endPoint = $this->getMock('\\OAuth\\Common\\Http\\Uri\\UriInterface');
|
||||
$endPoint->expects($this->any())
|
||||
->method('getHost')
|
||||
->will($this->returnValue('jkehfkefcmekjhcnkerjh'));
|
||||
$endPoint->expects($this->any())
|
||||
->method('getAbsoluteUri')
|
||||
->will($this->returnValue('jkehfkefcmekjhcnkerjh'));
|
||||
|
||||
$client = new CurlClient();
|
||||
|
||||
$client->setForceSSL3(true);
|
||||
|
||||
$response = $client->retrieveResponse(
|
||||
$endPoint,
|
||||
'',
|
||||
array('Content-Type' => 'foo/bar'),
|
||||
'get'
|
||||
);
|
||||
|
||||
$response = json_decode($response, true);
|
||||
|
||||
$this->assertSame('foo/bar', $response['headers']['Content-Type']);
|
||||
}
|
||||
|
||||
public function testAdditionalParameters()
|
||||
{
|
||||
$endPoint = $this->getMock('\\OAuth\\Common\\Http\\Uri\\UriInterface');
|
||||
$endPoint->expects($this->any())
|
||||
->method('getHost')
|
||||
->will($this->returnValue('httpbin.org'));
|
||||
$endPoint->expects($this->any())
|
||||
->method('getAbsoluteUri')
|
||||
->will($this->returnValue('http://httpbin.org/gzip'));
|
||||
|
||||
$client = new CurlClient();
|
||||
$client->setCurlParameters(array(
|
||||
CURLOPT_ENCODING => 'gzip',
|
||||
));
|
||||
|
||||
$response = $client->retrieveResponse(
|
||||
$endPoint,
|
||||
'',
|
||||
array(),
|
||||
'get'
|
||||
);
|
||||
|
||||
$response = json_decode($response, true);
|
||||
|
||||
$this->assertNotNull($response);
|
||||
$this->assertSame('gzip', $response['headers']['Accept-Encoding']);
|
||||
$this->assertTrue($response['gzipped']);
|
||||
}
|
||||
}
|
||||
283
vendor/lusitanian/oauth/tests/Unit/Common/Http/Client/StreamClientTest.php
vendored
Normal file
283
vendor/lusitanian/oauth/tests/Unit/Common/Http/Client/StreamClientTest.php
vendored
Normal file
@@ -0,0 +1,283 @@
|
||||
<?php
|
||||
|
||||
namespace OAuthTest\Unit\Common\Http\Client;
|
||||
|
||||
use OAuth\Common\Http\Client\StreamClient;
|
||||
|
||||
class StreamClientTest extends \PHPUnit_Framework_TestCase
|
||||
{
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public function testConstructCorrectInstance()
|
||||
{
|
||||
$client = new StreamClient();
|
||||
|
||||
$this->assertInstanceOf('\\OAuth\\Common\\Http\\Client\\AbstractClient', $client);
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers OAuth\Common\Http\Client\StreamClient::retrieveResponse
|
||||
*/
|
||||
public function testRetrieveResponseThrowsExceptionOnGetRequestWithBody()
|
||||
{
|
||||
$this->setExpectedException('\\InvalidArgumentException');
|
||||
|
||||
$client = new StreamClient();
|
||||
|
||||
$client->retrieveResponse(
|
||||
$this->getMock('\\OAuth\\Common\\Http\\Uri\\UriInterface'),
|
||||
'foo',
|
||||
array(),
|
||||
'GET'
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers OAuth\Common\Http\Client\StreamClient::retrieveResponse
|
||||
*/
|
||||
public function testRetrieveResponseThrowsExceptionOnGetRequestWithBodyMethodConvertedToUpper()
|
||||
{
|
||||
$this->setExpectedException('\\InvalidArgumentException');
|
||||
|
||||
$client = new StreamClient();
|
||||
|
||||
$client->retrieveResponse(
|
||||
$this->getMock('\\OAuth\\Common\\Http\\Uri\\UriInterface'),
|
||||
'foo',
|
||||
array(),
|
||||
'get'
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers OAuth\Common\Http\Client\StreamClient::retrieveResponse
|
||||
* @covers OAuth\Common\Http\Client\StreamClient::generateStreamContext
|
||||
*/
|
||||
public function testRetrieveResponseDefaultUserAgent()
|
||||
{
|
||||
$endPoint = $this->getMock('\\OAuth\\Common\\Http\\Uri\\UriInterface');
|
||||
$endPoint->expects($this->any())
|
||||
->method('getHost')
|
||||
->will($this->returnValue('httpbin.org'));
|
||||
$endPoint->expects($this->any())
|
||||
->method('getAbsoluteUri')
|
||||
->will($this->returnValue('http://httpbin.org/get'));
|
||||
|
||||
$client = new StreamClient();
|
||||
|
||||
$response = $client->retrieveResponse(
|
||||
$endPoint,
|
||||
'',
|
||||
array(),
|
||||
'get'
|
||||
);
|
||||
|
||||
$response = json_decode($response, true);
|
||||
|
||||
$this->assertSame('PHPoAuthLib', $response['headers']['User-Agent']);
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers OAuth\Common\Http\Client\StreamClient::retrieveResponse
|
||||
* @covers OAuth\Common\Http\Client\StreamClient::generateStreamContext
|
||||
*/
|
||||
public function testRetrieveResponseCustomUserAgent()
|
||||
{
|
||||
$endPoint = $this->getMock('\\OAuth\\Common\\Http\\Uri\\UriInterface');
|
||||
$endPoint->expects($this->any())
|
||||
->method('getHost')
|
||||
->will($this->returnValue('httpbin.org'));
|
||||
$endPoint->expects($this->any())
|
||||
->method('getAbsoluteUri')
|
||||
->will($this->returnValue('http://httpbin.org/get'));
|
||||
|
||||
$client = new StreamClient('My Super Awesome Http Client');
|
||||
|
||||
$response = $client->retrieveResponse(
|
||||
$endPoint,
|
||||
'',
|
||||
array(),
|
||||
'get'
|
||||
);
|
||||
|
||||
$response = json_decode($response, true);
|
||||
|
||||
$this->assertSame('My Super Awesome Http Client', $response['headers']['User-Agent']);
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers OAuth\Common\Http\Client\StreamClient::retrieveResponse
|
||||
* @covers OAuth\Common\Http\Client\StreamClient::generateStreamContext
|
||||
*/
|
||||
public function testRetrieveResponseWithCustomContentType()
|
||||
{
|
||||
$endPoint = $this->getMock('\\OAuth\\Common\\Http\\Uri\\UriInterface');
|
||||
$endPoint->expects($this->any())
|
||||
->method('getHost')
|
||||
->will($this->returnValue('httpbin.org'));
|
||||
$endPoint->expects($this->any())
|
||||
->method('getAbsoluteUri')
|
||||
->will($this->returnValue('http://httpbin.org/get'));
|
||||
|
||||
$client = new StreamClient();
|
||||
|
||||
$response = $client->retrieveResponse(
|
||||
$endPoint,
|
||||
'',
|
||||
array('Content-Type' => 'foo/bar'),
|
||||
'get'
|
||||
);
|
||||
|
||||
$response = json_decode($response, true);
|
||||
|
||||
$this->assertSame('foo/bar', $response['headers']['Content-Type']);
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers OAuth\Common\Http\Client\StreamClient::retrieveResponse
|
||||
* @covers OAuth\Common\Http\Client\StreamClient::generateStreamContext
|
||||
*/
|
||||
public function testRetrieveResponseWithFormUrlEncodedContentType()
|
||||
{
|
||||
$endPoint = $this->getMock('\\OAuth\\Common\\Http\\Uri\\UriInterface');
|
||||
$endPoint->expects($this->any())
|
||||
->method('getHost')
|
||||
->will($this->returnValue('httpbin.org'));
|
||||
$endPoint->expects($this->any())
|
||||
->method('getAbsoluteUri')
|
||||
->will($this->returnValue('http://httpbin.org/post'));
|
||||
|
||||
$client = new StreamClient();
|
||||
|
||||
$response = $client->retrieveResponse(
|
||||
$endPoint,
|
||||
array('foo' => 'bar', 'baz' => 'fab'),
|
||||
array(),
|
||||
'POST'
|
||||
);
|
||||
|
||||
$response = json_decode($response, true);
|
||||
|
||||
$this->assertSame('application/x-www-form-urlencoded', $response['headers']['Content-Type']);
|
||||
$this->assertEquals(array('foo' => 'bar', 'baz' => 'fab'), $response['form']);
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers OAuth\Common\Http\Client\StreamClient::retrieveResponse
|
||||
* @covers OAuth\Common\Http\Client\StreamClient::generateStreamContext
|
||||
*/
|
||||
public function testRetrieveResponseHost()
|
||||
{
|
||||
$endPoint = $this->getMock('\\OAuth\\Common\\Http\\Uri\\UriInterface');
|
||||
$endPoint->expects($this->any())
|
||||
->method('getHost')
|
||||
->will($this->returnValue('httpbin.org'));
|
||||
$endPoint->expects($this->any())
|
||||
->method('getAbsoluteUri')
|
||||
->will($this->returnValue('http://httpbin.org/post'));
|
||||
|
||||
$client = new StreamClient();
|
||||
|
||||
$response = $client->retrieveResponse(
|
||||
$endPoint,
|
||||
array('foo' => 'bar', 'baz' => 'fab'),
|
||||
array(),
|
||||
'POST'
|
||||
);
|
||||
|
||||
$response = json_decode($response, true);
|
||||
|
||||
$this->assertSame('httpbin.org', $response['headers']['Host']);
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers OAuth\Common\Http\Client\StreamClient::retrieveResponse
|
||||
* @covers OAuth\Common\Http\Client\StreamClient::generateStreamContext
|
||||
*/
|
||||
public function testRetrieveResponsePostRequestWithRequestBodyAsString()
|
||||
{
|
||||
$endPoint = $this->getMock('\\OAuth\\Common\\Http\\Uri\\UriInterface');
|
||||
$endPoint->expects($this->any())
|
||||
->method('getHost')
|
||||
->will($this->returnValue('httpbin.org'));
|
||||
$endPoint->expects($this->any())
|
||||
->method('getAbsoluteUri')
|
||||
->will($this->returnValue('http://httpbin.org/post'));
|
||||
|
||||
$formData = array('baz' => 'fab', 'foo' => 'bar');
|
||||
|
||||
$client = new StreamClient();
|
||||
|
||||
$response = $client->retrieveResponse(
|
||||
$endPoint,
|
||||
$formData,
|
||||
array(),
|
||||
'POST'
|
||||
);
|
||||
|
||||
$response = json_decode($response, true);
|
||||
|
||||
$this->assertSame($formData, $response['form']);
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers OAuth\Common\Http\Client\StreamClient::retrieveResponse
|
||||
* @covers OAuth\Common\Http\Client\StreamClient::generateStreamContext
|
||||
*/
|
||||
public function testRetrieveResponsePutRequestWithRequestBodyAsString()
|
||||
{
|
||||
$endPoint = $this->getMock('\\OAuth\\Common\\Http\\Uri\\UriInterface');
|
||||
$endPoint->expects($this->any())
|
||||
->method('getHost')
|
||||
->will($this->returnValue('httpbin.org'));
|
||||
$endPoint->expects($this->any())
|
||||
->method('getAbsoluteUri')
|
||||
->will($this->returnValue('http://httpbin.org/put'));
|
||||
|
||||
$formData = array('baz' => 'fab', 'foo' => 'bar');
|
||||
|
||||
$client = new StreamClient();
|
||||
|
||||
$response = $client->retrieveResponse(
|
||||
$endPoint,
|
||||
$formData,
|
||||
array(),
|
||||
'PUT'
|
||||
);
|
||||
|
||||
$response = json_decode($response, true);
|
||||
|
||||
$this->assertSame($formData, $response['form']);
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers OAuth\Common\Http\Client\StreamClient::retrieveResponse
|
||||
* @covers OAuth\Common\Http\Client\StreamClient::generateStreamContext
|
||||
*/
|
||||
public function testRetrieveResponseThrowsExceptionOnInvalidRequest()
|
||||
{
|
||||
$this->setExpectedException('\\OAuth\\Common\\Http\\Exception\\TokenResponseException');
|
||||
|
||||
$endPoint = $this->getMock('\\OAuth\\Common\\Http\\Uri\\UriInterface');
|
||||
$endPoint->expects($this->any())
|
||||
->method('getHost')
|
||||
->will($this->returnValue('dskjhfckjhekrsfhkehfkreljfrekljfkre'));
|
||||
$endPoint->expects($this->any())
|
||||
->method('getAbsoluteUri')
|
||||
->will($this->returnValue('dskjhfckjhekrsfhkehfkreljfrekljfkre'));
|
||||
|
||||
$client = new StreamClient();
|
||||
|
||||
$response = $client->retrieveResponse(
|
||||
$endPoint,
|
||||
'',
|
||||
array('Content-Type' => 'foo/bar'),
|
||||
'get'
|
||||
);
|
||||
|
||||
$response = json_decode($response, true);
|
||||
|
||||
$this->assertSame('foo/bar', $response['headers']['Content-Type']);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user