Commit 0dbe9ffc authored by TheBigB's avatar TheBigB
Browse files

More fixes for PHP 5.5

parent d6682eb7
......@@ -25,7 +25,7 @@ class CurlyOptions
{
#region // Mapping between property names and cURL constants
private static $__optionMap = [
protected static $__optionMap = [
'followRedirects' => CURLOPT_FOLLOWLOCATION,
'maxRedirects' => CURLOPT_MAXREDIRS,
'followPostRedirects' => CURLOPT_POSTREDIR,
......
......@@ -2,6 +2,8 @@
namespace OneOfZero\Curly;
use Psr\Http\Message\StreamInterface;
use Psr\Http\Message\UriInterface;
use Zend\Diactoros\ServerRequest;
use Zend\Diactoros\Uri;
......@@ -10,14 +12,14 @@ class ExtendedServerRequest extends ServerRequest
/**
* Returns a copy of this request with the provided URI pieces as URI.
*
* @param string[] ...$pieces
* @param string $pieces,...
*
* @return static
*/
public function withUriString(...$pieces)
public function withUriString($pieces)
{
// TODO: Fix this properly - https://tools.ietf.org/html/rfc3986#section-5.2
$pieces = array_map(function($item) { return trim($item, '/'); }, $pieces);
$pieces = array_map(function($item) { return trim($item, '/'); }, func_get_args());
return $this->withUri(new Uri(implode('/', $pieces)));
}
......@@ -110,4 +112,134 @@ class ExtendedServerRequest extends ServerRequest
->withStringBody($buffer)
;
}
#region // What follows is irrelevant proxying to fix the return-type hints
/**
* {@inheritdoc}
* @return static
*/
public function withProtocolVersion($version)
{
return parent::withProtocolVersion($version);
}
/**
* {@inheritdoc}
* @return static
*/
public function withHeader($header, $value)
{
return parent::withHeader($header, $value);
}
/**
* {@inheritdoc}
* @return static
*/
public function withAddedHeader($header, $value)
{
return parent::withAddedHeader($header, $value);
}
/**
* {@inheritdoc}
* @return static
*/
public function withoutHeader($header)
{
return parent::withoutHeader($header);
}
/**
* {@inheritdoc}
* @return static
*/
public function withBody(StreamInterface $body)
{
return parent::withBody($body);
}
/**
* {@inheritdoc}
* @return static
*/
public function withRequestTarget($requestTarget)
{
return parent::withRequestTarget($requestTarget);
}
/**
* {@inheritdoc}
* @return static
*/
public function withUri(UriInterface $uri, $preserveHost = false)
{
return parent::withUri($uri, $preserveHost);
}
/**
* {@inheritdoc}
* @return static
*/
public function withUploadedFiles(array $uploadedFiles)
{
return parent::withUploadedFiles($uploadedFiles);
}
/**
* {@inheritdoc}
* @return static
*/
public function withCookieParams(array $cookies)
{
return parent::withCookieParams($cookies);
}
/**
* {@inheritdoc}
* @return static
*/
public function withQueryParams(array $query)
{
return parent::withQueryParams($query);
}
/**
* {@inheritdoc}
* @return static
*/
public function withParsedBody($data)
{
return parent::withParsedBody($data);
}
/**
* {@inheritdoc}
* @return static
*/
public function withAttribute($attribute, $value)
{
return parent::withAttribute($attribute, $value);
}
/**
* {@inheritdoc}
* @return static
*/
public function withoutAttribute($attribute)
{
return parent::withoutAttribute($attribute);
}
/**
* {@inheritdoc}
* @return static
*/
public function withMethod($method)
{
return parent::withMethod($method);
}
#endregion
}
\ No newline at end of file
......@@ -19,7 +19,7 @@ abstract class AbstractHandler
const ON_READ = 'onRead';
const ON_WRITE = 'onWrite';
private static $validEvents = [ self::ON_HEADER, self::ON_PROGRESS, self::ON_READ, self::ON_WRITE ];
protected static $validEvents = [ self::ON_HEADER, self::ON_PROGRESS, self::ON_READ, self::ON_WRITE ];
/**
* Should return an array with the function names of the events that are implemented. The only supported events are:
......
......@@ -17,22 +17,57 @@ use Zend\Diactoros\Uri;
abstract class AbstractTestCase extends PHPUnit_Framework_TestCase
{
/**
* @param string[] $parts
* @var string $scheme
*/
protected $scheme = 'http';
/**
* @var string $host
*/
protected $host = '127.0.0.1';
/**
* @var int $port
*/
protected $port;
/**
*
*/
public function setUp()
{
$this->port = Bootstrapper::get()->getPort();
}
/**
* @return string
*/
protected function getBaseUri()
{
return sprintf('%s://%s:%s/', $this->scheme, $this->host, $this->port);
}
/**
* @param string[] $pieces
*
* @return Uri
*/
protected function buildUri($parts)
protected function buildUri($pieces)
{
$uri = new Uri('http://127.0.0.1/' . implode('/', $parts));
return $uri->withPort(Bootstrapper::get()->getPort());
return new Uri($this->getBaseUri() . implode('/', $pieces));
}
/**
* @param string $method
* @param string[] ...$url
* @param string $url,...
*
* @return ExtendedServerRequest
*/
protected function buildRequest($method, ...$url)
protected function buildRequest($method, $url)
{
$url = func_get_args();
array_shift($url);
return (new ExtendedServerRequest)
->withMethod($method)
->withUri($this->buildUri($url))
......
......@@ -24,7 +24,7 @@ class LoggingHandler extends AbstractHandler
*/
public function getImplemented()
{
return self::VALID_EVENTS;
return self::$validEvents;
}
/**
......
......@@ -10,6 +10,7 @@
namespace OneOfZero\Curly\Tests;
use OneOfZero\Curly\Curly;
use OneOfZero\Curly\ExtendedServerRequest;
use OneOfZero\Curly\RequestHelpers\JsonForm;
use OneOfZero\Curly\RequestHelpers\UrlEncodedForm;
use Zend\Diactoros\Request;
......@@ -80,4 +81,18 @@ class GenericTest extends AbstractTestCase
$this->assertEquals(404, $response->getStatusCode());
$this->assertEmpty(strval($response->getBody()));
}
public function testUriBuilder()
{
$curly = new Curly();
$request = (new ExtendedServerRequest)
->withMethod('GET')
->withUriString($this->getBaseUri(), 'get')
;
$response = $curly->request($request);
$this->assertEquals(200, $response->getStatusCode());
$this->assertJson(strval($response->getBody()));
}
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment