Merge branch '4.4' into 5.2

* 4.4:
  fix tests (ter)
  Fix tests (bis)
  [travis] fix travis hopefuly
  [Security] Fix SerializableUser fixture
  [FrameworkBundle][WebProfilerBundle] Don't pass null to string parameters
This commit is contained in:
Nicolas Grekas 2021-06-07 16:50:44 +02:00
commit dd12fe599d
12 changed files with 71 additions and 51 deletions

View File

@ -15,7 +15,7 @@ jobs:
strategy: strategy:
matrix: matrix:
php: ['7.2', '7.4'] php: ['7.2', '8.0']
services: services:
postgres: postgres:
@ -183,14 +183,14 @@ jobs:
KAFKA_BROKER: 127.0.0.1:9092 KAFKA_BROKER: 127.0.0.1:9092
POSTGRES_HOST: localhost POSTGRES_HOST: localhost
- name: Run HTTP push tests #- name: Run HTTP push tests
if: matrix.php == '7.4' # if: matrix.php == '8.0'
run: | # run: |
[ -d .phpunit ] && mv .phpunit .phpunit.bak # [ -d .phpunit ] && mv .phpunit .phpunit.bak
wget -q https://github.com/symfony/binary-utils/releases/download/v0.1/vulcain_0.1.3_Linux_x86_64.tar.gz -O - | tar xz && mv vulcain /usr/local/bin # wget -q https://github.com/symfony/binary-utils/releases/download/v0.1/vulcain_0.1.3_Linux_x86_64.tar.gz -O - | tar xz && mv vulcain /usr/local/bin
docker run --rm -e COMPOSER_ROOT_VERSION -v $(pwd):/app -v $(which composer):/usr/local/bin/composer -v /usr/local/bin/vulcain:/usr/local/bin/vulcain -w /app php:7.4-alpine ./phpunit src/Symfony/Component/HttpClient/Tests/CurlHttpClientTest.php --filter testHttp2Push # docker run --rm -e COMPOSER_ROOT_VERSION -v $(pwd):/app -v $(which composer):/usr/local/bin/composer -v $(which vulcain):/usr/local/bin/vulcain -w /app php:8.0-alpine ./phpunit src/Symfony/Component/HttpClient/Tests/CurlHttpClientTest.php --filter testHttp2Push
sudo rm -rf .phpunit # sudo rm -rf .phpunit
[ -d .phpunit.bak ] && mv .phpunit.bak .phpunit # [ -d .phpunit.bak ] && mv .phpunit.bak .phpunit
nightly: nightly:
name: PHPUnit on PHP nightly name: PHPUnit on PHP nightly

View File

