Skip to content

bump to PHP 7.1 #62

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

Merged
merged 1 commit into from
Mar 11, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
vendor/
composer.lock
phpunit.xml
.php_cs.cache
24 changes: 24 additions & 0 deletions .php_cs.dist
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<?php

return PhpCsFixer\Config::create()
->setRules([
'@Symfony' => true,
'@Symfony:risky' => true,
'@PHPUnit48Migration:risky' => true,
'php_unit_no_expectation_annotation' => false, // part of `PHPUnitXYMigration:risky` ruleset, to be enabled when PHPUnit 4.x support will be dropped, as we don't want to rewrite exceptions handling twice
'array_syntax' => ['syntax' => 'short'],
'fopen_flags' => false,
'ordered_imports' => true,
'protected_to_private' => false,
// Part of @Symfony:risky in PHP-CS-Fixer 2.13.0. To be removed from the config file once upgrading
'native_function_invocation' => ['include' => ['@compiler_optimized'], 'scope' => 'namespaced'],
// Part of future @Symfony ruleset in PHP-CS-Fixer To be removed from the config file once upgrading
'phpdoc_types_order' => ['null_adjustment' => 'always_last', 'sort_algorithm' => 'none'],
])
->setRiskyAllowed(true)
->setFinder(
PhpCsFixer\Finder::create()
->in(__DIR__)
->name('*.php')
)
;
24 changes: 1 addition & 23 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,40 +9,18 @@ env:
global:
- PHPUNIT_FLAGS="-v"
- SYMFONY_PHPUNIT_DIR="$HOME/symfony-bridge/.phpunit"
- DEPENDENCIES="zendframework/zend-diactoros:^1.4.1 http-interop/http-factory-diactoros:^1.0"

matrix:
fast_finish: true
include:
# Minimum supported dependencies with the latest and oldest PHP version
- php: 7.2
env: COMPOSER_FLAGS="--prefer-stable --prefer-lowest" SYMFONY_DEPRECATIONS_HELPER="weak_vendors"
- php: 5.3
dist: 'precise'
env: COMPOSER_FLAGS="--prefer-stable --prefer-lowest" SYMFONY_DEPRECATIONS_HELPER="weak_vendors" DEPENDENCIES=""

# Test the latest stable release
- php: 5.3
dist: 'precise'
env: DEPENDENCIES=""
- php: 5.4
env: DEPENDENCIES="zendframework/zend-diactoros:^1.4.1"
- php: 5.5
env: DEPENDENCIES="zendframework/zend-diactoros:^1.4.1"
- php: 5.6
env: DEPENDENCIES="zendframework/zend-diactoros:^1.4.1"
- php: 7.0
- php: 7.1
- php: 7.2
env: COVERAGE=true PHPUNIT_FLAGS="-v --coverage-text"

# Test LTS versions. This makes sure we do not use Symfony packages with version greater
# than 2 or 3 respectively.
- php: 7.2
env: DEPENDENCIES="$DEPENDENCIES symfony/lts:^2 symfony/force-lowest:~2.8.0"
- php: 7.2
env: DEPENDENCIES="$DEPENDENCIES symfony/lts:^3 symfony/force-lowest:~3.4.0"

# Latest commit to master
- php: 7.2
env: STABILITY="dev"
Expand All @@ -66,4 +44,4 @@ script:
- composer validate --strict --no-check-lock
# simple-phpunit is the PHPUnit wrapper provided by the PHPUnit Bridge component and
# it helps with testing legacy code and deprecations (composer require symfony/phpunit-bridge)
- ./vendor/bin/simple-phpunit $PHPUNIT_FLAGS
- ./vendor/bin/simple-phpunit $PHPUNIT_FLAGS
11 changes: 3 additions & 8 deletions Factory/DiactorosFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,12 +52,7 @@ public function createRequest(Request $symfonyRequest)
: \Zend\Diactoros\normalizeServer($symfonyRequest->server->all());
$headers = $symfonyRequest->headers->all();

if (PHP_VERSION_ID < 50600) {
$body = new DiactorosStream('php://temp', 'wb+');
$body->write($symfonyRequest->getContent());
} else {
$body = new DiactorosStream($symfonyRequest->getContent(true));
}
$body = new DiactorosStream($symfonyRequest->getContent(true));

