diff --git a/.travis.yml b/.travis.yml index 29cc1bb841..98e64d7865 100644 --- a/.travis.yml +++ b/.travis.yml @@ -6,7 +6,7 @@ matrix: - php: 5.5 - php: 5.6 - php: 5.5.9 - env: components=low SYMFONY_DEPRECATIONS_HELPER=weak + env: components=low - php: 5.6 env: components=high - php: hhvm-nightly @@ -40,5 +40,6 @@ install: script: - if [ "$components" = "no" ]; then ls -d src/Symfony/*/* | parallel --gnu --keep-order 'echo -e "\\nRunning {} tests"; phpunit --exclude-group tty,benchmark,intl-data {} || (echo -e "\\e[41mKO\\e[0m {}" && $(exit 1));'; fi; - if [ "$components" = "no" ]; then echo -e "\\nRunning tests requiring tty"; phpunit --group tty || (echo -e "\\e[41mKO\\e[0m tty group" && $(exit 1)); fi; + - if [ "$components" != "no" ]; then export SYMFONY_DEPRECATIONS_HELPER=weak; fi; - if [ "$components" = "high" ]; then find src/Symfony -mindepth 3 -type f -name phpunit.xml.dist | sed 's#\(.*\)/.*#\1#' | parallel --gnu --keep-order -j25% 'echo -e "\\nRunning {} tests"; cd {}; composer --prefer-source update; phpunit --exclude-group tty,benchmark,intl-data,legacy || (echo -e "\\e[41mKO\\e[0m {}" && $(exit 1));'; fi; - if [ "$components" = "low" ]; then find src/Symfony -mindepth 3 -type f -name phpunit.xml.dist | sed 's#\(.*\)/.*#\1#' | parallel --gnu --keep-order -j25% 'echo -e "\\nRunning {} tests"; cd {}; composer --prefer-source --prefer-lowest --prefer-stable update; phpunit --exclude-group tty,benchmark,intl-data || (echo -e "\\e[41mKO\\e[0m {}" && $(exit 1));'; fi; diff --git a/src/Symfony/Bridge/PhpUnit/DeprecationErrorHandler.php b/src/Symfony/Bridge/PhpUnit/DeprecationErrorHandler.php index 7758209c3e..62c6d4c5ac 100644 --- a/src/Symfony/Bridge/PhpUnit/DeprecationErrorHandler.php +++ b/src/Symfony/Bridge/PhpUnit/DeprecationErrorHandler.php @@ -20,7 +20,7 @@ class DeprecationErrorHandler { private static $isRegistered = false; - public static function register($strict = false) + public static function register($mode = false) { if (self::$isRegistered) { return; @@ -33,7 +33,7 @@ class DeprecationErrorHandler 'legacy' => array(), 'other' => array(), ); - $deprecationHandler = function ($type, $msg, $file, $line, $context) use (&$deprecations, $strict) { + $deprecationHandler = function ($type, $msg, $file, $line, $context) use (&$deprecations) { if (E_USER_DEPRECATED !== $type) { return \PHPUnit_Util_ErrorHandler::handleError($type, $msg, $file, $line, $context); } @@ -66,21 +66,6 @@ class DeprecationErrorHandler ++$ref; } ++$deprecations[$group.'Count']; - unset($trace, $ref); - - if ('legacy' !== $group) { - try { - $e = $strict ? error_reporting(-1) : error_reporting(); - $result = \PHPUnit_Util_ErrorHandler::handleError($type, $msg, $file, $line, $context); - error_reporting($e); - } catch (\Exception $x) { - error_reporting($e); - - throw $x; - } - - return $result; - } }; $oldErrorHandler = set_error_handler($deprecationHandler); @@ -88,7 +73,7 @@ class DeprecationErrorHandler restore_error_handler(); if (array('PHPUnit_Util_ErrorHandler', 'handleError') === $oldErrorHandler) { restore_error_handler(); - self::register(); + self::register($mode); } } else { self::$isRegistered = true; @@ -101,7 +86,7 @@ class DeprecationErrorHandler } else { $colorize = function ($str) {return $str;}; } - register_shutdown_function(function () use (&$deprecations, $deprecationHandler, $colorize) { + register_shutdown_function(function () use ($mode, &$deprecations, $deprecationHandler, $colorize) { $currErrorHandler = set_error_handler('var_dump'); restore_error_handler(); @@ -135,6 +120,14 @@ class DeprecationErrorHandler if (!empty($notices)) { echo "\n"; } + if ('weak' !== $mode) { + if ($deprecations['remaining'] || $deprecations['other']) { + exit(1); + } + if ('strict' === $mode && $deprecations['legacy'] && $deprecations['legacyCount'] !== $ref =& $deprecations['legacy']['Silenced']['count']) { + exit(1); + } + } }); } } diff --git a/src/Symfony/Bridge/PhpUnit/README.md b/src/Symfony/Bridge/PhpUnit/README.md index 4e8db55d56..3cc8539831 100644 --- a/src/Symfony/Bridge/PhpUnit/README.md +++ b/src/Symfony/Bridge/PhpUnit/README.md @@ -12,19 +12,19 @@ It comes with the following features: Handling user deprecation notices is sensitive to the SYMFONY_DEPRECATIONS_HELPER environment variable. This env var configures 3 behaviors depending on its value: - * when set to `strict`, all but legacy-tagged deprecation notices will make tests - fail. This is the recommended mode for best forward compatibility. + * when set to `strict`, all but silenced-legacy-tagged deprecation notices will + make tests fail. This is the recommended mode for best forward compatibility * `weak` on the contrary will make tests ignore all deprecation notices. This is the recommended mode for legacy projects that must use deprecated interfaces for backward compatibility reasons. - * any other value will respect the current error reporting level. + * with any other value, all but silenced-or-not-legacy-tagged deprecation + notices will make tests fail. All three modes will display a summary of deprecation notices at the end of the test suite, split in two groups: * **Legacy** deprecation notices denote tests that explicitly test some legacy - interfaces. In all 3 modes, deprecation notices triggered in a legacy-tagged - test do never make a test fail. There are four ways to mark a test as legacy: + interfaces. There are four ways to mark a test as legacy: - make its class start with the `Legacy` prefix; - make its method start with `testLegacy`; - make its data provider start with `provideLegacy` or `getLegacy`; diff --git a/src/Symfony/Bridge/PhpUnit/bootstrap.php b/src/Symfony/Bridge/PhpUnit/bootstrap.php index 8d554af447..2ef48f1fb2 100644 --- a/src/Symfony/Bridge/PhpUnit/bootstrap.php +++ b/src/Symfony/Bridge/PhpUnit/bootstrap.php @@ -15,15 +15,4 @@ if (class_exists('Doctrine\Common\Annotations\AnnotationRegistry')) { AnnotationRegistry::registerLoader('class_exists'); } -switch (getenv('SYMFONY_DEPRECATIONS_HELPER')) { - case 'strict': - DeprecationErrorHandler::register(true); - break; - - case 'weak': - error_reporting(error_reporting() & ~E_USER_DEPRECATED); - // No break; - default: - DeprecationErrorHandler::register(false); - break; -} +DeprecationErrorHandler::register(getenv('SYMFONY_DEPRECATIONS_HELPER')); diff --git a/src/Symfony/Bridge/PhpUnit/composer.json b/src/Symfony/Bridge/PhpUnit/composer.json index 041299e729..ac7c703605 100644 --- a/src/Symfony/Bridge/PhpUnit/composer.json +++ b/src/Symfony/Bridge/PhpUnit/composer.json @@ -18,6 +18,9 @@ "require": { "php": ">=5.5.9" }, + "suggest": { + "symfony/debug": "For tracking deprecated interfaces usages at runtime with DebugClassLoader" + }, "autoload": { "files": [ "bootstrap.php" ], "psr-0": { "Symfony\\Bridge\\PhpUnit\\": "" } diff --git a/src/Symfony/Bridge/Twig/composer.json b/src/Symfony/Bridge/Twig/composer.json index ed73831dd9..ef2f56e67a 100644 --- a/src/Symfony/Bridge/Twig/composer.json +++ b/src/Symfony/Bridge/Twig/composer.json @@ -21,6 +21,7 @@ }, "require-dev": { "symfony/phpunit-bridge": "~2.7|~3.0", + "symfony/asset": "~2.7|~3.0", "symfony/finder": "~2.7|~3.0", "symfony/form": "~2.7|~3.0", "symfony/http-kernel": "~2.7|~3.0", diff --git a/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/ConfigurationTest.php b/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/ConfigurationTest.php index 7275d4d4b6..1cef379eeb 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/ConfigurationTest.php +++ b/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/ConfigurationTest.php @@ -90,8 +90,10 @@ class ConfigurationTest extends \PHPUnit_Framework_TestCase * @expectedException \Symfony\Component\Config\Definition\Exception\InvalidConfigurationException * @expectedExceptionMessage You cannot use assets settings under "framework.templating" and "assets" configurations in the same project. */ - public function testInvalidValueAssets() + public function testLegacyInvalidValueAssets() { + $this->iniSet('error_reporting', -1 & ~E_USER_DEPRECATED); + $processor = new Processor(); $configuration = new Configuration(true); $processor->processConfiguration($configuration, array( diff --git a/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/FrameworkExtensionTest.php b/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/FrameworkExtensionTest.php index 88e059fc6c..7e7db49afd 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/FrameworkExtensionTest.php +++ b/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/FrameworkExtensionTest.php @@ -485,6 +485,8 @@ abstract class FrameworkExtensionTest extends TestCase public function testLegacyFormCsrfFieldNameUnderFormSettingsTakesPrecedence() { + $this->iniSet('error_reporting', -1 & ~E_USER_DEPRECATED); + $container = $this->createContainerFromFile('form_csrf_under_form_sets_field_name'); $this->assertTrue($container->getParameter('form.type_extension.csrf.enabled')); diff --git a/src/Symfony/Component/Debug/Tests/FatalErrorHandler/ClassNotFoundFatalErrorHandlerTest.php b/src/Symfony/Component/Debug/Tests/FatalErrorHandler/ClassNotFoundFatalErrorHandlerTest.php index 689fe08b62..a27e7df0e1 100644 --- a/src/Symfony/Component/Debug/Tests/FatalErrorHandler/ClassNotFoundFatalErrorHandlerTest.php +++ b/src/Symfony/Component/Debug/Tests/FatalErrorHandler/ClassNotFoundFatalErrorHandlerTest.php @@ -34,12 +34,11 @@ class ClassNotFoundFatalErrorHandlerTest extends \PHPUnit_Framework_TestCase } /** + * @group legacy * @dataProvider provideLegacyClassNotFoundData */ public function testLegacyHandleClassNotFound($error, $translatedMessage, $autoloader) { - $this->iniSet('error_reporting', -1 & ~E_USER_DEPRECATED); - // Unregister all autoloaders to ensure the custom provided // autoloader is the only one to be used during the test run. $autoloaders = spl_autoload_functions(); @@ -113,6 +112,8 @@ class ClassNotFoundFatalErrorHandlerTest extends \PHPUnit_Framework_TestCase public function provideLegacyClassNotFoundData() { + $this->iniSet('error_reporting', -1 & ~E_USER_DEPRECATED); + $prefixes = array('Symfony\Component\Debug\Exception\\' => realpath(__DIR__.'/../../Exception')); $symfonyAutoloader = new SymfonyClassLoader(); diff --git a/src/Symfony/Component/DependencyInjection/Tests/Dumper/GraphvizDumperTest.php b/src/Symfony/Component/DependencyInjection/Tests/Dumper/GraphvizDumperTest.php index bc41f1b967..7c13ac6ca1 100644 --- a/src/Symfony/Component/DependencyInjection/Tests/Dumper/GraphvizDumperTest.php +++ b/src/Symfony/Component/DependencyInjection/Tests/Dumper/GraphvizDumperTest.php @@ -25,6 +25,8 @@ class GraphvizDumperTest extends \PHPUnit_Framework_TestCase public function testLegacyDump() { + $this->iniSet('error_reporting', -1 & ~E_USER_DEPRECATED); + $container = include self::$fixturesPath.'/containers/legacy-container9.php'; $dumper = new GraphvizDumper($container); $this->assertEquals(str_replace('%path%', __DIR__, file_get_contents(self::$fixturesPath.'/graphviz/legacy-services9.dot')), $dumper->dump(), '->dump() dumps services'); diff --git a/src/Symfony/Component/DependencyInjection/Tests/LegacyDefinitionTest.php b/src/Symfony/Component/DependencyInjection/Tests/LegacyDefinitionTest.php index 9fb0c7ff0e..d508d81e1e 100644 --- a/src/Symfony/Component/DependencyInjection/Tests/LegacyDefinitionTest.php +++ b/src/Symfony/Component/DependencyInjection/Tests/LegacyDefinitionTest.php @@ -15,6 +15,11 @@ use Symfony\Component\DependencyInjection\Definition; class LegacyDefinitionTest extends \PHPUnit_Framework_TestCase { + public function setUp() + { + $this->iniSet('error_reporting', -1 & ~E_USER_DEPRECATED); + } + public function testSetGetFactoryClass() { $def = new Definition('stdClass'); diff --git a/src/Symfony/Component/DependencyInjection/Tests/Loader/YamlFileLoaderTest.php b/src/Symfony/Component/DependencyInjection/Tests/Loader/YamlFileLoaderTest.php index 594d9a3de7..d40886884b 100644 --- a/src/Symfony/Component/DependencyInjection/Tests/Loader/YamlFileLoaderTest.php +++ b/src/Symfony/Component/DependencyInjection/Tests/Loader/YamlFileLoaderTest.php @@ -122,6 +122,8 @@ class YamlFileLoaderTest extends \PHPUnit_Framework_TestCase public function testLegacyLoadServices() { + $this->iniSet('error_reporting', -1 & ~E_USER_DEPRECATED); + $container = new ContainerBuilder(); $loader = new YamlFileLoader($container, new FileLocator(self::$fixturesPath.'/yaml')); $loader->load('legacy-services6.yml'); diff --git a/src/Symfony/Component/Validator/Tests/Constraints/CallbackValidatorTest.php b/src/Symfony/Component/Validator/Tests/Constraints/CallbackValidatorTest.php index d9062998bb..42ee43bc3d 100644 --- a/src/Symfony/Component/Validator/Tests/Constraints/CallbackValidatorTest.php +++ b/src/Symfony/Component/Validator/Tests/Constraints/CallbackValidatorTest.php @@ -188,6 +188,8 @@ class CallbackValidatorTest extends AbstractConstraintValidatorTest // BC with Symfony < 2.4 public function testLegacySingleMethodBc() { + $this->iniSet('error_reporting', -1 & ~E_USER_DEPRECATED); + $object = new CallbackValidatorTest_Object(); $constraint = new Callback(array('validate')); @@ -201,6 +203,8 @@ class CallbackValidatorTest extends AbstractConstraintValidatorTest // BC with Symfony < 2.4 public function testLegacySingleMethodBcExplicitName() { + $this->iniSet('error_reporting', -1 & ~E_USER_DEPRECATED); + $object = new CallbackValidatorTest_Object(); $constraint = new Callback(array('methods' => array('validate'))); @@ -214,6 +218,8 @@ class CallbackValidatorTest extends AbstractConstraintValidatorTest // BC with Symfony < 2.4 public function testLegacyMultipleMethodsBc() { + $this->iniSet('error_reporting', -1 & ~E_USER_DEPRECATED); + $object = new CallbackValidatorTest_Object(); $constraint = new Callback(array('validate', 'validateStatic')); @@ -229,6 +235,8 @@ class CallbackValidatorTest extends AbstractConstraintValidatorTest // BC with Symfony < 2.4 public function testLegacyMultipleMethodsBcExplicitName() { + $this->iniSet('error_reporting', -1 & ~E_USER_DEPRECATED); + $object = new CallbackValidatorTest_Object(); $constraint = new Callback(array( 'methods' => array('validate', 'validateStatic'), @@ -246,6 +254,8 @@ class CallbackValidatorTest extends AbstractConstraintValidatorTest // BC with Symfony < 2.4 public function testLegacySingleStaticMethodBc() { + $this->iniSet('error_reporting', -1 & ~E_USER_DEPRECATED); + $object = new CallbackValidatorTest_Object(); $constraint = new Callback(array( array(__CLASS__.'_Class', 'validateCallback'), @@ -261,6 +271,8 @@ class CallbackValidatorTest extends AbstractConstraintValidatorTest // BC with Symfony < 2.4 public function testLegacySingleStaticMethodBcExplicitName() { + $this->iniSet('error_reporting', -1 & ~E_USER_DEPRECATED); + $object = new CallbackValidatorTest_Object(); $constraint = new Callback(array( 'methods' => array(array(__CLASS__.'_Class', 'validateCallback')), @@ -298,6 +310,8 @@ class CallbackValidatorTest extends AbstractConstraintValidatorTest */ public function testLegacyExpectEitherCallbackOrMethods() { + $this->iniSet('error_reporting', -1 & ~E_USER_DEPRECATED); + $object = new CallbackValidatorTest_Object(); $this->validator->validate($object, new Callback(array(