Merge branch '4.0'
* 4.0: [YAML] Issue #26065: leading spaces in YAML multi-line string literals [Bridge\PhpUnit] Exit as late as possible [Bridge\PhpUnit] Cleanup BC layer [PhpBridge] add PHPUnit 7 support to SymfonyTestsListener [Lock] Log already-locked errors as "notice" instead of "warning" add context to serialize and deserialize Update Repository Symlink Helper isCsrfTokenValid() replace string by ?string Document explicitly that dotfiles and vcs files are ignored by default [HttpKernel] don't try to wire Request argument with controller.service_arguments Make kernel build time optionally deterministic Use 0 for unlimited expiry [Routing] fix typo Bump default PHPUnit version from 6.3 to 6.5 do not mock the container builder in tests [Cache][WebProfiler] fix collecting cache stats with sub-requests + allow clearing calls
This commit is contained in:
commit
e81aa7694c
7
link
7
link
@ -37,7 +37,12 @@ if (!is_dir("$argv[1]/vendor/symfony")) {
|
|||||||
$sfPackages = array('symfony/symfony' => __DIR__);
|
$sfPackages = array('symfony/symfony' => __DIR__);
|
||||||
|
|
||||||
$filesystem = new Filesystem();
|
$filesystem = new Filesystem();
|
||||||
foreach (glob(__DIR__.'/src/Symfony/{Bundle,Bridge,Component,Component/Security}/*', GLOB_BRACE | GLOB_ONLYDIR | GLOB_NOSORT) as $dir) {
|
$braces = array('Bundle', 'Bridge', 'Component', 'Component/Security');
|
||||||
|
$directories = call_user_func_array('array_merge', array_values(array_map(function ($part) {
|
||||||
|
return glob(__DIR__.'/src/Symfony/'.$part.'/*', GLOB_ONLYDIR | GLOB_NOSORT);
|
||||||
|
}, $braces)));
|
||||||
|
|
||||||
|
foreach ($directories as $dir) {
|
||||||
if ($filesystem->exists($composer = "$dir/composer.json")) {
|
if ($filesystem->exists($composer = "$dir/composer.json")) {
|
||||||
$sfPackages[json_decode(file_get_contents($composer))->name] = $dir;
|
$sfPackages[json_decode(file_get_contents($composer))->name] = $dir;
|
||||||
}
|
}
|
||||||
|
@ -214,41 +214,62 @@ class DeprecationErrorHandler
|
|||||||
return $b['count'] - $a['count'];
|
return $b['count'] - $a['count'];
|
||||||
};
|
};
|
||||||
|
|
||||||
$groups = array('unsilenced', 'remaining');
|
$displayDeprecations = function ($deprecations) use ($colorize, $cmp) {
|
||||||
if (DeprecationErrorHandler::MODE_WEAK_VENDORS === $mode) {
|
$groups = array('unsilenced', 'remaining');
|
||||||
$groups[] = 'remaining vendor';
|
if (DeprecationErrorHandler::MODE_WEAK_VENDORS === $mode) {
|
||||||
}
|
$groups[] = 'remaining vendor';
|
||||||
array_push($groups, 'legacy', 'other');
|
}
|
||||||
|
array_push($groups, 'legacy', 'other');
|
||||||
|
|
||||||
foreach ($groups as $group) {
|
foreach ($groups as $group) {
|
||||||
if ($deprecations[$group.'Count']) {
|
if ($deprecations[$group.'Count']) {
|
||||||
echo "\n", $colorize(
|
echo "\n", $colorize(
|
||||||
sprintf('%s deprecation notices (%d)', ucfirst($group), $deprecations[$group.'Count']),
|
sprintf('%s deprecation notices (%d)', ucfirst($group), $deprecations[$group.'Count']),
|
||||||
'legacy' !== $group && 'remaining vendor' !== $group
|
'legacy' !== $group && 'remaining vendor' !== $group
|
||||||
), "\n";
|
), "\n";
|
||||||
|
|
||||||
uasort($deprecations[$group], $cmp);
|
uasort($deprecations[$group], $cmp);
|
||||||
|
|
||||||
foreach ($deprecations[$group] as $msg => $notices) {
|
foreach ($deprecations[$group] as $msg => $notices) {
|
||||||
echo "\n ", $notices['count'], 'x: ', $msg, "\n";
|
echo "\n ", $notices['count'], 'x: ', $msg, "\n";
|
||||||
|
|
||||||
arsort($notices);
|
arsort($notices);
|
||||||
|
|
||||||
foreach ($notices as $method => $count) {
|
foreach ($notices as $method => $count) {
|
||||||
if ('count' !== $method) {
|
if ('count' !== $method) {
|
||||||
echo ' ', $count, 'x in ', preg_replace('/(.*)\\\\(.*?::.*?)$/', '$2 from $1', $method), "\n";
|
echo ' ', $count, 'x in ', preg_replace('/(.*)\\\\(.*?::.*?)$/', '$2 from $1', $method), "\n";
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
if (!empty($notices)) {
|
||||||
if (!empty($notices)) {
|
echo "\n";
|
||||||
echo "\n";
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
$displayDeprecations($deprecations);
|
||||||
|
|
||||||
|
// store failing status
|
||||||
|
$isFailing = DeprecationErrorHandler::MODE_WEAK !== $mode && $mode < $deprecations['unsilencedCount'] + $deprecations['remainingCount'] + $deprecations['otherCount'];
|
||||||
|
|
||||||
|
// reset deprecations array
|
||||||
|
foreach ($deprecations as $group => $arrayOrInt) {
|
||||||
|
$deprecations[$group] = is_int($arrayOrInt) ? 0 : array();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (DeprecationErrorHandler::MODE_WEAK !== $mode && $mode < $deprecations['unsilencedCount'] + $deprecations['remainingCount'] + $deprecations['otherCount']) {
|
register_shutdown_function(function () use (&$deprecations, $isFailing, $displayDeprecations, $mode) {
|
||||||
exit(1);
|
foreach ($deprecations as $group => $arrayOrInt) {
|
||||||
}
|
if (0 < (is_int($arrayOrInt) ? $arrayOrInt : count($arrayOrInt))) {
|
||||||
|
echo "Shutdown-time deprecations:\n";
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
$displayDeprecations($deprecations);
|
||||||
|
if ($isFailing || DeprecationErrorHandler::MODE_WEAK !== $mode && $mode < $deprecations['unsilencedCount'] + $deprecations['remainingCount'] + $deprecations['otherCount']) {
|
||||||
|
exit(1);
|
||||||
|
}
|
||||||
|
});
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -18,7 +18,7 @@ namespace Symfony\Bridge\PhpUnit\Legacy;
|
|||||||
*
|
*
|
||||||
* @internal
|
* @internal
|
||||||
*/
|
*/
|
||||||
class SymfonyTestsListener extends \PHPUnit_Framework_BaseTestListener
|
class SymfonyTestsListenerForV5 extends \PHPUnit_Framework_BaseTestListener
|
||||||
{
|
{
|
||||||
private $trait;
|
private $trait;
|
||||||
|
|
||||||
@ -34,26 +34,26 @@ class SymfonyTestsListener extends \PHPUnit_Framework_BaseTestListener
|
|||||||
|
|
||||||
public function startTestSuite(\PHPUnit_Framework_TestSuite $suite)
|
public function startTestSuite(\PHPUnit_Framework_TestSuite $suite)
|
||||||
{
|
{
|
||||||
return $this->trait->startTestSuite($suite);
|
$this->trait->startTestSuite($suite);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function addSkippedTest(\PHPUnit_Framework_Test $test, \Exception $e, $time)
|
public function addSkippedTest(\PHPUnit_Framework_Test $test, \Exception $e, $time)
|
||||||
{
|
{
|
||||||
return $this->trait->addSkippedTest($test, $e, $time);
|
$this->trait->addSkippedTest($test, $e, $time);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function startTest(\PHPUnit_Framework_Test $test)
|
public function startTest(\PHPUnit_Framework_Test $test)
|
||||||
{
|
{
|
||||||
return $this->trait->startTest($test);
|
$this->trait->startTest($test);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function addWarning(\PHPUnit_Framework_Test $test, \PHPUnit_Framework_Warning $e, $time)
|
public function addWarning(\PHPUnit_Framework_Test $test, \PHPUnit_Framework_Warning $e, $time)
|
||||||
{
|
{
|
||||||
return $this->trait->addWarning($test, $e, $time);
|
$this->trait->addWarning($test, $e, $time);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function endTest(\PHPUnit_Framework_Test $test, $time)
|
public function endTest(\PHPUnit_Framework_Test $test, $time)
|
||||||
{
|
{
|
||||||
return $this->trait->endTest($test, $time);
|
$this->trait->endTest($test, $time);
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -0,0 +1,64 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
/*
|
||||||
|
* This file is part of the Symfony package.
|
||||||
|
*
|
||||||
|
* (c) Fabien Potencier <fabien@symfony.com>
|
||||||
|
*
|
||||||
|
* For the full copyright and license information, please view the LICENSE
|
||||||
|
* file that was distributed with this source code.
|
||||||
|
*/
|
||||||
|
|
||||||
|
namespace Symfony\Bridge\PhpUnit\Legacy;
|
||||||
|
|
||||||
|
use PHPUnit\Framework\BaseTestListener;
|
||||||
|
use PHPUnit\Framework\Test;
|
||||||
|
use PHPUnit\Framework\TestSuite;
|
||||||
|
use PHPUnit\Framework\Warning;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Collects and replays skipped tests.
|
||||||
|
*
|
||||||
|
* @author Nicolas Grekas <p@tchwork.com>
|
||||||
|
*
|
||||||
|
* @internal
|
||||||
|
*/
|
||||||
|
class SymfonyTestsListenerForV6 extends BaseTestListener
|
||||||
|
{
|
||||||
|
private $trait;
|
||||||
|
|
||||||
|
public function __construct(array $mockedNamespaces = array())
|
||||||
|
{
|
||||||
|
$this->trait = new Legacy\SymfonyTestsListenerTrait($mockedNamespaces);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function globalListenerDisabled()
|
||||||
|
{
|
||||||
|
$this->trait->globalListenerDisabled();
|
||||||
|
}
|
||||||
|
|
||||||
|
public function startTestSuite(TestSuite $suite)
|
||||||
|
{
|
||||||
|
$this->trait->startTestSuite($suite);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function addSkippedTest(Test $test, \Exception $e, $time)
|
||||||
|
{
|
||||||
|
$this->trait->addSkippedTest($test, $e, $time);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function startTest(Test $test)
|
||||||
|
{
|
||||||
|
$this->trait->startTest($test);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function addWarning(Test $test, Warning $e, $time)
|
||||||
|
{
|
||||||
|
$this->trait->addWarning($test, $e, $time);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function endTest(Test $test, $time)
|
||||||
|
{
|
||||||
|
$this->trait->endTest($test, $time);
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,67 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
/*
|
||||||
|
* This file is part of the Symfony package.
|
||||||
|
*
|
||||||
|
* (c) Fabien Potencier <fabien@symfony.com>
|
||||||
|
*
|
||||||
|
* For the full copyright and license information, please view the LICENSE
|
||||||
|
* file that was distributed with this source code.
|
||||||
|
*/
|
||||||
|
|
||||||
|
namespace Symfony\Bridge\PhpUnit;
|
||||||
|
|
||||||
|
use PHPUnit\Framework\Test;
|
||||||
|
use PHPUnit\Framework\TestListener;
|
||||||
|
use PHPUnit\Framework\TestListenerDefaultImplementation;
|
||||||
|
use PHPUnit\Framework\TestSuite;
|
||||||
|
use PHPUnit\Framework\Warning;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Collects and replays skipped tests.
|
||||||
|
*
|
||||||
|
* @author Nicolas Grekas <p@tchwork.com>
|
||||||
|
*
|
||||||
|
* @internal
|
||||||
|
*/
|
||||||
|
class SymfonyTestsListenerForV7 implements TestListener
|
||||||
|
{
|
||||||
|
use TestListenerDefaultImplementation;
|
||||||
|
|
||||||
|
private $trait;
|
||||||
|
|
||||||
|
public function __construct(array $mockedNamespaces = array())
|
||||||
|
{
|
||||||
|
$this->trait = new SymfonyTestsListenerTrait($mockedNamespaces);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function globalListenerDisabled()
|
||||||
|
{
|
||||||
|
$this->trait->globalListenerDisabled();
|
||||||
|
}
|
||||||
|
|
||||||
|
public function startTestSuite(TestSuite $suite): void
|
||||||
|
{
|
||||||
|
$this->trait->startTestSuite($suite);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function addSkippedTest(Test $test, \Throwable $t, float $time): void
|
||||||
|
{
|
||||||
|
$this->trait->addSkippedTest($test, $t, $time);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function startTest(Test $test): void
|
||||||
|
{
|
||||||
|
$this->trait->startTest($test);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function addWarning(Test $test, Warning $e, float $time): void
|
||||||
|
{
|
||||||
|
$this->trait->addWarning($test, $e, $time);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function endTest(Test $test, float $time): void
|
||||||
|
{
|
||||||
|
$this->trait->endTest($test, $time);
|
||||||
|
}
|
||||||
|
}
|
@ -11,60 +11,10 @@
|
|||||||
|
|
||||||
namespace Symfony\Bridge\PhpUnit;
|
namespace Symfony\Bridge\PhpUnit;
|
||||||
|
|
||||||
use PHPUnit\Framework\BaseTestListener;
|
|
||||||
use PHPUnit\Framework\Test;
|
|
||||||
use PHPUnit\Framework\TestSuite;
|
|
||||||
use PHPUnit\Framework\Warning;
|
|
||||||
|
|
||||||
if (class_exists('PHPUnit_Runner_Version') && version_compare(\PHPUnit_Runner_Version::id(), '6.0.0', '<')) {
|
if (class_exists('PHPUnit_Runner_Version') && version_compare(\PHPUnit_Runner_Version::id(), '6.0.0', '<')) {
|
||||||
class_alias('Symfony\Bridge\PhpUnit\Legacy\SymfonyTestsListener', 'Symfony\Bridge\PhpUnit\SymfonyTestsListener');
|
class_alias('Symfony\Bridge\PhpUnit\Legacy\SymfonyTestsListenerForV5', 'Symfony\Bridge\PhpUnit\SymfonyTestsListener');
|
||||||
// Using an early return instead of a else does not work when using the PHPUnit phar due to some weird PHP behavior (the class
|
} elseif (version_compare(\PHPUnit\Runner\Version::id(), '7.0.0', '<')) {
|
||||||
// gets defined without executing the code before it and so the definition is not properly conditional)
|
class_alias('Symfony\Bridge\PhpUnit\Legacy\SymfonyTestsListenerForV6', 'Symfony\Bridge\PhpUnit\SymfonyTestsListener');
|
||||||
} else {
|
} else {
|
||||||
/**
|
class_alias('Symfony\Bridge\PhpUnit\Legacy\SymfonyTestsListenerForV7', 'Symfony\Bridge\PhpUnit\SymfonyTestsListener');
|
||||||
* Collects and replays skipped tests.
|
|
||||||
*
|
|
||||||
* @author Nicolas Grekas <p@tchwork.com>
|
|
||||||
*
|
|
||||||
* @final
|
|
||||||
*/
|
|
||||||
class SymfonyTestsListener extends BaseTestListener
|
|
||||||
{
|
|
||||||
private $trait;
|
|
||||||
|
|
||||||
public function __construct(array $mockedNamespaces = array())
|
|
||||||
{
|
|
||||||
$this->trait = new Legacy\SymfonyTestsListenerTrait($mockedNamespaces);
|
|
||||||
}
|
|
||||||
|
|
||||||
public function globalListenerDisabled()
|
|
||||||
{
|
|
||||||
$this->trait->globalListenerDisabled();
|
|
||||||
}
|
|
||||||
|
|
||||||
public function startTestSuite(TestSuite $suite)
|
|
||||||
{
|
|
||||||
return $this->trait->startTestSuite($suite);
|
|
||||||
}
|
|
||||||
|
|
||||||
public function addSkippedTest(Test $test, \Exception $e, $time)
|
|
||||||
{
|
|
||||||
return $this->trait->addSkippedTest($test, $e, $time);
|
|
||||||
}
|
|
||||||
|
|
||||||
public function startTest(Test $test)
|
|
||||||
{
|
|
||||||
return $this->trait->startTest($test);
|
|
||||||
}
|
|
||||||
|
|
||||||
public function addWarning(Test $test, Warning $e, $time)
|
|
||||||
{
|
|
||||||
return $this->trait->addWarning($test, $e, $time);
|
|
||||||
}
|
|
||||||
|
|
||||||
public function endTest(Test $test, $time)
|
|
||||||
{
|
|
||||||
return $this->trait->endTest($test, $time);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@ -59,6 +59,10 @@ $foo = new FooTestCase();
|
|||||||
$foo->testLegacyFoo();
|
$foo->testLegacyFoo();
|
||||||
$foo->testNonLegacyBar();
|
$foo->testNonLegacyBar();
|
||||||
|
|
||||||
|
register_shutdown_function(function () {
|
||||||
|
exit('I get precedence over any exit statements inside the deprecation error handler.');
|
||||||
|
});
|
||||||
|
|
||||||
?>
|
?>
|
||||||
--EXPECTF--
|
--EXPECTF--
|
||||||
Unsilenced deprecation notices (3)
|
Unsilenced deprecation notices (3)
|
||||||
@ -80,3 +84,4 @@ Other deprecation notices (1)
|
|||||||
|
|
||||||
1x: root deprecation
|
1x: root deprecation
|
||||||
|
|
||||||
|
I get precedence over any exit statements inside the deprecation error handler.
|
||||||
|
@ -0,0 +1,91 @@
|
|||||||
|
--TEST--
|
||||||
|
Test DeprecationErrorHandler in default mode
|
||||||
|
--FILE--
|
||||||
|
<?php
|
||||||
|
|
||||||
|
putenv('SYMFONY_DEPRECATIONS_HELPER');
|
||||||
|
putenv('ANSICON');
|
||||||
|
putenv('ConEmuANSI');
|
||||||
|
putenv('TERM');
|
||||||
|
|
||||||
|
$vendor = __DIR__;
|
||||||
|
while (!file_exists($vendor.'/vendor')) {
|
||||||
|
$vendor = dirname($vendor);
|
||||||
|
}
|
||||||
|
define('PHPUNIT_COMPOSER_INSTALL', $vendor.'/vendor/autoload.php');
|
||||||
|
require PHPUNIT_COMPOSER_INSTALL;
|
||||||
|
require_once __DIR__.'/../../bootstrap.php';
|
||||||
|
|
||||||
|
@trigger_error('root deprecation', E_USER_DEPRECATED);
|
||||||
|
|
||||||
|
eval(<<<'EOPHP'
|
||||||
|
namespace PHPUnit\Util;
|
||||||
|
|
||||||
|
class Test
|
||||||
|
{
|
||||||
|
public static function getGroups()
|
||||||
|
{
|
||||||
|
return array();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
EOPHP
|
||||||
|
);
|
||||||
|
|
||||||
|
class PHPUnit_Util_Test
|
||||||
|
{
|
||||||
|
public static function getGroups()
|
||||||
|
{
|
||||||
|
return array();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
class FooTestCase
|
||||||
|
{
|
||||||
|
public function testLegacyFoo()
|
||||||
|
{
|
||||||
|
@trigger_error('silenced foo deprecation', E_USER_DEPRECATED);
|
||||||
|
trigger_error('unsilenced foo deprecation', E_USER_DEPRECATED);
|
||||||
|
trigger_error('unsilenced foo deprecation', E_USER_DEPRECATED);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testNonLegacyBar()
|
||||||
|
{
|
||||||
|
@trigger_error('silenced bar deprecation', E_USER_DEPRECATED);
|
||||||
|
trigger_error('unsilenced bar deprecation', E_USER_DEPRECATED);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
$foo = new FooTestCase();
|
||||||
|
$foo->testLegacyFoo();
|
||||||
|
$foo->testNonLegacyBar();
|
||||||
|
|
||||||
|
register_shutdown_function(function () {
|
||||||
|
@trigger_error('root deprecation during shutdown', E_USER_DEPRECATED);
|
||||||
|
});
|
||||||
|
|
||||||
|
?>
|
||||||
|
--EXPECTF--
|
||||||
|
Unsilenced deprecation notices (3)
|
||||||
|
|
||||||
|
2x: unsilenced foo deprecation
|
||||||
|
2x in FooTestCase::testLegacyFoo
|
||||||
|
|
||||||
|
1x: unsilenced bar deprecation
|
||||||
|
1x in FooTestCase::testNonLegacyBar
|
||||||
|
|
||||||
|
Remaining deprecation notices (1)
|
||||||
|
|
||||||
|
1x: silenced bar deprecation
|
||||||
|
1x in FooTestCase::testNonLegacyBar
|
||||||
|
|
||||||
|
Legacy deprecation notices (1)
|
||||||
|
|
||||||
|
Other deprecation notices (1)
|
||||||
|
|
||||||
|
1x: root deprecation
|
||||||
|
|
||||||
|
Shutdown-time deprecations:
|
||||||
|
|
||||||
|
Other deprecation notices (1)
|
||||||
|
|
||||||
|
1x: root deprecation during shutdown
|
@ -17,7 +17,7 @@ error_reporting(-1);
|
|||||||
|
|
||||||
if (PHP_VERSION_ID >= 70200) {
|
if (PHP_VERSION_ID >= 70200) {
|
||||||
// PHPUnit 6 is required for PHP 7.2+
|
// PHPUnit 6 is required for PHP 7.2+
|
||||||
$PHPUNIT_VERSION = getenv('SYMFONY_PHPUNIT_VERSION') ?: '6.3';
|
$PHPUNIT_VERSION = getenv('SYMFONY_PHPUNIT_VERSION') ?: '6.5';
|
||||||
} elseif (PHP_VERSION_ID >= 50600) {
|
} elseif (PHP_VERSION_ID >= 50600) {
|
||||||
// PHPUnit 4 does not support PHP 7
|
// PHPUnit 4 does not support PHP 7
|
||||||
$PHPUNIT_VERSION = getenv('SYMFONY_PHPUNIT_VERSION') ?: '5.7';
|
$PHPUNIT_VERSION = getenv('SYMFONY_PHPUNIT_VERSION') ?: '5.7';
|
||||||
|
@ -370,12 +370,12 @@ trait ControllerTrait
|
|||||||
/**
|
/**
|
||||||
* Checks the validity of a CSRF token.
|
* Checks the validity of a CSRF token.
|
||||||
*
|
*
|
||||||
* @param string $id The id used when generating the token
|
* @param string $id The id used when generating the token
|
||||||
* @param string $token The actual token sent with the request that should be validated
|
* @param string|null $token The actual token sent with the request that should be validated
|
||||||
*
|
*
|
||||||
* @final since version 3.4
|
* @final since version 3.4
|
||||||
*/
|
*/
|
||||||
protected function isCsrfTokenValid(string $id, string $token): bool
|
protected function isCsrfTokenValid(string $id, ?string $token): bool
|
||||||
{
|
{
|
||||||
if (!$this->container->has('security.csrf.token_manager')) {
|
if (!$this->container->has('security.csrf.token_manager')) {
|
||||||
throw new \LogicException('CSRF protection is not enabled in your application. Enable it with the "csrf_protection" key in "config/packages/framework.yaml".');
|
throw new \LogicException('CSRF protection is not enabled in your application. Enable it with the "csrf_protection" key in "config/packages/framework.yaml".');
|
||||||
|
@ -12,18 +12,11 @@
|
|||||||
namespace Symfony\Bundle\FrameworkBundle\Tests\DependencyInjection\Compiler;
|
namespace Symfony\Bundle\FrameworkBundle\Tests\DependencyInjection\Compiler;
|
||||||
|
|
||||||
use PHPUnit\Framework\TestCase;
|
use PHPUnit\Framework\TestCase;
|
||||||
use Symfony\Component\DependencyInjection\Definition;
|
use Symfony\Component\DependencyInjection\ContainerBuilder;
|
||||||
use Symfony\Bundle\FrameworkBundle\DependencyInjection\Compiler\ProfilerPass;
|
use Symfony\Bundle\FrameworkBundle\DependencyInjection\Compiler\ProfilerPass;
|
||||||
|
|
||||||
class ProfilerPassTest extends TestCase
|
class ProfilerPassTest extends TestCase
|
||||||
{
|
{
|
||||||
private $profilerDefinition;
|
|
||||||
|
|
||||||
protected function setUp()
|
|
||||||
{
|
|
||||||
$this->profilerDefinition = new Definition('ProfilerClass');
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Tests that collectors that specify a template but no "id" will throw
|
* Tests that collectors that specify a template but no "id" will throw
|
||||||
* an exception (both are needed if the template is specified).
|
* an exception (both are needed if the template is specified).
|
||||||
@ -31,17 +24,15 @@ class ProfilerPassTest extends TestCase
|
|||||||
* Thus, a fully-valid tag looks something like this:
|
* Thus, a fully-valid tag looks something like this:
|
||||||
*
|
*
|
||||||
* <tag name="data_collector" template="YourBundle:Collector:templatename" id="your_collector_name" />
|
* <tag name="data_collector" template="YourBundle:Collector:templatename" id="your_collector_name" />
|
||||||
|
*
|
||||||
|
* @expectedException \InvalidArgumentException
|
||||||
*/
|
*/
|
||||||
public function testTemplateNoIdThrowsException()
|
public function testTemplateNoIdThrowsException()
|
||||||
{
|
{
|
||||||
// one service, with a template key, but no id
|
$builder = new ContainerBuilder();
|
||||||
$services = array(
|
$builder->register('profiler', 'ProfilerClass');
|
||||||
'my_collector_service' => array(0 => array('template' => 'foo')),
|
$builder->register('my_collector_service')
|
||||||
);
|
->addTag('data_collector', array('template' => 'foo'));
|
||||||
|
|
||||||
$builder = $this->createContainerMock($services);
|
|
||||||
|
|
||||||
$this->{method_exists($this, $_ = 'expectException') ? $_ : 'setExpectedException'}('InvalidArgumentException');
|
|
||||||
|
|
||||||
$profilerPass = new ProfilerPass();
|
$profilerPass = new ProfilerPass();
|
||||||
$profilerPass->process($builder);
|
$profilerPass->process($builder);
|
||||||
@ -49,45 +40,19 @@ class ProfilerPassTest extends TestCase
|
|||||||
|
|
||||||
public function testValidCollector()
|
public function testValidCollector()
|
||||||
{
|
{
|
||||||
// one service, with a template key, but no id
|
$container = new ContainerBuilder();
|
||||||
$services = array(
|
$profilerDefinition = $container->register('profiler', 'ProfilerClass');
|
||||||
'my_collector_service' => array(0 => array('template' => 'foo', 'id' => 'my_collector')),
|
$container->register('my_collector_service')
|
||||||
);
|
->addTag('data_collector', array('template' => 'foo', 'id' => 'my_collector'));
|
||||||
|
|
||||||
$container = $this->createContainerMock($services);
|
|
||||||
|
|
||||||
// fake the getDefinition() to return a Profiler definition
|
|
||||||
$container->expects($this->atLeastOnce())
|
|
||||||
->method('getDefinition');
|
|
||||||
|
|
||||||
// assert that the data_collector.templates parameter should be set
|
|
||||||
$container->expects($this->once())
|
|
||||||
->method('setParameter')
|
|
||||||
->with('data_collector.templates', array('my_collector_service' => array('my_collector', 'foo')));
|
|
||||||
|
|
||||||
$profilerPass = new ProfilerPass();
|
$profilerPass = new ProfilerPass();
|
||||||
$profilerPass->process($container);
|
$profilerPass->process($container);
|
||||||
|
|
||||||
|
$this->assertSame(array('my_collector_service' => array('my_collector', 'foo')), $container->getParameter('data_collector.templates'));
|
||||||
|
|
||||||
// grab the method calls off of the "profiler" definition
|
// grab the method calls off of the "profiler" definition
|
||||||
$methodCalls = $this->profilerDefinition->getMethodCalls();
|
$methodCalls = $profilerDefinition->getMethodCalls();
|
||||||
$this->assertCount(1, $methodCalls);
|
$this->assertCount(1, $methodCalls);
|
||||||
$this->assertEquals('add', $methodCalls[0][0]); // grab the method part of the first call
|
$this->assertEquals('add', $methodCalls[0][0]); // grab the method part of the first call
|
||||||
}
|
}
|
||||||
|
|
||||||
private function createContainerMock($services)
|
|
||||||
{
|
|
||||||
$container = $this->getMockBuilder('Symfony\Component\DependencyInjection\ContainerBuilder')->setMethods(array('hasDefinition', 'getDefinition', 'findTaggedServiceIds', 'setParameter'))->getMock();
|
|
||||||
$container->expects($this->any())
|
|
||||||
->method('hasDefinition')
|
|
||||||
->with($this->equalTo('profiler'))
|
|
||||||
->will($this->returnValue(true));
|
|
||||||
$container->expects($this->any())
|
|
||||||
->method('getDefinition')
|
|
||||||
->will($this->returnValue($this->profilerDefinition));
|
|
||||||
$container->expects($this->atLeastOnce())
|
|
||||||
->method('findTaggedServiceIds')
|
|
||||||
->will($this->returnValue($services));
|
|
||||||
|
|
||||||
return $container;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@ -13,13 +13,14 @@ namespace Symfony\Bundle\TwigBundle\Tests\DependencyInjection\Compiler;
|
|||||||
|
|
||||||
use PHPUnit\Framework\TestCase;
|
use PHPUnit\Framework\TestCase;
|
||||||
use Symfony\Component\DependencyInjection\Alias;
|
use Symfony\Component\DependencyInjection\Alias;
|
||||||
|
use Symfony\Component\DependencyInjection\ContainerBuilder;
|
||||||
use Symfony\Component\DependencyInjection\Definition;
|
use Symfony\Component\DependencyInjection\Definition;
|
||||||
use Symfony\Bundle\TwigBundle\DependencyInjection\Compiler\TwigLoaderPass;
|
use Symfony\Bundle\TwigBundle\DependencyInjection\Compiler\TwigLoaderPass;
|
||||||
|
|
||||||
class TwigLoaderPassTest extends TestCase
|
class TwigLoaderPassTest extends TestCase
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
* @var \PHPUnit_Framework_MockObject_MockObject
|
* @var ContainerBuilder
|
||||||
*/
|
*/
|
||||||
private $builder;
|
private $builder;
|
||||||
/**
|
/**
|
||||||
@ -33,64 +34,33 @@ class TwigLoaderPassTest extends TestCase
|
|||||||
|
|
||||||
protected function setUp()
|
protected function setUp()
|
||||||
{
|
{
|
||||||
$this->builder = $this->getMockBuilder('Symfony\Component\DependencyInjection\ContainerBuilder')->setMethods(array('hasDefinition', 'findTaggedServiceIds', 'setAlias', 'getDefinition'))->getMock();
|
$this->builder = new ContainerBuilder();
|
||||||
|
$this->builder->register('twig');
|
||||||
$this->chainLoader = new Definition('loader');
|
$this->chainLoader = new Definition('loader');
|
||||||
$this->pass = new TwigLoaderPass();
|
$this->pass = new TwigLoaderPass();
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testMapperPassWithOneTaggedLoaders()
|
public function testMapperPassWithOneTaggedLoader()
|
||||||
{
|
{
|
||||||
$serviceIds = array(
|
$this->builder->register('test_loader_1')
|
||||||
'test_loader_1' => array(
|
->addTag('twig.loader');
|
||||||
array(),
|
|
||||||
),
|
|
||||||
);
|
|
||||||
|
|
||||||
$this->builder->expects($this->once())
|
|
||||||
->method('hasDefinition')
|
|
||||||
->with('twig')
|
|
||||||
->will($this->returnValue(true));
|
|
||||||
$this->builder->expects($this->once())
|
|
||||||
->method('findTaggedServiceIds')
|
|
||||||
->with('twig.loader')
|
|
||||||
->will($this->returnValue($serviceIds));
|
|
||||||
$this->builder->expects($this->once())
|
|
||||||
->method('setAlias')
|
|
||||||
->with('twig.loader', 'test_loader_1')
|
|
||||||
->will($this->returnValue(new Alias('test_loader_1')));
|
|
||||||
|
|
||||||
$this->pass->process($this->builder);
|
$this->pass->process($this->builder);
|
||||||
|
|
||||||
|
$this->assertSame('test_loader_1', (string) $this->builder->getAlias('twig.loader'));
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testMapperPassWithTwoTaggedLoaders()
|
public function testMapperPassWithTwoTaggedLoaders()
|
||||||
{
|
{
|
||||||
$serviceIds = array(
|
$this->builder->setDefinition('twig.loader.chain', $this->chainLoader);
|
||||||
'test_loader_1' => array(
|
$this->builder->register('test_loader_1')
|
||||||
array(),
|
->addTag('twig.loader');
|
||||||
),
|
$this->builder->register('test_loader_2')
|
||||||
'test_loader_2' => array(
|
->addTag('twig.loader');
|
||||||
array(),
|
|
||||||
),
|
|
||||||
);
|
|
||||||
|
|
||||||
$this->builder->expects($this->once())
|
|
||||||
->method('hasDefinition')
|
|
||||||
->with('twig')
|
|
||||||
->will($this->returnValue(true));
|
|
||||||
$this->builder->expects($this->once())
|
|
||||||
->method('findTaggedServiceIds')
|
|
||||||
->with('twig.loader')
|
|
||||||
->will($this->returnValue($serviceIds));
|
|
||||||
$this->builder->expects($this->once())
|
|
||||||
->method('getDefinition')
|
|
||||||
->with('twig.loader.chain')
|
|
||||||
->will($this->returnValue($this->chainLoader));
|
|
||||||
$this->builder->expects($this->once())
|
|
||||||
->method('setAlias')
|
|
||||||
->with('twig.loader', 'twig.loader.chain')
|
|
||||||
->will($this->returnValue(new Alias('twig.loader.chain')));
|
|
||||||
|
|
||||||
$this->pass->process($this->builder);
|
$this->pass->process($this->builder);
|
||||||
|
|
||||||
|
$this->assertSame('twig.loader.chain', (string) $this->builder->getAlias('twig.loader'));
|
||||||
$calls = $this->chainLoader->getMethodCalls();
|
$calls = $this->chainLoader->getMethodCalls();
|
||||||
$this->assertCount(2, $calls);
|
$this->assertCount(2, $calls);
|
||||||
$this->assertEquals('addLoader', $calls[0][0]);
|
$this->assertEquals('addLoader', $calls[0][0]);
|
||||||
@ -101,33 +71,15 @@ class TwigLoaderPassTest extends TestCase
|
|||||||
|
|
||||||
public function testMapperPassWithTwoTaggedLoadersWithPriority()
|
public function testMapperPassWithTwoTaggedLoadersWithPriority()
|
||||||
{
|
{
|
||||||
$serviceIds = array(
|
$this->builder->setDefinition('twig.loader.chain', $this->chainLoader);
|
||||||
'test_loader_1' => array(
|
$this->builder->register('test_loader_1')
|
||||||
array('priority' => 100),
|
->addTag('twig.loader', array('priority' => 100));
|
||||||
),
|
$this->builder->register('test_loader_2')
|
||||||
'test_loader_2' => array(
|
->addTag('twig.loader', array('priority' => 200));
|
||||||
array('priority' => 200),
|
|
||||||
),
|
|
||||||
);
|
|
||||||
|
|
||||||
$this->builder->expects($this->once())
|
|
||||||
->method('hasDefinition')
|
|
||||||
->with('twig')
|
|
||||||
->will($this->returnValue(true));
|
|
||||||
$this->builder->expects($this->once())
|
|
||||||
->method('findTaggedServiceIds')
|
|
||||||
->with('twig.loader')
|
|
||||||
->will($this->returnValue($serviceIds));
|
|
||||||
$this->builder->expects($this->once())
|
|
||||||
->method('getDefinition')
|
|
||||||
->with('twig.loader.chain')
|
|
||||||
->will($this->returnValue($this->chainLoader));
|
|
||||||
$this->builder->expects($this->once())
|
|
||||||
->method('setAlias')
|
|
||||||
->with('twig.loader', 'twig.loader.chain')
|
|
||||||
->will($this->returnValue(new Alias('twig.loader.chain')));
|
|
||||||
|
|
||||||
$this->pass->process($this->builder);
|
$this->pass->process($this->builder);
|
||||||
|
|
||||||
|
$this->assertSame('twig.loader.chain', (string) $this->builder->getAlias('twig.loader'));
|
||||||
$calls = $this->chainLoader->getMethodCalls();
|
$calls = $this->chainLoader->getMethodCalls();
|
||||||
$this->assertCount(2, $calls);
|
$this->assertCount(2, $calls);
|
||||||
$this->assertEquals('addLoader', $calls[0][0]);
|
$this->assertEquals('addLoader', $calls[0][0]);
|
||||||
@ -141,15 +93,6 @@ class TwigLoaderPassTest extends TestCase
|
|||||||
*/
|
*/
|
||||||
public function testMapperPassWithZeroTaggedLoaders()
|
public function testMapperPassWithZeroTaggedLoaders()
|
||||||
{
|
{
|
||||||
$this->builder->expects($this->once())
|
|
||||||
->method('hasDefinition')
|
|
||||||
->with('twig')
|
|
||||||
->will($this->returnValue(true));
|
|
||||||
$this->builder->expects($this->once())
|
|
||||||
->method('findTaggedServiceIds')
|
|
||||||
->with('twig.loader')
|
|
||||||
->will($this->returnValue(array()));
|
|
||||||
|
|
||||||
$this->pass->process($this->builder);
|
$this->pass->process($this->builder);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -204,11 +204,12 @@ class TraceableAdapter implements AdapterInterface, PruneableInterface, Resettab
|
|||||||
|
|
||||||
public function getCalls()
|
public function getCalls()
|
||||||
{
|
{
|
||||||
try {
|
return $this->calls;
|
||||||
return $this->calls;
|
}
|
||||||
} finally {
|
|
||||||
$this->calls = array();
|
public function clearCalls()
|
||||||
}
|
{
|
||||||
|
$this->calls = array();
|
||||||
}
|
}
|
||||||
|
|
||||||
protected function start($name)
|
protected function start($name)
|
||||||
|
@ -57,8 +57,7 @@ class CacheDataCollector extends DataCollector implements LateDataCollectorInter
|
|||||||
{
|
{
|
||||||
$this->data = array();
|
$this->data = array();
|
||||||
foreach ($this->instances as $instance) {
|
foreach ($this->instances as $instance) {
|
||||||
// Calling getCalls() will clear the calls.
|
$instance->clearCalls();
|
||||||
$instance->getCalls();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -36,9 +36,9 @@ trait FilesystemTrait
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($time >= (int) $expiresAt = fgets($h)) {
|
if (($expiresAt = (int) fgets($h)) && $time >= $expiresAt) {
|
||||||
fclose($h);
|
fclose($h);
|
||||||
$pruned = isset($expiresAt[0]) && @unlink($file) && !file_exists($file) && $pruned;
|
$pruned = @unlink($file) && !file_exists($file) && $pruned;
|
||||||
} else {
|
} else {
|
||||||
fclose($h);
|
fclose($h);
|
||||||
}
|
}
|
||||||
@ -60,11 +60,9 @@ trait FilesystemTrait
|
|||||||
if (!file_exists($file) || !$h = @fopen($file, 'rb')) {
|
if (!file_exists($file) || !$h = @fopen($file, 'rb')) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
if ($now >= (int) $expiresAt = fgets($h)) {
|
if (($expiresAt = (int) fgets($h)) && $now >= $expiresAt) {
|
||||||
fclose($h);
|
fclose($h);
|
||||||
if (isset($expiresAt[0])) {
|
@unlink($file);
|
||||||
@unlink($file);
|
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
$i = rawurldecode(rtrim(fgets($h)));
|
$i = rawurldecode(rtrim(fgets($h)));
|
||||||
$value = stream_get_contents($h);
|
$value = stream_get_contents($h);
|
||||||
@ -94,7 +92,7 @@ trait FilesystemTrait
|
|||||||
protected function doSave(array $values, $lifetime)
|
protected function doSave(array $values, $lifetime)
|
||||||
{
|
{
|
||||||
$ok = true;
|
$ok = true;
|
||||||
$expiresAt = time() + ($lifetime ?: 31557600); // 31557600s = 1 year
|
$expiresAt = $lifetime ? (time() + $lifetime) : 0;
|
||||||
|
|
||||||
foreach ($values as $id => $value) {
|
foreach ($values as $id => $value) {
|
||||||
$ok = $this->write($this->getFile($id, true), $expiresAt."\n".rawurlencode($id)."\n".serialize($value), $expiresAt) && $ok;
|
$ok = $this->write($this->getFile($id, true), $expiresAt."\n".rawurlencode($id)."\n".serialize($value), $expiresAt) && $ok;
|
||||||
|
@ -120,6 +120,7 @@ class PhpDumper extends Dumper
|
|||||||
'debug' => true,
|
'debug' => true,
|
||||||
'hot_path_tag' => 'container.hot_path',
|
'hot_path_tag' => 'container.hot_path',
|
||||||
'inline_class_loader_parameter' => 'container.dumper.inline_class_loader',
|
'inline_class_loader_parameter' => 'container.dumper.inline_class_loader',
|
||||||
|
'build_time' => time(),
|
||||||
), $options);
|
), $options);
|
||||||
|
|
||||||
$this->namespace = $options['namespace'];
|
$this->namespace = $options['namespace'];
|
||||||
@ -223,7 +224,7 @@ EOF;
|
|||||||
array_pop($code);
|
array_pop($code);
|
||||||
$code["Container{$hash}/{$options['class']}.php"] = substr_replace($files[$options['class'].'.php'], "<?php\n\nnamespace Container{$hash};\n", 0, 6);
|
$code["Container{$hash}/{$options['class']}.php"] = substr_replace($files[$options['class'].'.php'], "<?php\n\nnamespace Container{$hash};\n", 0, 6);
|
||||||
$namespaceLine = $this->namespace ? "\nnamespace {$this->namespace};\n" : '';
|
$namespaceLine = $this->namespace ? "\nnamespace {$this->namespace};\n" : '';
|
||||||
$time = time();
|
$time = $options['build_time'];
|
||||||
$id = hash('crc32', $hash.$time);
|
$id = hash('crc32', $hash.$time);
|
||||||
|
|
||||||
$code[$options['class'].'.php'] = <<<EOF
|
$code[$options['class'].'.php'] = <<<EOF
|
||||||
|
@ -12,6 +12,8 @@
|
|||||||
namespace Symfony\Component\DependencyInjection\Tests\Extension;
|
namespace Symfony\Component\DependencyInjection\Tests\Extension;
|
||||||
|
|
||||||
use PHPUnit\Framework\TestCase;
|
use PHPUnit\Framework\TestCase;
|
||||||
|
use Symfony\Component\DependencyInjection\ContainerBuilder;
|
||||||
|
use Symfony\Component\DependencyInjection\Extension\Extension;
|
||||||
|
|
||||||
class ExtensionTest extends TestCase
|
class ExtensionTest extends TestCase
|
||||||
{
|
{
|
||||||
@ -20,36 +22,8 @@ class ExtensionTest extends TestCase
|
|||||||
*/
|
*/
|
||||||
public function testIsConfigEnabledReturnsTheResolvedValue($enabled)
|
public function testIsConfigEnabledReturnsTheResolvedValue($enabled)
|
||||||
{
|
{
|
||||||
$pb = $this->getMockBuilder('Symfony\Component\DependencyInjection\ParameterBag\ParameterBag')
|
$extension = new EnableableExtension();
|
||||||
->setMethods(array('resolveValue'))
|
$this->assertSame($enabled, $extension->isConfigEnabled(new ContainerBuilder(), array('enabled' => $enabled)));
|
||||||
->getMock()
|
|
||||||
;
|
|
||||||
|
|
||||||
$container = $this->getMockBuilder('Symfony\Component\DependencyInjection\ContainerBuilder')
|
|
||||||
->setMethods(array('getParameterBag'))
|
|
||||||
->getMock()
|
|
||||||
;
|
|
||||||
|
|
||||||
$pb->expects($this->once())
|
|
||||||
->method('resolveValue')
|
|
||||||
->with($this->equalTo($enabled))
|
|
||||||
->will($this->returnValue($enabled))
|
|
||||||
;
|
|
||||||
|
|
||||||
$container->expects($this->once())
|
|
||||||
->method('getParameterBag')
|
|
||||||
->will($this->returnValue($pb))
|
|
||||||
;
|
|
||||||
|
|
||||||
$extension = $this->getMockBuilder('Symfony\Component\DependencyInjection\Extension\Extension')
|
|
||||||
->setMethods(array())
|
|
||||||
->getMockForAbstractClass()
|
|
||||||
;
|
|
||||||
|
|
||||||
$r = new \ReflectionMethod('Symfony\Component\DependencyInjection\Extension\Extension', 'isConfigEnabled');
|
|
||||||
$r->setAccessible(true);
|
|
||||||
|
|
||||||
$r->invoke($extension, $container, array('enabled' => $enabled));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getResolvedEnabledFixtures()
|
public function getResolvedEnabledFixtures()
|
||||||
@ -66,18 +40,20 @@ class ExtensionTest extends TestCase
|
|||||||
*/
|
*/
|
||||||
public function testIsConfigEnabledOnNonEnableableConfig()
|
public function testIsConfigEnabledOnNonEnableableConfig()
|
||||||
{
|
{
|
||||||
$container = $this->getMockBuilder('Symfony\Component\DependencyInjection\ContainerBuilder')
|
$extension = new EnableableExtension();
|
||||||
->getMock()
|
|
||||||
;
|
|
||||||
|
|
||||||
$extension = $this->getMockBuilder('Symfony\Component\DependencyInjection\Extension\Extension')
|
$extension->isConfigEnabled(new ContainerBuilder(), array());
|
||||||
->setMethods(array())
|
}
|
||||||
->getMockForAbstractClass()
|
}
|
||||||
;
|
|
||||||
|
class EnableableExtension extends Extension
|
||||||
$r = new \ReflectionMethod('Symfony\Component\DependencyInjection\Extension\Extension', 'isConfigEnabled');
|
{
|
||||||
$r->setAccessible(true);
|
public function load(array $configs, ContainerBuilder $container)
|
||||||
|
{
|
||||||
$r->invoke($extension, $container, array());
|
}
|
||||||
|
|
||||||
|
public function isConfigEnabled(ContainerBuilder $container, array $config)
|
||||||
|
{
|
||||||
|
return parent::isConfigEnabled($container, $config);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -313,6 +313,8 @@ class Finder implements \IteratorAggregate, \Countable
|
|||||||
/**
|
/**
|
||||||
* Excludes "hidden" directories and files (starting with a dot).
|
* Excludes "hidden" directories and files (starting with a dot).
|
||||||
*
|
*
|
||||||
|
* This option is enabled by default.
|
||||||
|
*
|
||||||
* @param bool $ignoreDotFiles Whether to exclude "hidden" files or not
|
* @param bool $ignoreDotFiles Whether to exclude "hidden" files or not
|
||||||
*
|
*
|
||||||
* @return $this
|
* @return $this
|
||||||
@ -333,6 +335,8 @@ class Finder implements \IteratorAggregate, \Countable
|
|||||||
/**
|
/**
|
||||||
* Forces the finder to ignore version control directories.
|
* Forces the finder to ignore version control directories.
|
||||||
*
|
*
|
||||||
|
* This option is enabled by default.
|
||||||
|
*
|
||||||
* @param bool $ignoreVCS Whether to exclude VCS files or not
|
* @param bool $ignoreVCS Whether to exclude VCS files or not
|
||||||
*
|
*
|
||||||
* @return $this
|
* @return $this
|
||||||
|
@ -22,6 +22,7 @@ use Symfony\Component\DependencyInjection\Exception\InvalidArgumentException;
|
|||||||
use Symfony\Component\DependencyInjection\LazyProxy\ProxyHelper;
|
use Symfony\Component\DependencyInjection\LazyProxy\ProxyHelper;
|
||||||
use Symfony\Component\DependencyInjection\Reference;
|
use Symfony\Component\DependencyInjection\Reference;
|
||||||
use Symfony\Component\DependencyInjection\TypedReference;
|
use Symfony\Component\DependencyInjection\TypedReference;
|
||||||
|
use Symfony\Component\HttpFoundation\Request;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates the service-locators required by ServiceValueResolver.
|
* Creates the service-locators required by ServiceValueResolver.
|
||||||
@ -148,6 +149,10 @@ class RegisterControllerArgumentLocatorsPass implements CompilerPassInterface
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (Request::class === $type) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
if ($type && !$p->isOptional() && !$p->allowsNull() && !class_exists($type) && !interface_exists($type, false)) {
|
if ($type && !$p->isOptional() && !$p->allowsNull() && !class_exists($type) && !interface_exists($type, false)) {
|
||||||
$message = sprintf('Cannot determine controller argument for "%s::%s()": the $%s argument is type-hinted with the non-existent class or interface: "%s".', $class, $r->name, $p->name, $type);
|
$message = sprintf('Cannot determine controller argument for "%s::%s()": the $%s argument is type-hinted with the non-existent class or interface: "%s".', $class, $r->name, $p->name, $type);
|
||||||
|
|
||||||
|
@ -693,6 +693,7 @@ abstract class Kernel implements KernelInterface, RebootableInterface, Terminabl
|
|||||||
'file' => $cache->getPath(),
|
'file' => $cache->getPath(),
|
||||||
'as_files' => true,
|
'as_files' => true,
|
||||||
'debug' => $this->debug,
|
'debug' => $this->debug,
|
||||||
|
'build_time' => $container->hasParameter('kernel.container_build_time') ? $container->getParameter('kernel.container_build_time') : time(),
|
||||||
));
|
));
|
||||||
|
|
||||||
$rootCode = array_pop($content);
|
$rootCode = array_pop($content);
|
||||||
|
@ -12,44 +12,39 @@
|
|||||||
namespace Symfony\Component\HttpKernel\Tests\DependencyInjection;
|
namespace Symfony\Component\HttpKernel\Tests\DependencyInjection;
|
||||||
|
|
||||||
use PHPUnit\Framework\TestCase;
|
use PHPUnit\Framework\TestCase;
|
||||||
|
use Symfony\Component\DependencyInjection\ContainerBuilder;
|
||||||
|
use Symfony\Component\HttpKernel\DependencyInjection\Extension;
|
||||||
use Symfony\Component\HttpKernel\DependencyInjection\MergeExtensionConfigurationPass;
|
use Symfony\Component\HttpKernel\DependencyInjection\MergeExtensionConfigurationPass;
|
||||||
|
|
||||||
class MergeExtensionConfigurationPassTest extends TestCase
|
class MergeExtensionConfigurationPassTest extends TestCase
|
||||||
{
|
{
|
||||||
public function testAutoloadMainExtension()
|
public function testAutoloadMainExtension()
|
||||||
{
|
{
|
||||||
$container = $this->getMockBuilder('Symfony\\Component\\DependencyInjection\\ContainerBuilder')->setMethods(array('getExtensionConfig', 'loadFromExtension', 'getParameterBag', 'getDefinitions', 'getAliases', 'getExtensions'))->getMock();
|
$container = new ContainerBuilder();
|
||||||
$params = $this->getMockBuilder('Symfony\\Component\\DependencyInjection\\ParameterBag\\ParameterBag')->getMock();
|
$container->registerExtension(new LoadedExtension());
|
||||||
|
$container->registerExtension(new NotLoadedExtension());
|
||||||
|
$container->loadFromExtension('loaded', array());
|
||||||
|
|
||||||
$container->expects($this->at(0))
|
$configPass = new MergeExtensionConfigurationPass(array('loaded', 'not_loaded'));
|
||||||
->method('getExtensionConfig')
|
|
||||||
->with('loaded')
|
|
||||||
->will($this->returnValue(array(array())));
|
|
||||||
$container->expects($this->at(1))
|
|
||||||
->method('getExtensionConfig')
|
|
||||||
->with('notloaded')
|
|
||||||
->will($this->returnValue(array()));
|
|
||||||
$container->expects($this->once())
|
|
||||||
->method('loadFromExtension')
|
|
||||||
->with('notloaded', array());
|
|
||||||
|
|
||||||
$container->expects($this->any())
|
|
||||||
->method('getParameterBag')
|
|
||||||
->will($this->returnValue($params));
|
|
||||||
$params->expects($this->any())
|
|
||||||
->method('all')
|
|
||||||
->will($this->returnValue(array()));
|
|
||||||
$container->expects($this->any())
|
|
||||||
->method('getDefinitions')
|
|
||||||
->will($this->returnValue(array()));
|
|
||||||
$container->expects($this->any())
|
|
||||||
->method('getAliases')
|
|
||||||
->will($this->returnValue(array()));
|
|
||||||
$container->expects($this->any())
|
|
||||||
->method('getExtensions')
|
|
||||||
->will($this->returnValue(array()));
|
|
||||||
|
|
||||||
$configPass = new MergeExtensionConfigurationPass(array('loaded', 'notloaded'));
|
|
||||||
$configPass->process($container);
|
$configPass->process($container);
|
||||||
|
|
||||||
|
$this->assertTrue($container->hasDefinition('loaded.foo'));
|
||||||
|
$this->assertTrue($container->hasDefinition('not_loaded.bar'));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
class LoadedExtension extends Extension
|
||||||
|
{
|
||||||
|
public function load(array $configs, ContainerBuilder $container)
|
||||||
|
{
|
||||||
|
$container->register('loaded.foo');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
class NotLoadedExtension extends Extension
|
||||||
|
{
|
||||||
|
public function load(array $configs, ContainerBuilder $container)
|
||||||
|
{
|
||||||
|
$container->register('not_loaded.bar');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -89,7 +89,7 @@ final class Lock implements LockInterface, LoggerAwareInterface
|
|||||||
return true;
|
return true;
|
||||||
} catch (LockConflictedException $e) {
|
} catch (LockConflictedException $e) {
|
||||||
$this->dirty = false;
|
$this->dirty = false;
|
||||||
$this->logger->warning('Failed to acquire the "{resource}" lock. Someone else already acquired the lock.', array('resource' => $this->key));
|
$this->logger->notice('Failed to acquire the "{resource}" lock. Someone else already acquired the lock.', array('resource' => $this->key));
|
||||||
|
|
||||||
if ($blocking) {
|
if ($blocking) {
|
||||||
throw $e;
|
throw $e;
|
||||||
@ -97,7 +97,7 @@ final class Lock implements LockInterface, LoggerAwareInterface
|
|||||||
|
|
||||||
return false;
|
return false;
|
||||||
} catch (\Exception $e) {
|
} catch (\Exception $e) {
|
||||||
$this->logger->warning('Failed to acquire the "{resource}" lock.', array('resource' => $this->key, 'exception' => $e));
|
$this->logger->notice('Failed to acquire the "{resource}" lock.', array('resource' => $this->key, 'exception' => $e));
|
||||||
throw new LockAcquiringException(sprintf('Failed to acquire the "%s" lock.', $this->key), 0, $e);
|
throw new LockAcquiringException(sprintf('Failed to acquire the "%s" lock.', $this->key), 0, $e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -123,10 +123,10 @@ final class Lock implements LockInterface, LoggerAwareInterface
|
|||||||
$this->logger->info('Expiration defined for "{resource}" lock for "{ttl}" seconds.', array('resource' => $this->key, 'ttl' => $this->ttl));
|
$this->logger->info('Expiration defined for "{resource}" lock for "{ttl}" seconds.', array('resource' => $this->key, 'ttl' => $this->ttl));
|
||||||
} catch (LockConflictedException $e) {
|
} catch (LockConflictedException $e) {
|
||||||
$this->dirty = false;
|
$this->dirty = false;
|
||||||
$this->logger->warning('Failed to define an expiration for the "{resource}" lock, someone else acquired the lock.', array('resource' => $this->key));
|
$this->logger->notice('Failed to define an expiration for the "{resource}" lock, someone else acquired the lock.', array('resource' => $this->key));
|
||||||
throw $e;
|
throw $e;
|
||||||
} catch (\Exception $e) {
|
} catch (\Exception $e) {
|
||||||
$this->logger->warning('Failed to define an expiration for the "{resource}" lock.', array('resource' => $this->key, 'exception' => $e));
|
$this->logger->notice('Failed to define an expiration for the "{resource}" lock.', array('resource' => $this->key, 'exception' => $e));
|
||||||
throw new LockAcquiringException(sprintf('Failed to define an expiration for the "%s" lock.', $this->key), 0, $e);
|
throw new LockAcquiringException(sprintf('Failed to define an expiration for the "%s" lock.', $this->key), 0, $e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -148,7 +148,7 @@ final class Lock implements LockInterface, LoggerAwareInterface
|
|||||||
$this->dirty = false;
|
$this->dirty = false;
|
||||||
|
|
||||||
if ($this->store->exists($this->key)) {
|
if ($this->store->exists($this->key)) {
|
||||||
$this->logger->warning('Failed to release the "{resource}" lock.', array('resource' => $this->key));
|
$this->logger->notice('Failed to release the "{resource}" lock.', array('resource' => $this->key));
|
||||||
throw new LockReleasingException(sprintf('Failed to release the "%s" lock.', $this->key));
|
throw new LockReleasingException(sprintf('Failed to release the "%s" lock.', $this->key));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -12,6 +12,7 @@
|
|||||||
namespace Symfony\Component\Lock\Tests;
|
namespace Symfony\Component\Lock\Tests;
|
||||||
|
|
||||||
use PHPUnit\Framework\TestCase;
|
use PHPUnit\Framework\TestCase;
|
||||||
|
use Psr\Log\LoggerInterface;
|
||||||
use Symfony\Component\Lock\Exception\LockConflictedException;
|
use Symfony\Component\Lock\Exception\LockConflictedException;
|
||||||
use Symfony\Component\Lock\Key;
|
use Symfony\Component\Lock\Key;
|
||||||
use Symfony\Component\Lock\Lock;
|
use Symfony\Component\Lock\Lock;
|
||||||
@ -192,6 +193,35 @@ class LockTest extends TestCase
|
|||||||
$lock->release();
|
$lock->release();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @expectedException \Symfony\Component\Lock\Exception\LockReleasingException
|
||||||
|
*/
|
||||||
|
public function testReleaseThrowsAndLog()
|
||||||
|
{
|
||||||
|
$key = new Key(uniqid(__METHOD__, true));
|
||||||
|
$store = $this->getMockBuilder(StoreInterface::class)->getMock();
|
||||||
|
$logger = $this->getMockBuilder(LoggerInterface::class)->getMock();
|
||||||
|
$lock = new Lock($key, $store, 10, true);
|
||||||
|
$lock->setLogger($logger);
|
||||||
|
|
||||||
|
$logger->expects($this->atLeastOnce())
|
||||||
|
->method('notice')
|
||||||
|
->with('Failed to release the "{resource}" lock.', array('resource' => $key));
|
||||||
|
|
||||||
|
$store
|
||||||
|
->expects($this->once())
|
||||||
|
->method('delete')
|
||||||
|
->with($key);
|
||||||
|
|
||||||
|
$store
|
||||||
|
->expects($this->once())
|
||||||
|
->method('exists')
|
||||||
|
->with($key)
|
||||||
|
->willReturn(true);
|
||||||
|
|
||||||
|
$lock->release();
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @dataProvider provideExpiredDates
|
* @dataProvider provideExpiredDates
|
||||||
*/
|
*/
|
||||||
|
@ -62,7 +62,7 @@ class ProjectUrlMatcher extends Symfony\Component\Routing\Matcher\UrlMatcher
|
|||||||
not_get_and_head:
|
not_get_and_head:
|
||||||
|
|
||||||
// post_and_head
|
// post_and_head
|
||||||
if ('/post_and_get' === $pathinfo) {
|
if ('/post_and_head' === $pathinfo) {
|
||||||
if (!in_array($requestMethod, array('POST', 'HEAD'))) {
|
if (!in_array($requestMethod, array('POST', 'HEAD'))) {
|
||||||
$allow = array_merge($allow, array('POST', 'HEAD'));
|
$allow = array_merge($allow, array('POST', 'HEAD'));
|
||||||
goto not_post_and_head;
|
goto not_post_and_head;
|
||||||
|
@ -354,7 +354,7 @@ class PhpMatcherDumperTest extends TestCase
|
|||||||
array('GET', 'HEAD')
|
array('GET', 'HEAD')
|
||||||
));
|
));
|
||||||
$headMatchCasesCollection->add('post_and_head', new Route(
|
$headMatchCasesCollection->add('post_and_head', new Route(
|
||||||
'/post_and_get',
|
'/post_and_head',
|
||||||
array(),
|
array(),
|
||||||
array(),
|
array(),
|
||||||
array(),
|
array(),
|
||||||
|
@ -30,6 +30,7 @@ CHANGELOG
|
|||||||
* added getter for extra attributes in `ExtraAttributesException`
|
* added getter for extra attributes in `ExtraAttributesException`
|
||||||
* improved `CsvEncoder` to handle variable nested structures
|
* improved `CsvEncoder` to handle variable nested structures
|
||||||
* CSV headers can be passed to the `CsvEncoder` via the `csv_headers` serialization context variable
|
* CSV headers can be passed to the `CsvEncoder` via the `csv_headers` serialization context variable
|
||||||
|
* added `$context` when checking for encoding, decoding and normalizing in `Serializer`
|
||||||
|
|
||||||
3.3.0
|
3.3.0
|
||||||
-----
|
-----
|
||||||
|
@ -98,11 +98,11 @@ class Serializer implements SerializerInterface, ContextAwareNormalizerInterface
|
|||||||
*/
|
*/
|
||||||
final public function serialize($data, $format, array $context = array())
|
final public function serialize($data, $format, array $context = array())
|
||||||
{
|
{
|
||||||
if (!$this->supportsEncoding($format)) {
|
if (!$this->supportsEncoding($format, $context)) {
|
||||||
throw new NotEncodableValueException(sprintf('Serialization for the format %s is not supported', $format));
|
throw new NotEncodableValueException(sprintf('Serialization for the format %s is not supported', $format));
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($this->encoder->needsNormalization($format)) {
|
if ($this->encoder->needsNormalization($format, $context)) {
|
||||||
$data = $this->normalize($data, $format, $context);
|
$data = $this->normalize($data, $format, $context);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -114,7 +114,7 @@ class Serializer implements SerializerInterface, ContextAwareNormalizerInterface
|
|||||||
*/
|
*/
|
||||||
final public function deserialize($data, $type, $format, array $context = array())
|
final public function deserialize($data, $type, $format, array $context = array())
|
||||||
{
|
{
|
||||||
if (!$this->supportsDecoding($format)) {
|
if (!$this->supportsDecoding($format, $context)) {
|
||||||
throw new NotEncodableValueException(sprintf('Deserialization for the format %s is not supported', $format));
|
throw new NotEncodableValueException(sprintf('Deserialization for the format %s is not supported', $format));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -63,7 +63,10 @@ class Dumper
|
|||||||
|
|
||||||
foreach ($input as $key => $value) {
|
foreach ($input as $key => $value) {
|
||||||
if ($inline >= 1 && Yaml::DUMP_MULTI_LINE_LITERAL_BLOCK & $flags && is_string($value) && false !== strpos($value, "\n") && false === strpos($value, "\r\n")) {
|
if ($inline >= 1 && Yaml::DUMP_MULTI_LINE_LITERAL_BLOCK & $flags && is_string($value) && false !== strpos($value, "\n") && false === strpos($value, "\r\n")) {
|
||||||
$output .= sprintf("%s%s%s |\n", $prefix, $dumpAsMap ? Inline::dump($key, $flags).':' : '-', '');
|
// If the first line starts with a space character, the spec requires a blockIndicationIndicator
|
||||||
|
// http://www.yaml.org/spec/1.2/spec.html#id2793979
|
||||||
|
$blockIndentationIndicator = (' ' === substr($value, 0, 1)) ? (string) $this->indentation : '';
|
||||||
|
$output .= sprintf("%s%s%s |%s\n", $prefix, $dumpAsMap ? Inline::dump($key, $flags).':' : '-', '', $blockIndentationIndicator);
|
||||||
|
|
||||||
foreach (preg_split('/\n|\r\n/', $value) as $row) {
|
foreach (preg_split('/\n|\r\n/', $value) as $row) {
|
||||||
$output .= sprintf("%s%s%s\n", $prefix, str_repeat(' ', $this->indentation), $row);
|
$output .= sprintf("%s%s%s\n", $prefix, str_repeat(' ', $this->indentation), $row);
|
||||||
|
@ -388,6 +388,17 @@ YAML;
|
|||||||
$this->assertSame(file_get_contents(__DIR__.'/Fixtures/multiple_lines_as_literal_block.yml'), $this->dumper->dump($data, 2, 0, Yaml::DUMP_MULTI_LINE_LITERAL_BLOCK));
|
$this->assertSame(file_get_contents(__DIR__.'/Fixtures/multiple_lines_as_literal_block.yml'), $this->dumper->dump($data, 2, 0, Yaml::DUMP_MULTI_LINE_LITERAL_BLOCK));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function testDumpMultiLineStringAsScalarBlockWhenFirstLineHasLeadingSpace()
|
||||||
|
{
|
||||||
|
$data = array(
|
||||||
|
'data' => array(
|
||||||
|
'multi_line' => " the first line has leading spaces\nThe second line does not.",
|
||||||
|
),
|
||||||
|
);
|
||||||
|
|
||||||
|
$this->assertSame(file_get_contents(__DIR__.'/Fixtures/multiple_lines_as_literal_block_leading_space_in_first_line.yml'), $this->dumper->dump($data, 2, 0, Yaml::DUMP_MULTI_LINE_LITERAL_BLOCK));
|
||||||
|
}
|
||||||
|
|
||||||
public function testCarriageReturnIsMaintainedWhenDumpingAsMultiLineLiteralBlock()
|
public function testCarriageReturnIsMaintainedWhenDumpingAsMultiLineLiteralBlock()
|
||||||
{
|
{
|
||||||
$this->assertSame("- \"a\\r\\nb\\nc\"\n", $this->dumper->dump(array("a\r\nb\nc"), 2, 0, Yaml::DUMP_MULTI_LINE_LITERAL_BLOCK));
|
$this->assertSame("- \"a\\r\\nb\\nc\"\n", $this->dumper->dump(array("a\r\nb\nc"), 2, 0, Yaml::DUMP_MULTI_LINE_LITERAL_BLOCK));
|
||||||
|
@ -0,0 +1,4 @@
|
|||||||
|
data:
|
||||||
|
multi_line: |4
|
||||||
|
the first line has leading spaces
|
||||||
|
The second line does not.
|
Reference in New Issue
Block a user