$files = method_exists('Zend\Diactoros\ServerRequestFactory', 'normalizeFiles')
? DiactorosRequestFactory::normalizeFiles($this->getFiles($symfonyRequest->files->all()))
Expand Down Expand Up @@ -95,7 +90,7 @@ public function createRequest(Request $symfonyRequest)
*/
private function getFiles(array $uploadedFiles)
{
$files = array();
$files = [];

foreach ($uploadedFiles as $key => $value) {
if (null === $value) {
Expand Down Expand Up @@ -157,7 +152,7 @@ public function createResponse(Response $symfonyResponse)
if (!isset($headers['Set-Cookie']) && !isset($headers['set-cookie'])) {
$cookies = $symfonyResponse->headers->getCookies();
if (!empty($cookies)) {
$headers['Set-Cookie'] = array();
$headers['Set-Cookie'] = [];
foreach ($cookies as $cookie) {
$headers['Set-Cookie'][] = $cookie->__toString();
}
Expand Down
10 changes: 5 additions & 5 deletions Factory/HttpFoundationFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@

namespace Symfony\Bridge\PsrHttpMessage\Factory;

use Psr\Http\Message\ServerRequestInterface;
use Psr\Http\Message\ResponseInterface;
use Psr\Http\Message\ServerRequestInterface;
use Psr\Http\Message\UploadedFileInterface;
use Psr\Http\Message\UriInterface;
use Symfony\Bridge\PsrHttpMessage\HttpFoundationFactoryInterface;
Expand All @@ -33,7 +33,7 @@ class HttpFoundationFactory implements HttpFoundationFactoryInterface
*/
public function createRequest(ServerRequestInterface $psrRequest)
{
$server = array();
$server = [];
$uri = $psrRequest->getUri();

if ($uri instanceof UriInterface) {
Expand All @@ -48,7 +48,7 @@ public function createRequest(ServerRequestInterface $psrRequest)
$server = array_replace($server, $psrRequest->getServerParams());

$parsedBody = $psrRequest->getParsedBody();
$parsedBody = is_array($parsedBody) ? $parsedBody : array();
$parsedBody = \is_array($parsedBody) ? $parsedBody : [];

$request = new Request(
$psrRequest->getQueryParams(),
Expand All @@ -73,7 +73,7 @@ public function createRequest(ServerRequestInterface $psrRequest)
*/
private function getFiles(array $uploadedFiles)
{
$files = array();
$files = [];

foreach ($uploadedFiles as $key => $value) {
if ($value instanceof UploadedFileInterface) {
Expand Down Expand Up @@ -141,7 +141,7 @@ protected function getTemporaryPath()
public function createResponse(ResponseInterface $psrResponse)
{
$cookies = $psrResponse->getHeader('Set-Cookie');
$psrResponse = $psrResponse->withHeader('Set-Cookie', array());
$psrResponse = $psrResponse->withHeader('Set-Cookie', []);

$response = new Response(
$psrResponse->getBody()->__toString(),
Expand Down
11 changes: 3 additions & 8 deletions Factory/PsrHttpFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -58,12 +58,7 @@ public function createRequest(Request $symfonyRequest)
$request = $request->withHeader($name, $value);
}

if (PHP_VERSION_ID < 50600) {
$body = $this->streamFactory->createStreamFromFile('php://temp', 'wb+');
$body->write($symfonyRequest->getContent());
} else {
$body = $this->streamFactory->createStreamFromResource($symfonyRequest->getContent(true));
}
$body = $this->streamFactory->createStreamFromResource($symfonyRequest->getContent(true));

$request = $request
->withBody($body)
Expand All @@ -89,7 +84,7 @@ public function createRequest(Request $symfonyRequest)
*/
private function getFiles(array $uploadedFiles)
{
$files = array();
$files = [];

foreach ($uploadedFiles as $key => $value) {
if (null === $value) {
Expand Down Expand Up @@ -158,7 +153,7 @@ public function createResponse(Response $symfonyResponse)
$headers = $symfonyResponse->headers->all();
$cookies = $symfonyResponse->headers->getCookies();
if (!empty($cookies)) {
$headers['Set-Cookie'] = array();
$headers['Set-Cookie'] = [];

foreach ($cookies as $cookie) {
$headers['Set-Cookie'][] = $cookie->__toString();
Expand Down
2 changes: 1 addition & 1 deletion HttpFoundationFactoryInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@

namespace Symfony\Bridge\PsrHttpMessage;

use Psr\Http\Message\ServerRequestInterface;
use Psr\Http\Message\ResponseInterface;
use Psr\Http\Message\ServerRequestInterface;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;

Expand Down
2 changes: 1 addition & 1 deletion HttpMessageFactoryInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@

namespace Symfony\Bridge\PsrHttpMessage;

use Psr\Http\Message\ServerRequestInterface;
use Psr\Http\Message\ResponseInterface;
use Psr\Http\Message\ServerRequestInterface;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;

Expand Down
67 changes: 36 additions & 31 deletions Tests/Factory/AbstractHttpMessageFactoryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,36 +44,36 @@ public function testCreateRequest()
{
$stdClass = new \stdClass();
$request = new Request(
array(
[
'foo' => '1',
'bar' => array('baz' => '42'),
),
array(
'twitter' => array(
'bar' => ['baz' => '42'],
],
[
'twitter' => [
'@dunglas' => 'Kévin Dunglas',
'@coopTilleuls' => 'Les-Tilleuls.coop',
),
],
'baz' => '2',
),
array(
],
[
'a1' => $stdClass,
'a2' => array('foo' => 'bar'),
),
array(
'a2' => ['foo' => 'bar'],
],
[
'c1' => 'foo',
'c2' => array('c3' => 'bar'),
),
array(
'c2' => ['c3' => 'bar'],
],
[
'f1' => $this->createUploadedFile('F1', 'f1.txt', 'text/plain', UPLOAD_ERR_OK),
'foo' => array('f2' => $this->createUploadedFile('F2', 'f2.txt', 'text/plain', UPLOAD_ERR_OK)),
),
array(
'foo' => ['f2' => $this->createUploadedFile('F2', 'f2.txt', 'text/plain', UPLOAD_ERR_OK)],
],
[
'REQUEST_METHOD' => 'POST',
'HTTP_HOST' => 'dunglas.fr',
'HTTP_X_SYMFONY' => '2.8',
'REQUEST_URI' => '/testCreateRequest?foo=1&bar[baz]=42',
'QUERY_STRING' => 'foo=1&bar[baz]=42',
),
],
'Content'
);

Expand Down Expand Up @@ -116,13 +116,13 @@ public function testCreateRequest()
$this->assertEquals('POST', $serverParams['REQUEST_METHOD']);
$this->assertEquals('2.8', $serverParams['HTTP_X_SYMFONY']);
$this->assertEquals('POST', $psrRequest->getMethod());
$this->assertEquals(array('2.8'), $psrRequest->getHeader('X-Symfony'));
$this->assertEquals(['2.8'], $psrRequest->getHeader('X-Symfony'));
}

public function testGetContentCanBeCalledAfterRequestCreation()
{
$header = array('HTTP_HOST' => 'dunglas.fr');
$request = new Request(array(), array(), array(), array(), array(), $header, 'Content');
$header = ['HTTP_HOST' => 'dunglas.fr'];
$request = new Request([], [], [], [], [], $header, 'Content');

$psrRequest = $this->factory->createRequest($request);

Expand All @@ -139,6 +139,7 @@ private function createUploadedFile($content, $originalName, $mimeType, $error)
// Symfony 4.1+
return new UploadedFile($path, $originalName, $mimeType, $error, true);
}

return new UploadedFile($path, $originalName, $mimeType, filesize($path), $error, true);
}

Expand All @@ -147,14 +148,14 @@ public function testCreateResponse()
$response = new Response(
'Response content.',
202,
array('X-Symfony' => array('3.4'))
['X-Symfony' => ['3.4']]
);
$response->headers->setCookie(new Cookie('city', 'Lille', new \DateTime('Wed, 13 Jan 2021 22:23:01 GMT'), '/', null, false, true, false, ''));
$response->headers->setCookie(new Cookie('city', 'Lille', new \DateTime('Wed, 13 Jan 2021 22:23:01 GMT'), '/', null, false, true, false, null));

$psrResponse = $this->factory->createResponse($response);
$this->assertEquals('Response content.', $psrResponse->getBody()->__toString());
$this->assertEquals(202, $psrResponse->getStatusCode());
$this->assertEquals(array('3.4'), $psrResponse->getHeader('X-Symfony'));
$this->assertEquals(['3.4'], $psrResponse->getHeader('X-Symfony'));

$cookieHeader = $psrResponse->getHeader('Set-Cookie');
$this->assertInternalType('array', $cookieHeader);
Expand Down Expand Up @@ -201,17 +202,21 @@ public function testUploadErrNoFile()
$this->assertEquals(UPLOAD_ERR_NO_FILE, $file->getError());
$this->assertFalse($file->getSize(), 'SplFile::getSize() returns false on error');

$request = new Request(array(), array(), array(), array(),
array(
$request = new Request(
[],
[],
[],
[],
[
'f1' => $file,
'f2' => array('name' => null, 'type' => null, 'tmp_name' => null, 'error' => UPLOAD_ERR_NO_FILE, 'size' => 0),
),
array(
'f2' => ['name' => null, 'type' => null, 'tmp_name' => null, 'error' => UPLOAD_ERR_NO_FILE, 'size' => 0],
],
[
'REQUEST_METHOD' => 'POST',
'HTTP_HOST' => 'dunglas.fr',
'HTTP_X_SYMFONY' => '2.8',
),
'Content'
],
'Content'
);

$psrRequest = $this->factory->createRequest($request);
Expand Down
Loading