Skip to content

Fixed broken build #45

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
Aug 8, 2018
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
71 changes: 44 additions & 27 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,49 +1,66 @@
language: php

sudo: false

cache:
directories:
- $HOME/.composer/cache/files
- $HOME/symfony-bridge/.phpunit

env:
global:
- PHPUNIT_FLAGS="-v"
- SYMFONY_PHPUNIT_DIR="$HOME/symfony-bridge/.phpunit"
- DEPENDENCIES="zendframework/zend-diactoros:^1.4.1"

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'
- php: 5.4
- php: 5.5
- php: 5.6
env: COMPOSER_FLAGS="--prefer-stable --prefer-lowest" SYMFONY_DEPRECATIONS_HELPER="weak_vendors" DEPENDENCIES=""

# Test the latest stable release
- php: 5.3
dist: 'precise'
env: COMPOSER_OPTIONS="--prefer-lowest --prefer-stable" SYMFONY_DEPRECATIONS_HELPER=weak
env: DEPENDENCIES=""
- php: 5.4
- php: 5.5
- php: 5.6
env: COMPOSER_OPTIONS="" SYMFONY_DEPRECATIONS_HELPER=weak
- php: 7.0
- php: hhvm
allow_failures:
- php: hhvm
fast_finish: true
- php: 7.1
- php: 7.2
env: COVERAGE=true PHPUNIT_FLAGS="-v --coverage-text"

env:
global:
- deps=no
- SYMFONY_DEPRECATIONS_HELPER=strict
- SYMFONY_PHPUNIT_DIR="$HOME/symfony-bridge/.phpunit"
- COMPOSER_OPTIONS="--prefer-stable"
# 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="symfony/lts:^2 symfony/force-lowest:~2.8.0 zendframework/zend-diactoros:^1.4.1"
- php: 7.2
env: DEPENDENCIES="symfony/lts:^3 symfony/force-lowest:~3.4.0 zendframework/zend-diactoros:^1.4.1"

# Latest commit to master
- php: 7.2
env: STABILITY="dev"

allow_failures:
# Dev-master is allowed to fail.
- env: STABILITY="dev"

before_install:
- if [[ "$TRAVIS_PHP_VERSION" != "nightly" ]] && [[ "$TRAVIS_PHP_VERSION" != "hhvm" ]]; then phpenv config-rm xdebug.ini; fi;
- composer self-update
- if [[ "$TRAVIS_PHP_VERSION" != "nightly" ]] && [[ "$TRAVIS_PHP_VERSION" != "hhvm" ]] && [ $(php -r "echo PHP_MINOR_VERSION;") -le 4 ]; then echo "extension = apc.so" >> ~/.phpenv/versions/$(phpenv version-name)/etc/php.ini; fi;
- if [[ "$TRAVIS_PHP_VERSION" != "nightly" ]] && [[ "$TRAVIS_PHP_VERSION" != "hhvm" ]]; then php -i; fi;
# Set the COMPOSER_ROOT_VERSION to the right version according to the branch being built
- if [ "$TRAVIS_BRANCH" = "master" ]; then export COMPOSER_ROOT_VERSION=dev-master; else export COMPOSER_ROOT_VERSION="$TRAVIS_BRANCH".x-dev; fi;
- if [[ $COVERAGE != true ]]; then phpenv config-rm xdebug.ini || true; fi
- if ! [ -z "$STABILITY" ]; then composer config minimum-stability ${STABILITY}; fi;
- if ! [ -v "$DEPENDENCIES" ]; then composer require --no-update ${DEPENDENCIES}; fi;

install:
- if [ "$TRAVIS_PHP_VERSION" != "5.3" ]; then composer require --no-update zendframework/zend-diactoros; fi;
- composer update --prefer-source $COMPOSER_OPTIONS
- vendor/bin/simple-phpunit install
# To be removed when this issue will be resolved: https://github.com/composer/composer/issues/5355
- if [[ "$COMPOSER_FLAGS" == *"--prefer-lowest"* ]]; then composer update --prefer-dist --no-interaction --prefer-stable --quiet; fi
- composer update ${COMPOSER_FLAGS} --prefer-dist --no-interaction
- ./vendor/bin/simple-phpunit install

script:
- vendor/bin/simple-phpunit
- 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
17 changes: 9 additions & 8 deletions Factory/DiactorosFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

namespace Symfony\Bridge\PsrHttpMessage\Factory;

