From 9c7512bf39bcb56c9229863cb6b7343657106997 Mon Sep 17 00:00:00 2001 From: Christian Flothmann Date: Tue, 14 Jun 2016 14:01:38 +0200 Subject: [PATCH 1/4] update tests to use the new error assertion helper --- phpunit | 2 +- .../FrameworkExtensionTest.php | 22 +++---------- .../Templating/TemplateNameParserTest.php | 24 ++++---------- .../Tests/ContainerBuilderTest.php | 28 +++++------------ .../Tests/Loader/XmlFileLoaderTest.php | 31 +++++++------------ .../Fragment/EsiFragmentRendererTest.php | 28 ++++------------- .../Component/Yaml/Tests/InlineTest.php | 19 ++---------- 7 files changed, 39 insertions(+), 115 deletions(-) diff --git a/phpunit b/phpunit index 3ab3ca1686..f70cdbfb49 100755 --- a/phpunit +++ b/phpunit @@ -56,7 +56,7 @@ if (!file_exists("$PHPUNIT_DIR/phpunit-$PHPUNIT_VERSION/phpunit") || md5_file(__ if (5.1 <= $PHPUNIT_VERSION && $PHPUNIT_VERSION < 5.4) { passthru("$COMPOSER require --no-update phpunit/phpunit-mock-objects \"~3.1.0\""); } - passthru("$COMPOSER require --dev --no-update symfony/phpunit-bridge \">=3.1@dev\""); + passthru("$COMPOSER require --dev --no-update symfony/phpunit-bridge \">=3.2@dev\""); passthru("$COMPOSER install --prefer-dist --no-progress --ansi", $exit); if ($exit) { exit($exit); diff --git a/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/FrameworkExtensionTest.php b/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/FrameworkExtensionTest.php index f0d5692d62..ef0c5522fd 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/FrameworkExtensionTest.php +++ b/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/FrameworkExtensionTest.php @@ -11,6 +11,7 @@ namespace Symfony\Bundle\FrameworkBundle\Tests\DependencyInjection; +use Symfony\Bridge\PhpUnit\ErrorAssert; use Symfony\Bundle\FrameworkBundle\Tests\TestCase; use Symfony\Bundle\FrameworkBundle\DependencyInjection\FrameworkExtension; use Symfony\Component\Cache\Adapter\ApcuAdapter; @@ -541,25 +542,12 @@ abstract class FrameworkExtensionTest extends TestCase */ public function testDeprecatedSerializerCacheOption() { - $deprecations = array(); - set_error_handler(function ($type, $msg) use (&$deprecations) { - if (E_USER_DEPRECATED !== $type) { - restore_error_handler(); + ErrorAssert::assertDeprecationsAreTriggered('The "framework.serializer.cache" option is deprecated', function () { + $container = $this->createContainerFromFile('serializer_legacy_cache', array('kernel.debug' => true, 'kernel.container_class' => __CLASS__)); - return call_user_func_array('PHPUnit_Util_ErrorHandler::handleError', func_get_args()); - } - - $deprecations[] = $msg; + $this->assertFalse($container->hasDefinition('serializer.mapping.cache_class_metadata_factory')); + $this->assertEquals(new Reference('foo'), $container->getDefinition('serializer.mapping.class_metadata_factory')->getArgument(1)); }); - - $container = $this->createContainerFromFile('serializer_legacy_cache', array('kernel.debug' => true, 'kernel.container_class' => __CLASS__)); - - restore_error_handler(); - - $this->assertCount(1, $deprecations); - $this->assertContains('The "framework.serializer.cache" option is deprecated', $deprecations[0]); - $this->assertFalse($container->hasDefinition('serializer.mapping.cache_class_metadata_factory')); - $this->assertEquals(new Reference('foo'), $container->getDefinition('serializer.mapping.class_metadata_factory')->getArgument(1)); } public function testAssetHelperWhenAssetsAreEnabled() diff --git a/src/Symfony/Bundle/FrameworkBundle/Tests/Templating/TemplateNameParserTest.php b/src/Symfony/Bundle/FrameworkBundle/Tests/Templating/TemplateNameParserTest.php index 813f440217..8506b9ea6c 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Tests/Templating/TemplateNameParserTest.php +++ b/src/Symfony/Bundle/FrameworkBundle/Tests/Templating/TemplateNameParserTest.php @@ -11,6 +11,7 @@ namespace Symfony\Bundle\FrameworkBundle\Tests\Templating; +use Symfony\Bridge\PhpUnit\ErrorAssert; use Symfony\Bundle\FrameworkBundle\Tests\TestCase; use Symfony\Bundle\FrameworkBundle\Templating\TemplateNameParser; use Symfony\Bundle\FrameworkBundle\Templating\TemplateReference; @@ -88,26 +89,13 @@ class TemplateNameParserTest extends TestCase */ public function testAbsolutePathsAreDeprecated($name, $logicalName, $path, $ref) { - $deprecations = array(); - set_error_handler(function ($type, $msg) use (&$deprecations) { - if (E_USER_DEPRECATED !== $type) { - restore_error_handler(); + ErrorAssert::assertDeprecationsAreTriggered('Absolute template path support is deprecated since Symfony 3.1 and will be removed in 4.0.', function () use ($name, $logicalName, $path, $ref) { + $template = $this->parser->parse($name); - return call_user_func_array('PHPUnit_Util_ErrorHandler::handleError', func_get_args()); - } - - $deprecations[] = $msg; + $this->assertSame($ref->getLogicalName(), $template->getLogicalName()); + $this->assertSame($logicalName, $template->getLogicalName()); + $this->assertSame($path, $template->getPath()); }); - - $template = $this->parser->parse($name); - - restore_error_handler(); - - $this->assertSame($ref->getLogicalName(), $template->getLogicalName()); - $this->assertSame($logicalName, $template->getLogicalName()); - $this->assertSame($path, $template->getPath()); - $this->assertCount(1, $deprecations); - $this->assertContains('Absolute template path support is deprecated since Symfony 3.1 and will be removed in 4.0.', $deprecations[0]); } public function provideAbsolutePaths() diff --git a/src/Symfony/Component/DependencyInjection/Tests/ContainerBuilderTest.php b/src/Symfony/Component/DependencyInjection/Tests/ContainerBuilderTest.php index c8820d5d59..25c4cb12c0 100644 --- a/src/Symfony/Component/DependencyInjection/Tests/ContainerBuilderTest.php +++ b/src/Symfony/Component/DependencyInjection/Tests/ContainerBuilderTest.php @@ -14,13 +14,13 @@ namespace Symfony\Component\DependencyInjection\Tests; require_once __DIR__.'/Fixtures/includes/classes.php'; require_once __DIR__.'/Fixtures/includes/ProjectExtension.php'; +use Symfony\Bridge\PhpUnit\ErrorAssert; use Symfony\Component\Config\Resource\ResourceInterface; use Symfony\Component\DependencyInjection\Alias; use Symfony\Component\DependencyInjection\ContainerBuilder; use Symfony\Component\DependencyInjection\ContainerInterface; use Symfony\Component\DependencyInjection\Definition; use Symfony\Component\DependencyInjection\Exception\RuntimeException; -use Symfony\Component\DependencyInjection\Exception\InactiveScopeException; use Symfony\Component\DependencyInjection\Exception\ServiceCircularReferenceException; use Symfony\Component\DependencyInjection\Exception\ServiceNotFoundException; use Symfony\Component\DependencyInjection\Loader\ClosureLoader; @@ -60,28 +60,14 @@ class ContainerBuilderTest extends \PHPUnit_Framework_TestCase public function testCreateDeprecatedService() { - $deprecations = array(); - set_error_handler(function ($type, $msg) use (&$deprecations) { - if (E_USER_DEPRECATED !== $type) { - restore_error_handler(); + ErrorAssert::assertDeprecationsAreTriggered('The "deprecated_foo" service is deprecated. You should stop using it, as it will soon be removed.', function () { + $definition = new Definition('stdClass'); + $definition->setDeprecated(true); - return call_user_func_array('PHPUnit_Util_ErrorHandler::handleError', func_get_args()); - } - - $deprecations[] = $msg; + $builder = new ContainerBuilder(); + $builder->setDefinition('deprecated_foo', $definition); + $builder->get('deprecated_foo'); }); - - $definition = new Definition('stdClass'); - $definition->setDeprecated(true); - - $builder = new ContainerBuilder(); - $builder->setDefinition('deprecated_foo', $definition); - $builder->get('deprecated_foo'); - - restore_error_handler(); - - $this->assertCount(1, $deprecations); - $this->assertContains('The "deprecated_foo" service is deprecated. You should stop using it, as it will soon be removed.', $deprecations[0]); } public function testRegister() diff --git a/src/Symfony/Component/DependencyInjection/Tests/Loader/XmlFileLoaderTest.php b/src/Symfony/Component/DependencyInjection/Tests/Loader/XmlFileLoaderTest.php index 9f04e92d78..cb235ac812 100644 --- a/src/Symfony/Component/DependencyInjection/Tests/Loader/XmlFileLoaderTest.php +++ b/src/Symfony/Component/DependencyInjection/Tests/Loader/XmlFileLoaderTest.php @@ -11,6 +11,7 @@ namespace Symfony\Component\DependencyInjection\Tests\Loader; +use Symfony\Bridge\PhpUnit\ErrorAssert; use Symfony\Component\DependencyInjection\ContainerInterface; use Symfony\Component\DependencyInjection\ContainerBuilder; use Symfony\Component\DependencyInjection\Exception\InvalidArgumentException; @@ -546,29 +547,19 @@ class XmlFileLoaderTest extends \PHPUnit_Framework_TestCase */ public function testAliasDefinitionContainsUnsupportedElements() { - $container = new ContainerBuilder(); - $loader = new XmlFileLoader($container, new FileLocator(self::$fixturesPath.'/xml')); + $deprecations = array( + 'Using the attribute "class" is deprecated for alias definition "bar"', + 'Using the element "tag" is deprecated for alias definition "bar"', + 'Using the element "factory" is deprecated for alias definition "bar"', + ); - $deprecations = array(); - set_error_handler(function ($type, $msg) use (&$deprecations) { - if (E_USER_DEPRECATED !== $type) { - restore_error_handler(); + ErrorAssert::assertDeprecationsAreTriggered($deprecations, function () { + $container = new ContainerBuilder(); + $loader = new XmlFileLoader($container, new FileLocator(self::$fixturesPath.'/xml')); - return call_user_func_array('PHPUnit_Util_ErrorHandler::handleError', func_get_args()); - } + $loader->load('legacy_invalid_alias_definition.xml'); - $deprecations[] = $msg; + $this->assertTrue($container->has('bar')); }); - - $loader->load('legacy_invalid_alias_definition.xml'); - - restore_error_handler(); - - $this->assertTrue($container->has('bar')); - - $this->assertCount(3, $deprecations); - $this->assertContains('Using the attribute "class" is deprecated for alias definition "bar"', $deprecations[0]); - $this->assertContains('Using the element "tag" is deprecated for alias definition "bar"', $deprecations[1]); - $this->assertContains('Using the element "factory" is deprecated for alias definition "bar"', $deprecations[2]); } } diff --git a/src/Symfony/Component/HttpKernel/Tests/Fragment/EsiFragmentRendererTest.php b/src/Symfony/Component/HttpKernel/Tests/Fragment/EsiFragmentRendererTest.php index 4780aa3d74..3326297349 100644 --- a/src/Symfony/Component/HttpKernel/Tests/Fragment/EsiFragmentRendererTest.php +++ b/src/Symfony/Component/HttpKernel/Tests/Fragment/EsiFragmentRendererTest.php @@ -11,6 +11,7 @@ namespace Symfony\Component\HttpKernel\Tests\Fragment; +use Symfony\Bridge\PhpUnit\ErrorAssert; use Symfony\Component\HttpKernel\Controller\ControllerReference; use Symfony\Component\HttpKernel\Fragment\EsiFragmentRenderer; use Symfony\Component\HttpKernel\HttpCache\Esi; @@ -30,29 +31,12 @@ class EsiFragmentRendererTest extends \PHPUnit_Framework_TestCase */ public function testRenderFallbackWithObjectAttributesIsDeprecated() { - $deprecations = array(); - set_error_handler(function ($type, $message) use (&$deprecations) { - if (E_USER_DEPRECATED !== $type) { - restore_error_handler(); - - return call_user_func_array('PHPUnit_Util_ErrorHandler::handleError', func_get_args()); - } - - $deprecations[] = $message; + ErrorAssert::assertDeprecationsAreTriggered('Passing objects as part of URI attributes to the ESI and SSI rendering strategies is deprecated', function () { + $strategy = new EsiFragmentRenderer(new Esi(), $this->getInlineStrategy(true), new UriSigner('foo')); + $request = Request::create('/'); + $reference = new ControllerReference('main_controller', array('foo' => array('a' => array(), 'b' => new \stdClass())), array()); + $strategy->render($reference, $request); }); - - $strategy = new EsiFragmentRenderer(new Esi(), $this->getInlineStrategy(true), new UriSigner('foo')); - - $request = Request::create('/'); - - $reference = new ControllerReference('main_controller', array('foo' => array('a' => array(), 'b' => new \stdClass())), array()); - - $strategy->render($reference, $request); - - restore_error_handler(); - - $this->assertCount(1, $deprecations); - $this->assertContains('Passing objects as part of URI attributes to the ESI and SSI rendering strategies is deprecated', $deprecations[0]); } public function testRender() diff --git a/src/Symfony/Component/Yaml/Tests/InlineTest.php b/src/Symfony/Component/Yaml/Tests/InlineTest.php index fb6210dd7d..05e58ca92b 100644 --- a/src/Symfony/Component/Yaml/Tests/InlineTest.php +++ b/src/Symfony/Component/Yaml/Tests/InlineTest.php @@ -11,6 +11,7 @@ namespace Symfony\Component\Yaml\Tests; +use Symfony\Bridge\PhpUnit\ErrorAssert; use Symfony\Component\Yaml\Inline; use Symfony\Component\Yaml\Yaml; @@ -258,23 +259,9 @@ class InlineTest extends \PHPUnit_Framework_TestCase */ public function testParseUnquotedScalarStartingWithPercentCharacter() { - $deprecations = array(); - set_error_handler(function ($type, $msg) use (&$deprecations) { - if (E_USER_DEPRECATED !== $type) { - restore_error_handler(); - - return call_user_func_array('PHPUnit_Util_ErrorHandler::handleError', func_get_args()); - } - - $deprecations[] = $msg; + ErrorAssert::assertDeprecationsAreTriggered('Not quoting a scalar starting with the "%" indicator character is deprecated since Symfony 3.1 and will throw a ParseException in 4.0.', function () { + Inline::parse('{ foo: %foo }'); }); - - Inline::parse('{ foo: %foo }'); - - restore_error_handler(); - - $this->assertCount(1, $deprecations); - $this->assertContains('Not quoting a scalar starting with the "%" indicator character is deprecated since Symfony 3.1 and will throw a ParseException in 4.0.', $deprecations[0]); } /** From c12b66664fdd2993dd5b37bdff148356445a787c Mon Sep 17 00:00:00 2001 From: Nicolas Grekas Date: Thu, 16 Jun 2016 09:20:06 +0200 Subject: [PATCH 2/4] [ci] Upgrade to symfony/phpunit-bridge >=3.2@dev --- phpunit | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/phpunit b/phpunit index 3ab3ca1686..f70cdbfb49 100755 --- a/phpunit +++ b/phpunit @@ -56,7 +56,7 @@ if (!file_exists("$PHPUNIT_DIR/phpunit-$PHPUNIT_VERSION/phpunit") || md5_file(__ if (5.1 <= $PHPUNIT_VERSION && $PHPUNIT_VERSION < 5.4) { passthru("$COMPOSER require --no-update phpunit/phpunit-mock-objects \"~3.1.0\""); } - passthru("$COMPOSER require --dev --no-update symfony/phpunit-bridge \">=3.1@dev\""); + passthru("$COMPOSER require --dev --no-update symfony/phpunit-bridge \">=3.2@dev\""); passthru("$COMPOSER install --prefer-dist --no-progress --ansi", $exit); if ($exit) { exit($exit); From e5cf4d424b741dd9418c4dd8efe3d2407581f375 Mon Sep 17 00:00:00 2001 From: Christian Flothmann Date: Tue, 14 Jun 2016 14:01:38 +0200 Subject: [PATCH 3/4] update tests to use the new error assertion helper --- phpunit | 2 +- .../Tests/ContainerBuilderTest.php | 25 +++++-------------- .../Component/Yaml/Tests/ParserTest.php | 24 +++++------------- 3 files changed, 13 insertions(+), 38 deletions(-) diff --git a/phpunit b/phpunit index 3ab3ca1686..f70cdbfb49 100755 --- a/phpunit +++ b/phpunit @@ -56,7 +56,7 @@ if (!file_exists("$PHPUNIT_DIR/phpunit-$PHPUNIT_VERSION/phpunit") || md5_file(__ if (5.1 <= $PHPUNIT_VERSION && $PHPUNIT_VERSION < 5.4) { passthru("$COMPOSER require --no-update phpunit/phpunit-mock-objects \"~3.1.0\""); } - passthru("$COMPOSER require --dev --no-update symfony/phpunit-bridge \">=3.1@dev\""); + passthru("$COMPOSER require --dev --no-update symfony/phpunit-bridge \">=3.2@dev\""); passthru("$COMPOSER install --prefer-dist --no-progress --ansi", $exit); if ($exit) { exit($exit); diff --git a/src/Symfony/Component/DependencyInjection/Tests/ContainerBuilderTest.php b/src/Symfony/Component/DependencyInjection/Tests/ContainerBuilderTest.php index 8e80c47205..f9f6aabe73 100644 --- a/src/Symfony/Component/DependencyInjection/Tests/ContainerBuilderTest.php +++ b/src/Symfony/Component/DependencyInjection/Tests/ContainerBuilderTest.php @@ -14,6 +14,7 @@ namespace Symfony\Component\DependencyInjection\Tests; require_once __DIR__.'/Fixtures/includes/classes.php'; require_once __DIR__.'/Fixtures/includes/ProjectExtension.php'; +use Symfony\Bridge\PhpUnit\ErrorAssert; use Symfony\Component\Config\Resource\ResourceInterface; use Symfony\Component\DependencyInjection\Alias; use Symfony\Component\DependencyInjection\ContainerBuilder; @@ -61,27 +62,13 @@ class ContainerBuilderTest extends \PHPUnit_Framework_TestCase public function testCreateDeprecatedService() { - $deprecations = array(); - set_error_handler(function ($type, $msg) use (&$deprecations) { - if (E_USER_DEPRECATED !== $type) { - restore_error_handler(); + ErrorAssert::assertDeprecationsAreTriggered('The "deprecated_foo" service is deprecated. You should stop using it, as it will soon be removed.', function () { + $definition = new Definition('stdClass'); + $definition->setDeprecated(true); - return call_user_func_array('PHPUnit_Util_ErrorHandler::handleError', func_get_args()); - } - - $deprecations[] = $msg; + $builder = new ContainerBuilder(); + $builder->createService($definition, 'deprecated_foo'); }); - - $definition = new Definition('stdClass'); - $definition->setDeprecated(true); - - $builder = new ContainerBuilder(); - $builder->createService($definition, 'deprecated_foo'); - - restore_error_handler(); - - $this->assertCount(1, $deprecations); - $this->assertContains('The "deprecated_foo" service is deprecated. You should stop using it, as it will soon be removed.', $deprecations[0]); } public function testRegister() diff --git a/src/Symfony/Component/Yaml/Tests/ParserTest.php b/src/Symfony/Component/Yaml/Tests/ParserTest.php index 0152e07ffe..7b36819535 100644 --- a/src/Symfony/Component/Yaml/Tests/ParserTest.php +++ b/src/Symfony/Component/Yaml/Tests/ParserTest.php @@ -11,6 +11,7 @@ namespace Symfony\Component\Yaml\Tests; +use Symfony\Bridge\PhpUnit\ErrorAssert; use Symfony\Component\Yaml\Yaml; use Symfony\Component\Yaml\Parser; @@ -930,27 +931,14 @@ EOF; */ public function testColonInMappingValueException() { - $yaml = <<parser; + + ErrorAssert::assertDeprecationsAreTriggered('Using a colon in the unquoted mapping value "bar: baz" in line 1 is deprecated since Symfony 2.8 and will throw a ParseException in 3.0.', function () use ($parser) { + $yaml = <<parse($yaml); }); - - $this->parser->parse($yaml); - - restore_error_handler(); - - $this->assertCount(1, $deprecations); - $this->assertContains('Using a colon in the unquoted mapping value "bar: baz" in line 1 is deprecated since Symfony 2.8 and will throw a ParseException in 3.0.', $deprecations[0]); } public function testColonInMappingValueExceptionNotTriggeredByColonInComment() From 8da9a387d73f150c65c82613e1cd13986bcd7ca6 Mon Sep 17 00:00:00 2001 From: Nicolas Grekas Date: Thu, 16 Jun 2016 10:27:19 +0200 Subject: [PATCH 4/4] Tweak merge --- src/Symfony/Component/Yaml/Tests/ParserTest.php | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/src/Symfony/Component/Yaml/Tests/ParserTest.php b/src/Symfony/Component/Yaml/Tests/ParserTest.php index 7801ae69a5..cb6bc4b234 100644 --- a/src/Symfony/Component/Yaml/Tests/ParserTest.php +++ b/src/Symfony/Component/Yaml/Tests/ParserTest.php @@ -931,13 +931,12 @@ EOF; */ public function testColonInMappingValueException() { - $parser = $this->parser; - - ErrorAssert::assertDeprecationsAreTriggered('Using a colon in the unquoted mapping value "bar: baz" in line 1 is deprecated since Symfony 2.8 and will throw a ParseException in 3.0.', function () use ($parser) { + ErrorAssert::assertDeprecationsAreTriggered('Using a colon in the unquoted mapping value "bar: baz" in line 1 is deprecated since Symfony 2.8 and will throw a ParseException in 3.0.', function () { $yaml = <<parse($yaml); + + $this->parser->parse($yaml); }); }