Merge branch '3.2'

* 3.2:
  Allow terminal dimensions to be set to 0 (unbounded)
  [Cache] Remove exception false-positive from FilesystemAdapterTrait
  fix risky tests
  fix risky tests
  [Yaml] release memory after parsing
  [HttpFoundation] Fix and test status codes according to IANA's data
  Add `use_strict_mode` in validOptions for session
  [Console] Inherit phpdoc from OutputFormatterInterface
This commit is contained in:
Nicolas Grekas 2017-04-11 20:40:10 +02:00
commit 6491fd5854
17 changed files with 164 additions and 61 deletions

View File

@ -27,26 +27,25 @@ trait FilesystemCommonTrait
{
if (!isset($directory[0])) {
$directory = sys_get_temp_dir().'/symfony-cache';
} else {
$directory = realpath($directory) ?: $directory;
}
if (isset($namespace[0])) {
if (preg_match('#[^-+_.A-Za-z0-9]#', $namespace, $match)) {
throw new InvalidArgumentException(sprintf('Namespace contains "%s" but only characters in [-+_.A-Za-z0-9] are allowed.', $match[0]));
}
$directory .= '/'.$namespace;
$directory .= DIRECTORY_SEPARATOR.$namespace;
}
if (!file_exists($dir = $directory.'/.')) {
if (!file_exists($directory)) {
@mkdir($directory, 0777, true);
}
if (false === $dir = realpath($dir) ?: (file_exists($dir) ? $dir : false)) {
throw new InvalidArgumentException(sprintf('Cache directory does not exist (%s)', $directory));
}
$dir .= DIRECTORY_SEPARATOR;
$directory .= DIRECTORY_SEPARATOR;
// On Windows the whole path is limited to 258 chars
if ('\\' === DIRECTORY_SEPARATOR && strlen($dir) > 234) {
if ('\\' === DIRECTORY_SEPARATOR && strlen($directory) > 234) {
throw new InvalidArgumentException(sprintf('Cache directory too long (%s)', $directory));
}
$this->directory = $dir;
$this->directory = $directory;
}
/**

View File

@ -81,9 +81,7 @@ class OutputFormatter implements OutputFormatterInterface
}
/**
* Sets the decorated flag.
*
* @param bool $decorated Whether to decorate the messages or not
* {@inheritdoc}
*/
public function setDecorated($decorated)
{
@ -91,9 +89,7 @@ class OutputFormatter implements OutputFormatterInterface
}
/**
* Gets the decorated flag.
*
* @return bool true if the output will decorate messages, false otherwise
* {@inheritdoc}
*/
public function isDecorated()
{
@ -101,10 +97,7 @@ class OutputFormatter implements OutputFormatterInterface
}
/**
* Sets a new style.
*
* @param string $name The style name
* @param OutputFormatterStyleInterface $style The style instance
* {@inheritdoc}
*/
public function setStyle($name, OutputFormatterStyleInterface $style)
{
@ -112,11 +105,7 @@ class OutputFormatter implements OutputFormatterInterface
}
/**
* Checks if output formatter has style with specified name.
*
* @param string $name
*
* @return bool
* {@inheritdoc}
*/
public function hasStyle($name)
{
@ -124,13 +113,7 @@ class OutputFormatter implements OutputFormatterInterface
}
/**
* Gets style options from style with specified name.
*
* @param string $name
*
* @return OutputFormatterStyleInterface
*
* @throws InvalidArgumentException When style isn't defined
* {@inheritdoc}
*/
public function getStyle($name)
{
@ -142,11 +125,7 @@ class OutputFormatter implements OutputFormatterInterface
}
/**
* Formats a message according to the given styles.
*
* @param string $message The message to style
*
* @return string The styled message
* {@inheritdoc}
*/
public function format($message)
{

View File

@ -55,6 +55,8 @@ interface OutputFormatterInterface
* @param string $name
*
* @return OutputFormatterStyleInterface
*
* @throws \InvalidArgumentException When style isn't defined
*/
public function getStyle($name);

View File

@ -23,8 +23,9 @@ class Terminal
*/
public function getWidth()
{
if ($width = trim(getenv('COLUMNS'))) {
return (int) $width;
$width = getenv('COLUMNS');
if (false !== $width) {
return (int) trim($width);
}
if (null === self::$width) {
@ -41,8 +42,9 @@ class Terminal
*/
public function getHeight()
{
if ($height = trim(getenv('LINES'))) {
return (int) $height;
$height = getenv('LINES');
if (false !== $height) {
return (int) trim($height);
}
if (null === self::$height) {

View File

@ -30,4 +30,15 @@ class TerminalTest extends TestCase
$this->assertSame(120, $terminal->getWidth());
$this->assertSame(60, $terminal->getHeight());
}
public function test_zero_values()
{
putenv('COLUMNS=0');
putenv('LINES=0');
$terminal = new Terminal();
$this->assertSame(0, $terminal->getWidth());
$this->assertSame(0, $terminal->getHeight());
}
}

View File

@ -615,6 +615,10 @@ class AutowirePassTest extends TestCase
$pass = new AutowirePass();
$pass->process($container);
$this->assertTrue($container->hasDefinition('deprecated'));
$this->assertTrue($container->hasDefinition('foo'));
$this->assertTrue($container->hasDefinition('bar'));
}
public function testEmptyStringIsKept()

View File

@ -55,7 +55,7 @@ class IniFileLoaderTest extends TestCase
}
if (!$supported) {
return;
$this->markTestSkipped(sprintf('Converting the value "%s" to "%s" is not supported by the IniFileLoader.', $key, $value));
}
$this->loader->load('types.ini');

View File

@ -593,7 +593,10 @@ class FilesystemTest extends FilesystemTestCase
$this->filesystem->hardlink($file, $link);
$this->filesystem->chown($link, $this->getFileOwner($link));
$owner = $this->getFileOwner($link);
$this->filesystem->chown($link, $owner);
$this->assertSame($owner, $this->getFileOwner($link));
}
/**
@ -699,7 +702,10 @@ class FilesystemTest extends FilesystemTestCase
$this->filesystem->hardlink($file, $link);
$this->filesystem->chgrp($link, $this->getFileGroup($link));
$group = $this->getFileGroup($link);
$this->filesystem->chgrp($link, $group);
$this->assertSame($group, $this->getFileGroup($link));
}
/**

View File

@ -13,6 +13,7 @@ namespace Symfony\Component\Form\Tests\Extension\Core\Type;
use Symfony\Component\Form\Extension\Core\Type\DateIntervalType;
use Symfony\Component\Form\FormError;
use Symfony\Component\Form\FormInterface;
class DateIntervalTypeTest extends BaseTypeTest
{
@ -195,7 +196,7 @@ class DateIntervalTypeTest extends BaseTypeTest
{
// Throws an exception if "data_class" option is not explicitly set
// to null in the type
$this->factory->create(static::TESTED_TYPE, new \DateInterval('P0Y'));
$this->assertInstanceOf(FormInterface::class, $this->factory->create(static::TESTED_TYPE, new \DateInterval('P0Y')));
}
public function testPassDefaultPlaceholderToViewIfNotRequired()

View File

@ -179,7 +179,7 @@ class Response
503 => 'Service Unavailable',
504 => 'Gateway Timeout',
505 => 'HTTP Version Not Supported',
506 => 'Variant Also Negotiates (Experimental)', // RFC2295
506 => 'Variant Also Negotiates', // RFC2295
507 => 'Insufficient Storage', // RFC4918
508 => 'Loop Detected', // RFC5842
510 => 'Not Extended', // RFC2774

View File

@ -81,6 +81,7 @@ class NativeSessionStorage implements SessionStorageInterface
* name, "PHPSESSID"
* referer_check, ""
* serialize_handler, "php"
* use_strict_mode, "0"
* use_cookies, "1"
* use_only_cookies, "1"
* use_trans_sid, "0"
@ -330,7 +331,7 @@ class NativeSessionStorage implements SessionStorageInterface
'entropy_file', 'entropy_length', 'gc_divisor',
'gc_maxlifetime', 'gc_probability', 'hash_bits_per_character',
'hash_function', 'name', 'referer_check',
'serialize_handler', 'use_cookies',
'serialize_handler', 'use_strict_mode', 'use_cookies',
'use_only_cookies', 'use_trans_sid', 'upload_progress.enabled',
'upload_progress.cleanup', 'upload_progress.prefix', 'upload_progress.name',
'upload_progress.freq', 'upload_progress.min-freq', 'url_rewriter.tags',

View File

@ -302,7 +302,7 @@ class RequestTest extends TestCase
}
/**
* @dataProvider getFormatToMimeTypeMapProvider
* @dataProvider getFormatToMimeTypeMapProviderWithAdditionalNullFormat
*/
public function testGetFormatFromMimeType($format, $mimeTypes)
{
@ -320,6 +320,14 @@ class RequestTest extends TestCase
}
}
public function getFormatToMimeTypeMapProviderWithAdditionalNullFormat()
{
return array_merge(
array(array(null, array(null, 'unexistent-mime-type'))),
$this->getFormatToMimeTypeMapProvider()
);
}
public function testGetFormatFromMimeTypeWithParameters()
{
$request = new Request();
@ -331,10 +339,8 @@ class RequestTest extends TestCase
*/
public function testGetMimeTypeFromFormat($format, $mimeTypes)
{
if (null !== $format) {
$request = new Request();
$this->assertEquals($mimeTypes[0], $request->getMimeType($format));
}
$request = new Request();
$this->assertEquals($mimeTypes[0], $request->getMimeType($format));
}
/**
@ -342,9 +348,7 @@ class RequestTest extends TestCase
*/
public function testGetMimeTypesFromFormat($format, $mimeTypes)
{
if (null !== $format) {
$this->assertEquals($mimeTypes, Request::getMimeTypes($format));
}
$this->assertEquals($mimeTypes, Request::getMimeTypes($format));
}
public function testGetMimeTypesFromInexistentFormat()
@ -364,7 +368,6 @@ class RequestTest extends TestCase
public function getFormatToMimeTypeMapProvider()
{
return array(
array(null, array(null, 'unexistent-mime-type')),
array('txt', array('text/plain')),
array('js', array('application/javascript', 'application/x-javascript', 'text/javascript')),
array('css', array('text/css')),

View File

@ -845,6 +845,16 @@ class ResponseTest extends ResponseTestCase
}
}
public function testNoDeprecationsAreTriggered()
{
new DefaultResponse();
$this->getMockBuilder(Response::class)->getMock();
// we just need to ensure that subclasses of Response can be created without any deprecations
// being triggered if the subclass does not override any final methods
$this->addToAssertionCount(1);
}
public function validContentProvider()
{
return array(
@ -884,6 +894,67 @@ class ResponseTest extends ResponseTestCase
{
return new Response();
}
/**
* @see http://github.com/zendframework/zend-diactoros for the canonical source repository
*
* @author Fábio Pacheco
* @copyright Copyright (c) 2015-2016 Zend Technologies USA Inc. (http://www.zend.com)
* @license https://github.com/zendframework/zend-diactoros/blob/master/LICENSE.md New BSD License
*/
public function ianaCodesReasonPhrasesProvider()
{
if (!in_array('https', stream_get_wrappers(), true)) {
$this->markTestSkipped('The "https" wrapper is not available');
}
$ianaHttpStatusCodes = new \DOMDocument();
libxml_set_streams_context(stream_context_create(array(
'http' => array(
'method' => 'GET',
'timeout' => 30,
),
)));
$ianaHttpStatusCodes->load('https://www.iana.org/assignments/http-status-codes/http-status-codes.xml');
if (!$ianaHttpStatusCodes->relaxNGValidate('https://www.iana.org/assignments/http-status-codes/http-status-codes.rng')) {
self::fail('Invalid IANA\'s HTTP status code list.');
}
$ianaCodesReasonPhrases = array();
$xpath = new \DomXPath($ianaHttpStatusCodes);
$xpath->registerNamespace('ns', 'http://www.iana.org/assignments');
$records = $xpath->query('//ns:record');
foreach ($records as $record) {
$value = $xpath->query('.//ns:value', $record)->item(0)->nodeValue;
$description = $xpath->query('.//ns:description', $record)->item(0)->nodeValue;
if (in_array($description, array('Unassigned', '(Unused)'), true)) {
continue;
}
if (preg_match('/^([0-9]+)\s*\-\s*([0-9]+)$/', $value, $matches)) {
for ($value = $matches[1]; $value <= $matches[2]; ++$value) {
$ianaCodesReasonPhrases[] = array($value, $description);
}
} else {
$ianaCodesReasonPhrases[] = array($value, $description);
}
}
return $ianaCodesReasonPhrases;
}
/**
* @dataProvider ianaCodesReasonPhrasesProvider
*/
public function testReasonPhraseDefaultsAgainstIana($code, $reasonPhrase)
{
$this->assertEquals($reasonPhrase, Response::$statusTexts[$code]);
}
}
class StringableObject

View File

@ -153,6 +153,8 @@ class LocaleTest extends AbstractLocaleTest
public function testSetDefaultAcceptsEn()
{
$this->call('setDefault', 'en');
$this->assertSame('en', $this->call('getDefault'));
}
protected function call($methodName)

View File

@ -36,7 +36,8 @@ class AbstractObjectNormalizerTest extends TestCase
$context = array();
$normalizer = new AbstractObjectNormalizerDummy();
$normalizer->instantiateObject($data, $class, $context, new \ReflectionClass($class), array());
$this->assertInstanceOf(__NAMESPACE__.'\Dummy', $normalizer->instantiateObject($data, $class, $context, new \ReflectionClass($class), array()));
}
/**

View File

@ -111,6 +111,12 @@ class Parser
mb_internal_encoding($mbEncoding);
}
$this->lines = array();
$this->currentLine = '';
$this->refs = array();
$this->skippedLineNumbers = array();
$this->locallySkippedLineNumbers = array();
if (null !== $e) {
throw $e;
}

View File

@ -277,14 +277,29 @@ class InlineTest extends TestCase
* @expectedException \Symfony\Component\Yaml\Exception\ParseException
* @expectedExceptionMessage cannot start a plain scalar; you need to quote the scalar.
*/
public function testParseUnquotedScalarStartingWithReservedIndicator($indicator)
public function testParseUnquotedScalarStartingWithReservedAtIndicator()
{
Inline::parse(sprintf('{ foo: %sfoo }', $indicator));
Inline::parse('{ foo: @foo }');
}
public function getReservedIndicators()
/**
* @group legacy
* @expectedDeprecation Not quoting the scalar "`foo " starting with "`" is deprecated since Symfony 2.8 and will throw a ParseException in 3.0.
* throws \Symfony\Component\Yaml\Exception\ParseException in 3.0
*/
public function testParseUnquotedScalarStartingWithReservedBacktickIndicator()
{
return array(array('@'), array('`'));
Inline::parse('{ foo: `foo }');
}
/**
* @group legacy
* @expectedDeprecation Not quoting the scalar "|foo " starting with "|" is deprecated since Symfony 2.8 and will throw a ParseException in 3.0.
* throws \Symfony\Component\Yaml\Exception\ParseException in 3.0
*/
public function testParseUnquotedScalarStartingWithLiteralStyleIndicator()
{
Inline::parse('{ foo: |foo }');
}
/**
@ -292,9 +307,9 @@ class InlineTest extends TestCase
* @expectedException \Symfony\Component\Yaml\Exception\ParseException
* @expectedExceptionMessage cannot start a plain scalar; you need to quote the scalar.
*/
public function testParseUnquotedScalarStartingWithScalarIndicator($indicator)
public function testParseUnquotedScalarStartingWithFoldedStyleIndicator()
{
Inline::parse(sprintf('{ foo: %sfoo }', $indicator));
Inline::parse('{ foo: >foo }');
}
public function getScalarIndicators()