use Psr\Http\Message\UploadedFileInterface;
use Symfony\Bridge\PsrHttpMessage\HttpMessageFactoryInterface;
use Symfony\Component\HttpFoundation\BinaryFileResponse;
use Symfony\Component\HttpFoundation\File\UploadedFile;
Expand Down Expand Up @@ -112,7 +113,7 @@ private function createUploadedFile(UploadedFile $symfonyUploadedFile)
{
return new DiactorosUploadedFile(
$symfonyUploadedFile->getRealPath(),
$symfonyUploadedFile->getClientSize(),
(int) $symfonyUploadedFile->getSize(),
$symfonyUploadedFile->getError(),
$symfonyUploadedFile->getClientOriginalName(),
$symfonyUploadedFile->getClientMimeType()
Expand Down Expand Up @@ -143,13 +144,13 @@ public function createResponse(Response $symfonyResponse)
}

$headers = $symfonyResponse->headers->all();

$cookies = $symfonyResponse->headers->getCookies();
if (!empty($cookies)) {
$headers['Set-Cookie'] = array();

foreach ($cookies as $cookie) {
$headers['Set-Cookie'][] = $cookie->__toString();
if (!isset($headers['Set-Cookie']) && !isset($headers['set-sookie'])) {
$cookies = $symfonyResponse->headers->getCookies();
if (!empty($cookies)) {
$headers['Set-Cookie'] = array();
foreach ($cookies as $cookie) {
$headers['Set-Cookie'][] = $cookie->__toString();
}
}
}

Expand Down
11 changes: 11 additions & 0 deletions Factory/HttpFoundationFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,17 @@ private function createUploadedFile(UploadedFileInterface $psrUploadedFile)
$clientFileName = $psrUploadedFile->getClientFilename();
}

if (class_exists('Symfony\Component\HttpFoundation\HeaderUtils')) {
// Symfony 4.1+
return new UploadedFile(
$temporaryPath,
null === $clientFileName ? '' : $clientFileName,
$psrUploadedFile->getClientMediaType(),
$psrUploadedFile->getError(),
true
);
}

return new UploadedFile(
$temporaryPath,
null === $clientFileName ? '' : $clientFileName,
Expand Down
18 changes: 13 additions & 5 deletions Tests/Factory/DiactorosFactoryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,10 @@ private function createUploadedFile($content, $originalName, $mimeType, $error)
$path = tempnam($this->tmpDir, uniqid());
file_put_contents($path, $content);

if (class_exists('Symfony\Component\HttpFoundation\HeaderUtils')) {
// Symfony 4.1+
return new UploadedFile($path, $originalName, $mimeType, $error, true);
}
return new UploadedFile($path, $originalName, $mimeType, filesize($path), $error, true);
}

Expand All @@ -141,19 +145,19 @@ public function testCreateResponse()
$response = new Response(
'Response content.',
202,
array('X-Symfony' => array('2.8'))
array('X-Symfony' => array('3.4'))
);
$response->headers->setCookie(new Cookie('city', 'Lille', new \DateTime('Wed, 13 Jan 2021 22:23:01 GMT')));

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

$cookieHeader = $psrResponse->getHeader('Set-Cookie');
$this->assertInternalType('array', $cookieHeader);
$this->assertCount(1, $cookieHeader);
$this->assertRegExp('{city=Lille; expires=Wed, 13-Jan-2021 22:23:01 GMT;( max-age=\d+;)? path=/; httponly}', $cookieHeader[0]);
$this->assertRegExp('{city=Lille; expires=Wed, 13-Jan-2021 22:23:01 GMT;( max-age=\d+;)? path=/; httponly}i', $cookieHeader[0]);
}

public function testCreateResponseFromStreamed()
Expand Down Expand Up @@ -185,11 +189,15 @@ public function testCreateResponseFromBinaryFile()

public function testUploadErrNoFile()
{
$file = new UploadedFile('', '', null, 0, UPLOAD_ERR_NO_FILE, true);
if (class_exists('Symfony\Component\HttpFoundation\HeaderUtils')) {
// Symfony 4.1+
$file = new UploadedFile('', '', null, UPLOAD_ERR_NO_FILE, true);
} else {
$file = new UploadedFile('', '', null, 0, UPLOAD_ERR_NO_FILE, true);
}
$this->assertEquals(0, $file->getSize());
$this->assertEquals(UPLOAD_ERR_NO_FILE, $file->getError());
$this->assertFalse($file->getSize(), 'SplFile::getSize() returns false on error');
$this->assertInternalType('integer', $file->getClientSize());

$request = new Request(array(), array(), array(), array(),
array(
Expand Down
3 changes: 2 additions & 1 deletion Tests/Factory/HttpFoundationFactoryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -146,11 +146,12 @@ public function testCreateUploadedFile()
{
$uploadedFile = $this->createUploadedFile('An uploaded file.', UPLOAD_ERR_OK, 'myfile.txt', 'text/plain');
$symfonyUploadedFile = $this->callCreateUploadedFile($uploadedFile);
$size = $symfonyUploadedFile->getSize();

$uniqid = uniqid();
$symfonyUploadedFile->move($this->tmpDir, $uniqid);

$this->assertEquals($uploadedFile->getSize(), $symfonyUploadedFile->getClientSize());
$this->assertEquals($uploadedFile->getSize(), $size);
$this->assertEquals(UPLOAD_ERR_OK, $symfonyUploadedFile->getError());
$this->assertEquals('myfile.txt', $symfonyUploadedFile->getClientOriginalName());
$this->assertEquals('txt', $symfonyUploadedFile->getClientOriginalExtension());
Expand Down
9 changes: 4 additions & 5 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,12 @@
}
],
"require": {
"php": ">=5.3.3",
"psr/http-message": "~1.0",
"symfony/http-foundation": "~2.3|~3.0|~4.0"
"php": "^5.3.3 || ^7.0",
"psr/http-message": "^1.0",
"symfony/http-foundation": "^2.3.42 || ^3.4 || ^4.0"
},
"require-dev": {
"symfony/phpunit-bridge": "~3.2|4.0"
"symfony/phpunit-bridge": "^3.4 || 4.0"
},
"suggest": {
"psr/http-message-implementation": "To use the HttpFoundation factory",
Expand All @@ -30,7 +30,6 @@
"autoload": {
"psr-4": { "Symfony\\Bridge\\PsrHttpMessage\\": "" }
},
"minimum-stability": "dev",
"extra": {
"branch-alias": {
"dev-master": "1.0-dev"
Expand Down