Skip to content

Initial support #1

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 37 commits into from
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
37 commits
Select commit Hold shift + click to select a range
999be72
Add composer dependencies
dunglas May 21, 2015
47c6564
More dependencies
dunglas May 21, 2015
6a4ab9b
Add interfaces and stubs.
dunglas May 21, 2015
1ed3bff
Add .gitignore
dunglas May 21, 2015
1b81ee0
Make factory methods static. Add test infra.
dunglas May 21, 2015
1e3307c
Setup Travis
dunglas May 21, 2015
7e7fbf6
Add missing static keywords
dunglas May 21, 2015
43d4c48
Use ServerRequestInterface
dunglas May 21, 2015
bb43a07
Basic HttpFoundationFactory::createRequest implementation
dunglas May 21, 2015
656318b
Remove a short array usage
dunglas May 21, 2015
40c2973
Make immutable
dunglas May 22, 2015
a246407
Enforce immutability
dunglas May 22, 2015
77360d6
Uploaded file support
dunglas May 22, 2015
6f5815b
Fix some @stof comments
dunglas May 22, 2015
5240539
Add license headers
dunglas May 22, 2015
8b4a078
More unit tests for uploaded files.
dunglas May 23, 2015
14dac4e
HttpFoundation Response factory and tests
dunglas May 23, 2015
8c3c90e
Fix CS
dunglas May 23, 2015
65261ee
Diactoros factory draft implementation
dunglas May 23, 2015
7e44bc2
New version of DiactorosFactory::createRequest(). Tests.
dunglas May 24, 2015
1e480a9
Rename HttpMessageFactoryInterface
dunglas May 24, 2015
9127c84
Update LICENSE copyright year
dunglas May 24, 2015
b360068
Better stream handling in DiactorosFactory::createRequest
dunglas May 24, 2015
4d11665
New DiactorosFactory::createResponse implementation. Tests.
dunglas May 24, 2015
e129154
StreamedResponse support
dunglas May 24, 2015
91a13dc
Fix BadMethodCallException
dunglas May 25, 2015
ef384ae
Throw an exception if Zend Diactoros isn't installed.
dunglas May 25, 2015
bcfa698
Fix Travis
dunglas May 26, 2015
8a2bd7b
Remove dev dependency to Zend Diactoros
dunglas May 27, 2015
f41f3e4
New DiactorosFactory implementation
dunglas May 27, 2015
9c6f180
Added cookies support
dunglas May 27, 2015
7d8bdc8
PHPUnit optimizations
dunglas May 27, 2015
eacce8f
Remove crap.
dunglas May 27, 2015
7012db5
Enhanced headers support
dunglas May 27, 2015
b887c36
CS fixes
dunglas May 27, 2015
ca2ea3b
BinaryFileResponse support
dunglas May 27, 2015
577e633
Support Symfony 3.0
dunglas May 28, 2015
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
Prev Previous commit
Next Next commit
Enforce immutability
  • Loading branch information
dunglas committed May 22, 2015
commit a246407983db77d55c07bbdb75908ff86895d70c
60 changes: 47 additions & 13 deletions Tests/Factory/HttpFoundationFactoryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,21 @@ public function setup()

public function testCreateRequest()
{
$serverRequest = new ServerRequest(array('country' => 'France'));
$serverRequest->withQueryParams(array('url' => 'http://les-tilleuls.coop'));
$serverRequest->withParsedBody(array('url' => 'http://dunglas.fr'));

$stdClass = new \stdClass();
$serverRequest->withAttribute('custom', $stdClass);

$serverRequest->withCookieParams(array('city' => 'Lille'));
$serverRequest->withBody(new Stream('The body'));
$serverRequest = new ServerRequest(
'1.1',
array(),
new Stream('The body'),
'/about/kevin',
'GET',
'http://les-tilleuls.coop/about/kevin',
array('country' => 'France'),
array('city' => 'Lille'),
array('url' => 'http://les-tilleuls.coop'),
array(),
array('url' => 'http://dunglas.fr'),
array('custom' => $stdClass)
);

$symfonyRequest = $this->factory->createRequest($serverRequest);

Expand All @@ -39,14 +45,43 @@ public function testCreateRequest()
$this->assertEquals('The body', $symfonyRequest->getContent());
}

public function testCreateRequestWithNonArrayParsedBody()
public function testCreateRequestWithNullParsedBody()
{
$serverRequest = new ServerRequest();
$serverRequest = new ServerRequest(
'1.1',
array(),
new Stream(),
'/',
'GET',
null,
array(),
array(),
array(),
array(),
null,
array()
);

$serverRequest->withParsedBody(null);
$this->assertCount(0, $this->factory->createRequest($serverRequest)->request);
}

public function testCreateRequestWithObjectParsedBody()
{
$serverRequest = new ServerRequest(
'1.1',
array(),
new Stream(),
'/',
'GET',
null,
array(),
array(),
array(),
array(),
new \stdClass(),
array()
);

$serverRequest->withParsedBody(new \stdClass());
$this->assertCount(0, $this->factory->createRequest($serverRequest)->request);
}

Expand All @@ -55,4 +90,3 @@ public function testCreateResponse()

}
}