@ -1,6 +1,6 @@
language: php language: php
dist: xenial dist: bionic
git: git:
depth: 2 depth: 2
@ -11,6 +11,10 @@ addons:
- language-pack-fr-base - language-pack-fr-base
- zookeeperd - zookeeperd
- libzookeeper-mt-dev - libzookeeper-mt-dev
- librabbitmq-dev
- libsodium-dev
- libtidy-dev
- zlib1g-dev
env: env:
global: global:
@ -36,15 +40,6 @@ cache:
- ~/php-ext - ~/php-ext
before_install: before_install:
- |
# Enable extra ppa
sudo apt-key adv --keyserver keyserver.ubuntu.com --recv-keys 6B05F25D762E3157
sudo add-apt-repository -y ppa:ondrej/php
sudo rm /etc/apt/sources.list.d/google-chrome.list
sudo rm /etc/apt/sources.list.d/mongodb-3.4.list
sudo apt update
sudo apt install -y librabbitmq-dev libsodium-dev php-uuid zlib1g-dev
- | - |
# General configuration # General configuration
set -e set -e
@ -123,8 +118,13 @@ before_install:
- | - |
# php.ini configuration # php.ini configuration
(
for PHP in $TRAVIS_PHP_VERSION $php_extra; do
phpenv global $PHP 2>/dev/null || (cd / && wget https://storage.googleapis.com/travis-ci-language-archives/php/binaries/ubuntu/18.04/x86_64/php-$PHP.tar.bz2 -O - | tar -xj) &
done
wait
)
for PHP in $TRAVIS_PHP_VERSION $php_extra; do for PHP in $TRAVIS_PHP_VERSION $php_extra; do
phpenv global $PHP 2>/dev/null || (cd / && wget https://storage.googleapis.com/travis-ci-language-archives/php/binaries/ubuntu/16.04/x86_64/php-$PHP.tar.bz2 -O - | tar -xj)
INI=~/.phpenv/versions/$PHP/etc/conf.d/travis.ini INI=~/.phpenv/versions/$PHP/etc/conf.d/travis.ini
echo date.timezone = Europe/Paris >> $INI echo date.timezone = Europe/Paris >> $INI
echo memory_limit = -1 >> $INI echo memory_limit = -1 >> $INI
@ -132,34 +132,30 @@ before_install:
echo session.gc_probability = 0 >> $INI echo session.gc_probability = 0 >> $INI
echo opcache.enable_cli = 1 >> $INI echo opcache.enable_cli = 1 >> $INI
echo apc.enable_cli = 1 >> $INI echo apc.enable_cli = 1 >> $INI
if [[ $PHP != 8.* ]]; then
echo extension = memcached.so >> $INI
fi
done done
find ~/.phpenv -name xdebug.ini -delete find ~/.phpenv -name xdebug.ini -delete
composer self-update
composer self-update --2
- | - |
# Install extra PHP extensions # Install extra PHP extensions
for PHP in $TRAVIS_PHP_VERSION $php_extra; do for PHP in $TRAVIS_PHP_VERSION $php_extra; do
export PHP=$PHP export PHP=$PHP
phpenv global $PHP phpenv global $PHP
composer self-update
composer self-update --2
INI=~/.phpenv/versions/$PHP/etc/conf.d/travis.ini INI=~/.phpenv/versions/$PHP/etc/conf.d/travis.ini
if ! php --ri sodium > /dev/null; then if ! php --ri sodium > /dev/null; then
tfold ext.libsodium tpecl libsodium sodium.so $INI tfold ext.libsodium tpecl libsodium sodium.so $INI
fi fi
if [[ $PHP = 8.* ]]; then if [[ $PHP != 8.* ]]; then
tfold ext.memcached tpecl memcached-3.1.5 memcached.so $INI
else
tfold ext.zookeeper tpecl zookeeper-0.7.2 zookeeper.so $INI tfold ext.zookeeper tpecl zookeeper-0.7.2 zookeeper.so $INI
tfold ext.amqp tpecl amqp-1.10.2 amqp.so $INI
fi fi
tfold ext.memcached tpecl memcached-3.1.5 memcached.so $INI
tfold ext.mongodb tpecl mongodb-1.9.0 mongodb.so $INI tfold ext.amqp tpecl amqp-1.11.0beta amqp.so $INI
tfold ext.apcu tpecl apcu-5.1.19 apcu.so $INI tfold ext.apcu tpecl apcu-5.1.19 apcu.so $INI
tfold ext.igbinary tpecl igbinary-3.1.6 igbinary.so $INI tfold ext.igbinary tpecl igbinary-3.1.6 igbinary.so $INI
tfold ext.redis tpecl redis-5.2.3 redis.so $INI "no" tfold ext.redis tpecl redis-5.2.3 redis.so $INI "no"
tfold ext.mongodb tpecl mongodb-1.9.1 mongodb.so $INI
done done
install: install:

View File

@ -315,7 +315,7 @@ class XmlDescriptor extends Descriptor
$descriptionXML->appendChild($dom->createCDATASection($classDescription)); $descriptionXML->appendChild($dom->createCDATASection($classDescription));
} }
$serviceXML->setAttribute('class', $definition->getClass()); $serviceXML->setAttribute('class', $definition->getClass() ?? '');
if ($factory = $definition->getFactory()) { if ($factory = $definition->getFactory()) {
$serviceXML->appendChild($factoryXML = $dom->createElement('factory')); $serviceXML->appendChild($factoryXML = $dom->createElement('factory'));
@ -341,7 +341,7 @@ class XmlDescriptor extends Descriptor
$serviceXML->setAttribute('abstract', $definition->isAbstract() ? 'true' : 'false'); $serviceXML->setAttribute('abstract', $definition->isAbstract() ? 'true' : 'false');
$serviceXML->setAttribute('autowired', $definition->isAutowired() ? 'true' : 'false'); $serviceXML->setAttribute('autowired', $definition->isAutowired() ? 'true' : 'false');
$serviceXML->setAttribute('autoconfigured', $definition->isAutoconfigured() ? 'true' : 'false'); $serviceXML->setAttribute('autoconfigured', $definition->isAutoconfigured() ? 'true' : 'false');
$serviceXML->setAttribute('file', $definition->getFile()); $serviceXML->setAttribute('file', $definition->getFile() ?? '');
$calls = $definition->getMethodCalls(); $calls = $definition->getMethodCalls();
if (\count($calls) > 0) { if (\count($calls) > 0) {

View File

@ -103,7 +103,7 @@ class WebDebugToolbarListener implements EventSubscriberInterface
|| $response->isRedirection() || $response->isRedirection()
|| ($response->headers->has('Content-Type') && false === strpos($response->headers->get('Content-Type'), 'html')) || ($response->headers->has('Content-Type') && false === strpos($response->headers->get('Content-Type'), 'html'))
|| 'html' !== $request->getRequestFormat() || 'html' !== $request->getRequestFormat()
|| false !== stripos($response->headers->get('Content-Disposition'), 'attachment;') || false !== stripos($response->headers->get('Content-Disposition', ''), 'attachment;')
) { ) {
return; return;
} }

View File

@ -38,7 +38,8 @@ class CurlHttpClientTest extends HttpClientTestCase
public function testBindToPort() public function testBindToPort()
{ {
$client = $this->getHttpClient(__FUNCTION__); $client = $this->getHttpClient(__FUNCTION__);
$response = $client->request('GET', 'http://localhost:8057', ['bindto' => '127.0.0.1:9876']); $localhost = gethostbyname('localhost');
$response = $client->request('GET', "http://$localhost:8057", ['bindto' => "$localhost:9876"]);
$response->getStatusCode(); $response->getStatusCode();
$r = new \ReflectionProperty($response, 'handle'); $r = new \ReflectionProperty($response, 'handle');
@ -46,7 +47,7 @@ class CurlHttpClientTest extends HttpClientTestCase
$curlInfo = curl_getinfo($r->getValue($response)); $curlInfo = curl_getinfo($r->getValue($response));
self::assertSame('127.0.0.1', $curlInfo['local_ip']); self::assertSame($localhost, $curlInfo['local_ip']);
self::assertSame(9876, $curlInfo['local_port']); self::assertSame(9876, $curlInfo['local_port']);
} }

View File

@ -298,13 +298,15 @@ abstract class HttpClientTestCase extends BaseHttpClientTestCase
self::markTestSkipped('Testing with the "vulcain" is not supported on Windows.'); self::markTestSkipped('Testing with the "vulcain" is not supported on Windows.');
} }
if (['application/json'] !== $client->request('GET', 'http://127.0.0.1:8057/json')->getHeaders()['content-type']) { $localhost = gethostbyname('localhost');
if (['application/json'] !== $client->request('GET', "http://$localhost:8057/json")->getHeaders()['content-type']) {
self::markTestSkipped('symfony/http-client-contracts >= 2.0.1 required'); self::markTestSkipped('symfony/http-client-contracts >= 2.0.1 required');
} }
$process = new Process(['vulcain'], null, [ $process = new Process(['vulcain'], null, [
'DEBUG' => 1, 'DEBUG' => 1,
'UPSTREAM' => 'http://127.0.0.1:8057', 'UPSTREAM' => "http://$localhost:8057",
'ADDR' => ':3000', 'ADDR' => ':3000',
'KEY_FILE' => __DIR__.'/Fixtures/tls/server.key', 'KEY_FILE' => __DIR__.'/Fixtures/tls/server.key',
'CERT_FILE' => __DIR__.'/Fixtures/tls/server.crt', 'CERT_FILE' => __DIR__.'/Fixtures/tls/server.crt',

View File

@ -23,7 +23,7 @@
"require": { "require": {
"php": ">=7.2.5", "php": ">=7.2.5",
"psr/log": "^1.0", "psr/log": "^1.0",
"symfony/http-client-contracts": "^2.2", "symfony/http-client-contracts": "~2.2.1|~2.3.2|^2.4.1",
"symfony/polyfill-php73": "^1.11", "symfony/polyfill-php73": "^1.11",
"symfony/polyfill-php80": "^1.15", "symfony/polyfill-php80": "^1.15",
"symfony/service-contracts": "^1.0|^2" "symfony/service-contracts": "^1.0|^2"

View File

@ -20,4 +20,9 @@ class FileBinaryMimeTypeGuesserTest extends AbstractMimeTypeGuesserTest
{ {
return new FileBinaryMimeTypeGuesser(); return new FileBinaryMimeTypeGuesser();
} }
public function testGuessWithDuplicatedFileType()
{
$this->markTestSkipped('Result varies depending on the OS');
}
} }

View File

@ -235,12 +235,22 @@ class SerializableUser implements UserInterface, \Serializable
public function serialize(): string public function serialize(): string
{ {
return serialize($this->name); return serialize($this->__serialize());
} }
public function unserialize($serialized): void public function unserialize($serialized): void
{ {
$this->name = unserialize($serialized); $this->__unserialize(unserialize($serialized));
}
public function __serialize(): array
{
return ['name' => $this->name];
}
public function __unserialize(array $data): void
{
['name' => $this->name] = $data;
} }
} }

View File

@ -30,6 +30,7 @@ foreach ($_SERVER as $k => $v) {
} }
$json = json_encode($vars, \JSON_PRETTY_PRINT | \JSON_UNESCAPED_SLASHES | \JSON_UNESCAPED_UNICODE); $json = json_encode($vars, \JSON_PRETTY_PRINT | \JSON_UNESCAPED_SLASHES | \JSON_UNESCAPED_UNICODE);
$localhost = gethostbyname('localhost');
switch ($vars['REQUEST_URI']) { switch ($vars['REQUEST_URI']) {
default: default:
@ -41,7 +42,7 @@ switch ($vars['REQUEST_URI']) {
case '/': case '/':
case '/?a=a&b=b': case '/?a=a&b=b':
case 'http://127.0.0.1:8057/': case "http://$localhost:8057/":
case 'http://localhost:8057/': case 'http://localhost:8057/':
ob_start('ob_gzhandler'); ob_start('ob_gzhandler');
break; break;
@ -74,7 +75,7 @@ switch ($vars['REQUEST_URI']) {
case '/301': case '/301':
if ('Basic Zm9vOmJhcg==' === $vars['HTTP_AUTHORIZATION']) { if ('Basic Zm9vOmJhcg==' === $vars['HTTP_AUTHORIZATION']) {
header('Location: http://127.0.0.1:8057/302', true, 301); header("Location: http://$localhost:8057/302", true, 301);
} }
break; break;

View File

@ -334,6 +334,7 @@ abstract class HttpClientTestCase extends TestCase
public function testRedirects() public function testRedirects()
{ {
$client = $this->getHttpClient(__FUNCTION__); $client = $this->getHttpClient(__FUNCTION__);
$localhost = gethostbyname('localhost');
$response = $client->request('POST', 'http://localhost:8057/301', [ $response = $client->request('POST', 'http://localhost:8057/301', [
'auth_basic' => 'foo:bar', 'auth_basic' => 'foo:bar',
'body' => function () { 'body' => function () {
@ -351,7 +352,7 @@ abstract class HttpClientTestCase extends TestCase
$expected = [ $expected = [
'HTTP/1.1 301 Moved Permanently', 'HTTP/1.1 301 Moved Permanently',
'Location: http://127.0.0.1:8057/302', "Location: http://$localhost:8057/302",
'Content-Type: application/json', 'Content-Type: application/json',
'HTTP/1.1 302 Found', 'HTTP/1.1 302 Found',
'Location: http://localhost:8057/', 'Location: http://localhost:8057/',
@ -424,6 +425,7 @@ abstract class HttpClientTestCase extends TestCase
public function testMaxRedirects() public function testMaxRedirects()
{ {
$client = $this->getHttpClient(__FUNCTION__); $client = $this->getHttpClient(__FUNCTION__);
$localhost = gethostbyname('localhost');
$response = $client->request('GET', 'http://localhost:8057/301', [ $response = $client->request('GET', 'http://localhost:8057/301', [
'max_redirects' => 1, 'max_redirects' => 1,
'auth_basic' => 'foo:bar', 'auth_basic' => 'foo:bar',
@ -441,7 +443,7 @@ abstract class HttpClientTestCase extends TestCase
$expected = [ $expected = [
'HTTP/1.1 301 Moved Permanently', 'HTTP/1.1 301 Moved Permanently',
'Location: http://127.0.0.1:8057/302', "Location: http://$localhost:8057/302",
'Content-Type: application/json', 'Content-Type: application/json',
'HTTP/1.1 302 Found', 'HTTP/1.1 302 Found',
'Location: http://localhost:8057/', 'Location: http://localhost:8057/',
@ -690,8 +692,9 @@ abstract class HttpClientTestCase extends TestCase
public function testResolve() public function testResolve()
{ {
$client = $this->getHttpClient(__FUNCTION__); $client = $this->getHttpClient(__FUNCTION__);
$localhost = gethostbyname('localhost');
$response = $client->request('GET', 'http://symfony.com:8057/', [ $response = $client->request('GET', 'http://symfony.com:8057/', [
'resolve' => ['symfony.com' => '127.0.0.1'], 'resolve' => ['symfony.com' => $localhost],
]); ]);
$this->assertSame(200, $response->getStatusCode()); $this->assertSame(200, $response->getStatusCode());
@ -705,15 +708,16 @@ abstract class HttpClientTestCase extends TestCase
public function testIdnResolve() public function testIdnResolve()
{ {
$client = $this->getHttpClient(__FUNCTION__); $client = $this->getHttpClient(__FUNCTION__);
$localhost = gethostbyname('localhost');
$response = $client->request('GET', 'http://0-------------------------------------------------------------0.com:8057/', [ $response = $client->request('GET', 'http://0-------------------------------------------------------------0.com:8057/', [
'resolve' => ['0-------------------------------------------------------------0.com' => '127.0.0.1'], 'resolve' => ['0-------------------------------------------------------------0.com' => $localhost],
]); ]);
$this->assertSame(200, $response->getStatusCode()); $this->assertSame(200, $response->getStatusCode());
$response = $client->request('GET', 'http://Bücher.example:8057/', [ $response = $client->request('GET', 'http://Bücher.example:8057/', [
'resolve' => ['xn--bcher-kva.example' => '127.0.0.1'], 'resolve' => ['xn--bcher-kva.example' => $localhost],
]); ]);
$this->assertSame(200, $response->getStatusCode()); $this->assertSame(200, $response->getStatusCode());
@ -881,7 +885,7 @@ abstract class HttpClientTestCase extends TestCase
$body = $response->toArray(); $body = $response->toArray();
$this->assertSame('localhost:8057', $body['HTTP_HOST']); $this->assertSame('localhost:8057', $body['HTTP_HOST']);
$this->assertMatchesRegularExpression('#^http://(localhost|127\.0\.0\.1):8057/$#', $body['REQUEST_URI']); $this->assertMatchesRegularExpression('#^http://(localhost|127\.0\.\d+\.1):8057/$#', $body['REQUEST_URI']);
$response = $client->request('GET', 'http://localhost:8057/', [ $response = $client->request('GET', 'http://localhost:8057/', [
'proxy' => 'http://foo:b%3Dar@localhost:8057', 'proxy' => 'http://foo:b%3Dar@localhost:8057',

View File

@ -28,15 +28,16 @@ class TestHttpServer
}); });
} }
$localhost = gethostbyname('localhost');
$finder = new PhpExecutableFinder(); $finder = new PhpExecutableFinder();
$process = new Process(array_merge([$finder->find(false)], $finder->findArguments(), ['-dopcache.enable=0', '-dvariables_order=EGPCS', '-S', '127.0.0.1:'.$port])); $process = new Process(array_merge([$finder->find(false)], $finder->findArguments(), ['-dopcache.enable=0', '-dvariables_order=EGPCS', '-S', "$localhost:$port"]));
$process->setWorkingDirectory(__DIR__.'/Fixtures/web'); $process->setWorkingDirectory(__DIR__.'/Fixtures/web');
$process->start(); $process->start();
self::$process[$port] = $process; self::$process[$port] = $process;
do { do {
usleep(50000); usleep(50000);
} while (!@fopen('http://127.0.0.1:'.$port, 'r')); } while (!@fopen("http://$localhost:$port", 'r'));
return $process; return $process;
} }