From e5cf4d424b741dd9418c4dd8efe3d2407581f375 Mon Sep 17 00:00:00 2001 From: Christian Flothmann Date: Tue, 14 Jun 2016 14:01:38 +0200 Subject: [PATCH] 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()