22 changes: 9 additions & 13 deletions Tests/Fixtures/Message.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,11 @@ class Message implements MessageInterface
private $headers = array();
private $body;

public function __construct()
public function __construct($version = '1.1', array $headers = array(), StreamInterface $body = null)
{
$this->body = new Stream();
$this->version = $version;
$this->headers = $headers;
$this->body = null === $body ? new Stream() : $body;
}

public function getProtocolVersion()
Expand All @@ -28,7 +30,7 @@ public function getProtocolVersion()

public function withProtocolVersion($version)
{
$this->version = $version;
throw \BadMethodCallException('Not implemented.');
}

public function getHeaders()
Expand All @@ -53,23 +55,17 @@ public function getHeaderLine($name)

public function withHeader($name, $value)
{
if (!is_array($value)) {
$value = array($value);
}

$this->headers[$name] = $value;
throw \BadMethodCallException('Not implemented.');
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

throw new \BadMethodCallException('Not implemented.');

}

public function withAddedHeader($name, $value)
{
$this->headers[$name][] = $value;
throw \BadMethodCallException('Not implemented.');
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

throw new \BadMethodCallException('Not implemented.');

}

public function withoutHeader($name)
{
if ($this->hasHeader($name)) {
unset($this->headers[$name]);
}
throw \BadMethodCallException('Not implemented.');
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

throw new \BadMethodCallException('Not implemented.');

}

public function getBody()
Expand All @@ -79,6 +75,6 @@ public function getBody()

public function withBody(StreamInterface $body)
{
$this->body = $body;
throw \BadMethodCallException('Not implemented.');
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

throw new \BadMethodCallException('Not implemented.');

}
}
48 changes: 27 additions & 21 deletions Tests/Fixtures/ServerRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,28 +3,37 @@
namespace Symfony\Bridge\PsrHttpMessage\Tests\Fixtures;

use Psr\Http\Message\ServerRequestInterface;
use Psr\Http\Message\StreamInterface;
use Psr\Http\Message\UriInterface;

/**
* @author Kévin Dunglas <dunglas@gmail.com>
*/
class ServerRequest extends Message implements ServerRequestInterface
{
private $requestTarget = '/';
private $method = 'GET';
private $requestTarget ;
private $method;
private $uri;
private $server = array();
private $cookies = array();
private $query = array();
private $uploadedFiles = array();
private $data = null;
private $attributes = array();
private $server;
private $cookies;
private $query;
private $uploadedFiles;
private $data;
private $attributes;

public function __construct($server = array())
public function __construct($version = '1.1', array $headers = array(), StreamInterface $body = null, $requestTarget = '/', $method = 'GET', $uri = null, array $server = array(), array $cookies = array(), array $query = array(), array $uploadedFiles = array(), $data = null, array $attributes = array())
{
parent::__construct();
parent::__construct($version, $headers, $body);

$this->requestTarget = $requestTarget;
$this->method = $method;
$this->uri = $uri;
$this->server = $server;
$this->cookies = $cookies;
$this->query = $query;
$this->uploadedFiles = $uploadedFiles;
$this->data = $data;
$this->attributes = $attributes;
}

public function getRequestTarget()
Expand All @@ -34,7 +43,7 @@ public function getRequestTarget()

public function withRequestTarget($requestTarget)
{
$this->requestTarget = $requestTarget;
throw \BadMethodCallException('Not implemented.');
}

public function getMethod()
Expand All @@ -44,7 +53,6 @@ public function getMethod()

public function withMethod($method)
{
$this->method = $method;
}

public function getUri()
Expand All @@ -54,7 +62,7 @@ public function getUri()

public function withUri(UriInterface $uri, $preserveHost = false)
{
$this->uri = $uri;
throw \BadMethodCallException('Not implemented.');
}

public function getServerParams()
Expand All @@ -69,7 +77,7 @@ public function getCookieParams()

public function withCookieParams(array $cookies)
{
$this->cookies = $cookies;
throw \BadMethodCallException('Not implemented.');
}

public function getQueryParams()
Expand All @@ -79,7 +87,7 @@ public function getQueryParams()

public function withQueryParams(array $query)
{
$this->query = $query;
throw \BadMethodCallException('Not implemented.');
}

public function getUploadedFiles()
Expand All @@ -89,7 +97,7 @@ public function getUploadedFiles()

public function withUploadedFiles(array $uploadedFiles)
{
$this->uploadedFiles = $uploadedFiles;
throw \BadMethodCallException('Not implemented.');
}

public function getParsedBody()
Expand All @@ -99,7 +107,7 @@ public function getParsedBody()

public function withParsedBody($data)
{
$this->data = $data;
throw \BadMethodCallException('Not implemented.');
}

public function getAttributes()
Expand All @@ -114,13 +122,11 @@ public function getAttribute($name, $default = null)

public function withAttribute($name, $value)
{
$this->attributes[$name] = $value;
throw \BadMethodCallException('Not implemented.');
}

public function withoutAttribute($name)
{
if ($this->getAttribute($name)) {
unset($this->attributes[$name]);
}
throw \BadMethodCallException('Not implemented.');
}
}