Skip to content

Commit f11f173

Browse files
committed
feature #45 Fixed broken build (Nyholm)
This PR was squashed before being merged into the 1.0-dev branch (closes #45). Discussion ---------- Fixed broken build This PR updates travis.yml to adapt to our best practices: https://symfony.com/doc/current/bundles/best_practices.html It update our dependencies (dropping sf2.8 and unsupported symfony versions) It also remove use of deprecated code. Commits ------- 8780dd3 Fixed broken build
2 parents c2b7579 + 8780dd3 commit f11f173

6 files changed

+83
-46
lines changed

.travis.yml

+44-27
Original file line numberDiff line numberDiff line change
@@ -1,49 +1,66 @@
11
language: php
2-
32
sudo: false
4-
53
cache:
64
directories:
75
- $HOME/.composer/cache/files
86
- $HOME/symfony-bridge/.phpunit
97

8+
env:
9+
global:
10+
- PHPUNIT_FLAGS="-v"
11+
- SYMFONY_PHPUNIT_DIR="$HOME/symfony-bridge/.phpunit"
12+
- DEPENDENCIES="zendframework/zend-diactoros:^1.4.1"
13+
1014
matrix:
15+
fast_finish: true
1116
include:
17+
# Minimum supported dependencies with the latest and oldest PHP version
18+
- php: 7.2
19+
env: COMPOSER_FLAGS="--prefer-stable --prefer-lowest" SYMFONY_DEPRECATIONS_HELPER="weak_vendors"
1220
- php: 5.3
1321
dist: 'precise'
14-
- php: 5.4
15-
- php: 5.5
16-
- php: 5.6
22+
env: COMPOSER_FLAGS="--prefer-stable --prefer-lowest" SYMFONY_DEPRECATIONS_HELPER="weak_vendors" DEPENDENCIES=""
23+
24+
# Test the latest stable release
1725
- php: 5.3
1826
dist: 'precise'
19-
env: COMPOSER_OPTIONS="--prefer-lowest --prefer-stable" SYMFONY_DEPRECATIONS_HELPER=weak
27+
env: DEPENDENCIES=""
28+
- php: 5.4
29+
- php: 5.5
2030
- php: 5.6
21-
env: COMPOSER_OPTIONS="" SYMFONY_DEPRECATIONS_HELPER=weak
2231
- php: 7.0
23-
- php: hhvm
24-
allow_failures:
25-
- php: hhvm
26-
fast_finish: true
32+
- php: 7.1
33+
- php: 7.2
34+
env: COVERAGE=true PHPUNIT_FLAGS="-v --coverage-text"
2735

28-
env:
29-
global:
30-
- deps=no
31-
- SYMFONY_DEPRECATIONS_HELPER=strict
32-
- SYMFONY_PHPUNIT_DIR="$HOME/symfony-bridge/.phpunit"
33-
- COMPOSER_OPTIONS="--prefer-stable"
36+
# Test LTS versions. This makes sure we do not use Symfony packages with version greater
37+
# than 2 or 3 respectively.
38+
- php: 7.2
39+
env: DEPENDENCIES="symfony/lts:^2 symfony/force-lowest:~2.8.0 zendframework/zend-diactoros:^1.4.1"
40+
- php: 7.2
41+
env: DEPENDENCIES="symfony/lts:^3 symfony/force-lowest:~3.4.0 zendframework/zend-diactoros:^1.4.1"
42+
43+
# Latest commit to master
44+
- php: 7.2
45+
env: STABILITY="dev"
46+
47+
allow_failures:
48+
# Dev-master is allowed to fail.
49+
- env: STABILITY="dev"
3450

3551
before_install:
36-
- if [[ "$TRAVIS_PHP_VERSION" != "nightly" ]] && [[ "$TRAVIS_PHP_VERSION" != "hhvm" ]]; then phpenv config-rm xdebug.ini; fi;
37-
- composer self-update
38-
- 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;
39-
- if [[ "$TRAVIS_PHP_VERSION" != "nightly" ]] && [[ "$TRAVIS_PHP_VERSION" != "hhvm" ]]; then php -i; fi;
40-
# Set the COMPOSER_ROOT_VERSION to the right version according to the branch being built
41-
- if [ "$TRAVIS_BRANCH" = "master" ]; then export COMPOSER_ROOT_VERSION=dev-master; else export COMPOSER_ROOT_VERSION="$TRAVIS_BRANCH".x-dev; fi;
52+
- if [[ $COVERAGE != true ]]; then phpenv config-rm xdebug.ini || true; fi
53+
- if ! [ -z "$STABILITY" ]; then composer config minimum-stability ${STABILITY}; fi;
54+
- if ! [ -v "$DEPENDENCIES" ]; then composer require --no-update ${DEPENDENCIES}; fi;
4255

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

4862
script:
49-
- vendor/bin/simple-phpunit
63+
- composer validate --strict --no-check-lock
64+
# simple-phpunit is the PHPUnit wrapper provided by the PHPUnit Bridge component and
65+
# it helps with testing legacy code and deprecations (composer require symfony/phpunit-bridge)
66+
- ./vendor/bin/simple-phpunit $PHPUNIT_FLAGS

Factory/DiactorosFactory.php

+9-8
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111

1212
namespace Symfony\Bridge\PsrHttpMessage\Factory;
1313

14+
use Psr\Http\Message\UploadedFileInterface;
1415
use Symfony\Bridge\PsrHttpMessage\HttpMessageFactoryInterface;
1516
use Symfony\Component\HttpFoundation\BinaryFileResponse;
1617
use Symfony\Component\HttpFoundation\File\UploadedFile;
@@ -112,7 +113,7 @@ private function createUploadedFile(UploadedFile $symfonyUploadedFile)
112113
{
113114
return new DiactorosUploadedFile(
114115
$symfonyUploadedFile->getRealPath(),
115-
$symfonyUploadedFile->getClientSize(),
116+
(int) $symfonyUploadedFile->getSize(),
116117
$symfonyUploadedFile->getError(),
117118
$symfonyUploadedFile->getClientOriginalName(),
118119
$symfonyUploadedFile->getClientMimeType()
@@ -143,13 +144,13 @@ public function createResponse(Response $symfonyResponse)
143144
}
144145

145146
$headers = $symfonyResponse->headers->all();
146-
147-
$cookies = $symfonyResponse->headers->getCookies();
148-
if (!empty($cookies)) {
149-
$headers['Set-Cookie'] = array();
150-
151-
foreach ($cookies as $cookie) {
152-
$headers['Set-Cookie'][] = $cookie->__toString();
147+
if (!isset($headers['Set-Cookie']) && !isset($headers['set-sookie'])) {
148+
$cookies = $symfonyResponse->headers->getCookies();
149+
if (!empty($cookies)) {
150+
$headers['Set-Cookie'] = array();
151+
foreach ($cookies as $cookie) {
152+
$headers['Set-Cookie'][] = $cookie->__toString();
153+
}
153154
}
154155
}
155156

Factory/HttpFoundationFactory.php

+11
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,17 @@ private function createUploadedFile(UploadedFileInterface $psrUploadedFile)
104104
$clientFileName = $psrUploadedFile->getClientFilename();
105105
}
106106

107+
if (class_exists('Symfony\Component\HttpFoundation\HeaderUtils')) {
108+
// Symfony 4.1+
109+
return new UploadedFile(
110+
$temporaryPath,
111+
null === $clientFileName ? '' : $clientFileName,
112+
$psrUploadedFile->getClientMediaType(),
113+
$psrUploadedFile->getError(),
114+
true
115+
);
116+
}
117+
107118
return new UploadedFile(
108119
$temporaryPath,
109120
null === $clientFileName ? '' : $clientFileName,

Tests/Factory/DiactorosFactoryTest.php

+13-5
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,10 @@ private function createUploadedFile($content, $originalName, $mimeType, $error)
133133
$path = tempnam($this->tmpDir, uniqid());
134134
file_put_contents($path, $content);
135135

136+
if (class_exists('Symfony\Component\HttpFoundation\HeaderUtils')) {
137+
// Symfony 4.1+
138+
return new UploadedFile($path, $originalName, $mimeType, $error, true);
139+
}
136140
return new UploadedFile($path, $originalName, $mimeType, filesize($path), $error, true);
137141
}
138142

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

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

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

159163
public function testCreateResponseFromStreamed()
@@ -185,11 +189,15 @@ public function testCreateResponseFromBinaryFile()
185189

186190
public function testUploadErrNoFile()
187191
{
188-
$file = new UploadedFile('', '', null, 0, UPLOAD_ERR_NO_FILE, true);
192+
if (class_exists('Symfony\Component\HttpFoundation\HeaderUtils')) {
193+
// Symfony 4.1+
194+
$file = new UploadedFile('', '', null, UPLOAD_ERR_NO_FILE, true);
195+
} else {
196+
$file = new UploadedFile('', '', null, 0, UPLOAD_ERR_NO_FILE, true);
197+
}
189198
$this->assertEquals(0, $file->getSize());
190199
$this->assertEquals(UPLOAD_ERR_NO_FILE, $file->getError());
191200
$this->assertFalse($file->getSize(), 'SplFile::getSize() returns false on error');
192-
$this->assertInternalType('integer', $file->getClientSize());
193201

194202
$request = new Request(array(), array(), array(), array(),
195203
array(

Tests/Factory/HttpFoundationFactoryTest.php

+2-1
Original file line numberDiff line numberDiff line change
@@ -146,11 +146,12 @@ public function testCreateUploadedFile()
146146
{
147147
$uploadedFile = $this->createUploadedFile('An uploaded file.', UPLOAD_ERR_OK, 'myfile.txt', 'text/plain');
148148
$symfonyUploadedFile = $this->callCreateUploadedFile($uploadedFile);
149+
$size = $symfonyUploadedFile->getSize();
149150

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

153-
$this->assertEquals($uploadedFile->getSize(), $symfonyUploadedFile->getClientSize());
154+
$this->assertEquals($uploadedFile->getSize(), $size);
154155
$this->assertEquals(UPLOAD_ERR_OK, $symfonyUploadedFile->getError());
155156
$this->assertEquals('myfile.txt', $symfonyUploadedFile->getClientOriginalName());
156157
$this->assertEquals('txt', $symfonyUploadedFile->getClientOriginalExtension());

composer.json

+4-5
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,12 @@
1616
}
1717
],
1818
"require": {
19-
"php": ">=5.3.3",
20-
"psr/http-message": "~1.0",
21-
"symfony/http-foundation": "~2.3|~3.0|~4.0"
19+
"php": "^5.3.3 || ^7.0",
20+
"psr/http-message": "^1.0",
21+
"symfony/http-foundation": "^2.3.42 || ^3.4 || ^4.0"
2222
},
2323
"require-dev": {
24-
"symfony/phpunit-bridge": "~3.2|4.0"
24+
"symfony/phpunit-bridge": "^3.4 || 4.0"
2525
},
2626
"suggest": {
2727
"psr/http-message-implementation": "To use the HttpFoundation factory",
@@ -30,7 +30,6 @@
3030
"autoload": {
3131
"psr-4": { "Symfony\\Bridge\\PsrHttpMessage\\": "" }
3232
},
33-
"minimum-stability": "dev",
3433
"extra": {
3534
"branch-alias": {
3635
"dev-master": "1.0-dev"

0 commit comments

Comments
 (0)