Skip to content

Commit 9c7512b

Browse files
committed
update tests to use the new error assertion helper
1 parent 343c0da commit 9c7512b

File tree

7 files changed

+39
-115
lines changed

7 files changed

+39
-115
lines changed

phpunit

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ if (!file_exists("$PHPUNIT_DIR/phpunit-$PHPUNIT_VERSION/phpunit") || md5_file(__
5656
if (5.1 <= $PHPUNIT_VERSION && $PHPUNIT_VERSION < 5.4) {
5757
passthru("$COMPOSER require --no-update phpunit/phpunit-mock-objects \"~3.1.0\"");
5858
}
59-
passthru("$COMPOSER require --dev --no-update symfony/phpunit-bridge \">=3.1@dev\"");
59+
passthru("$COMPOSER require --dev --no-update symfony/phpunit-bridge \">=3.2@dev\"");
6060
passthru("$COMPOSER install --prefer-dist --no-progress --ansi", $exit);
6161
if ($exit) {
6262
exit($exit);

src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/FrameworkExtensionTest.php

Lines changed: 5 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111

1212
namespace Symfony\Bundle\FrameworkBundle\Tests\DependencyInjection;
1313

14+
use Symfony\Bridge\PhpUnit\ErrorAssert;
1415
use Symfony\Bundle\FrameworkBundle\Tests\TestCase;
1516
use Symfony\Bundle\FrameworkBundle\DependencyInjection\FrameworkExtension;
1617
use Symfony\Component\Cache\Adapter\ApcuAdapter;
@@ -541,25 +542,12 @@ public function testSerializerCacheDisabled()
541542
*/
542543
public function testDeprecatedSerializerCacheOption()
543544
{
544-
$deprecations = array();
545-
set_error_handler(function ($type, $msg) use (&$deprecations) {
546-
if (E_USER_DEPRECATED !== $type) {
547-
restore_error_handler();
545+
ErrorAssert::assertDeprecationsAreTriggered('The "framework.serializer.cache" option is deprecated', function () {
546+
$container = $this->createContainerFromFile('serializer_legacy_cache', array('kernel.debug' => true, 'kernel.container_class' => __CLASS__));
548547

549-
return call_user_func_array('PHPUnit_Util_ErrorHandler::handleError', func_get_args());
550-
}
551-
552-
$deprecations[] = $msg;
548+
$this->assertFalse($container->hasDefinition('serializer.mapping.cache_class_metadata_factory'));
549+
$this->assertEquals(new Reference('foo'), $container->getDefinition('serializer.mapping.class_metadata_factory')->getArgument(1));
553550
});
554-
555-
$container = $this->createContainerFromFile('serializer_legacy_cache', array('kernel.debug' => true, 'kernel.container_class' => __CLASS__));
556-
557-
restore_error_handler();
558-
559-
$this->assertCount(1, $deprecations);
560-
$this->assertContains('The "framework.serializer.cache" option is deprecated', $deprecations[0]);
561-
$this->assertFalse($container->hasDefinition('serializer.mapping.cache_class_metadata_factory'));
562-
$this->assertEquals(new Reference('foo'), $container->getDefinition('serializer.mapping.class_metadata_factory')->getArgument(1));
563551
}
564552

565553
public function testAssetHelperWhenAssetsAreEnabled()

src/Symfony/Bundle/FrameworkBundle/Tests/Templating/TemplateNameParserTest.php

Lines changed: 6 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111

1212
namespace Symfony\Bundle\FrameworkBundle\Tests\Templating;
1313

14+
use Symfony\Bridge\PhpUnit\ErrorAssert;
1415
use Symfony\Bundle\FrameworkBundle\Tests\TestCase;
1516
use Symfony\Bundle\FrameworkBundle\Templating\TemplateNameParser;
1617
use Symfony\Bundle\FrameworkBundle\Templating\TemplateReference;
@@ -88,26 +89,13 @@ public function testParseValidNameWithNotFoundBundle()
8889
*/
8990
public function testAbsolutePathsAreDeprecated($name, $logicalName, $path, $ref)
9091
{
91-
$deprecations = array();
92-
set_error_handler(function ($type, $msg) use (&$deprecations) {
93-
if (E_USER_DEPRECATED !== $type) {
94-
restore_error_handler();
92+
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) {
93+
$template = $this->parser->parse($name);
9594

96-
return call_user_func_array('PHPUnit_Util_ErrorHandler::handleError', func_get_args());
97-
}
98-
99-
$deprecations[] = $msg;
95+
$this->assertSame($ref->getLogicalName(), $template->getLogicalName());
96+
$this->assertSame($logicalName, $template->getLogicalName());
97+
$this->assertSame($path, $template->getPath());
10098
});
101-
102-
$template = $this->parser->parse($name);
103-
104-
restore_error_handler();
105-
106-
$this->assertSame($ref->getLogicalName(), $template->getLogicalName());
107-
$this->assertSame($logicalName, $template->getLogicalName());
108-
$this->assertSame($path, $template->getPath());
109-
$this->assertCount(1, $deprecations);
110-
$this->assertContains('Absolute template path support is deprecated since Symfony 3.1 and will be removed in 4.0.', $deprecations[0]);
11199
}
112100

113101
public function provideAbsolutePaths()

src/Symfony/Component/DependencyInjection/Tests/ContainerBuilderTest.php

Lines changed: 7 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,13 @@
1414
require_once __DIR__.'/Fixtures/includes/classes.php';
1515
require_once __DIR__.'/Fixtures/includes/ProjectExtension.php';
1616

17+
use Symfony\Bridge\PhpUnit\ErrorAssert;
1718
use Symfony\Component\Config\Resource\ResourceInterface;
1819
use Symfony\Component\DependencyInjection\Alias;
1920
use Symfony\Component\DependencyInjection\ContainerBuilder;
2021
use Symfony\Component\DependencyInjection\ContainerInterface;
2122
use Symfony\Component\DependencyInjection\Definition;
2223
use Symfony\Component\DependencyInjection\Exception\RuntimeException;
23-
use Symfony\Component\DependencyInjection\Exception\InactiveScopeException;
2424
use Symfony\Component\DependencyInjection\Exception\ServiceCircularReferenceException;
2525
use Symfony\Component\DependencyInjection\Exception\ServiceNotFoundException;
2626
use Symfony\Component\DependencyInjection\Loader\ClosureLoader;
@@ -60,28 +60,14 @@ public function testDefinitions()
6060

6161
public function testCreateDeprecatedService()
6262
{
63-
$deprecations = array();
64-
set_error_handler(function ($type, $msg) use (&$deprecations) {
65-
if (E_USER_DEPRECATED !== $type) {
66-
restore_error_handler();
63+
ErrorAssert::assertDeprecationsAreTriggered('The "deprecated_foo" service is deprecated. You should stop using it, as it will soon be removed.', function () {
64+
$definition = new Definition('stdClass');
65+
$definition->setDeprecated(true);
6766

68-
return call_user_func_array('PHPUnit_Util_ErrorHandler::handleError', func_get_args());
69-
}
70-
71-
$deprecations[] = $msg;
67+
$builder = new ContainerBuilder();
68+
$builder->setDefinition('deprecated_foo', $definition);
69+
$builder->get('deprecated_foo');
7270
});
73-
74-
$definition = new Definition('stdClass');
75-
$definition->setDeprecated(true);
76-
77-
$builder = new ContainerBuilder();
78-
$builder->setDefinition('deprecated_foo', $definition);
79-
$builder->get('deprecated_foo');
80-
81-
restore_error_handler();
82-
83-
$this->assertCount(1, $deprecations);
84-
$this->assertContains('The "deprecated_foo" service is deprecated. You should stop using it, as it will soon be removed.', $deprecations[0]);
8571
}
8672

8773
public function testRegister()

src/Symfony/Component/DependencyInjection/Tests/Loader/XmlFileLoaderTest.php

Lines changed: 11 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111

1212
namespace Symfony\Component\DependencyInjection\Tests\Loader;
1313

14+
use Symfony\Bridge\PhpUnit\ErrorAssert;
1415
use Symfony\Component\DependencyInjection\ContainerInterface;
1516
use Symfony\Component\DependencyInjection\ContainerBuilder;
1617
use Symfony\Component\DependencyInjection\Exception\InvalidArgumentException;
@@ -546,29 +547,19 @@ public function testAutowire()
546547
*/
547548
public function testAliasDefinitionContainsUnsupportedElements()
548549
{
549-
$container = new ContainerBuilder();
550-
$loader = new XmlFileLoader($container, new FileLocator(self::$fixturesPath.'/xml'));
550+
$deprecations = array(
551+
'Using the attribute "class" is deprecated for alias definition "bar"',
552+
'Using the element "tag" is deprecated for alias definition "bar"',
553+
'Using the element "factory" is deprecated for alias definition "bar"',
554+
);
551555

552-
$deprecations = array();
553-
set_error_handler(function ($type, $msg) use (&$deprecations) {
554-
if (E_USER_DEPRECATED !== $type) {
555-
restore_error_handler();
556+
ErrorAssert::assertDeprecationsAreTriggered($deprecations, function () {
557+
$container = new ContainerBuilder();
558+
$loader = new XmlFileLoader($container, new FileLocator(self::$fixturesPath.'/xml'));
556559

557-
return call_user_func_array('PHPUnit_Util_ErrorHandler::handleError', func_get_args());
558-
}
560+
$loader->load('legacy_invalid_alias_definition.xml');
559561

560-
$deprecations[] = $msg;
562+
$this->assertTrue($container->has('bar'));
561563
});
562-
563-
$loader->load('legacy_invalid_alias_definition.xml');
564-
565-
restore_error_handler();
566-
567-
$this->assertTrue($container->has('bar'));
568-
569-
$this->assertCount(3, $deprecations);
570-
$this->assertContains('Using the attribute "class" is deprecated for alias definition "bar"', $deprecations[0]);
571-
$this->assertContains('Using the element "tag" is deprecated for alias definition "bar"', $deprecations[1]);
572-
$this->assertContains('Using the element "factory" is deprecated for alias definition "bar"', $deprecations[2]);
573564
}
574565
}

src/Symfony/Component/HttpKernel/Tests/Fragment/EsiFragmentRendererTest.php

Lines changed: 6 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111

1212
namespace Symfony\Component\HttpKernel\Tests\Fragment;
1313

14+
use Symfony\Bridge\PhpUnit\ErrorAssert;
1415
use Symfony\Component\HttpKernel\Controller\ControllerReference;
1516
use Symfony\Component\HttpKernel\Fragment\EsiFragmentRenderer;
1617
use Symfony\Component\HttpKernel\HttpCache\Esi;
@@ -30,29 +31,12 @@ public function testRenderFallbackToInlineStrategyIfEsiNotSupported()
3031
*/
3132
public function testRenderFallbackWithObjectAttributesIsDeprecated()
3233
{
33-
$deprecations = array();
34-
set_error_handler(function ($type, $message) use (&$deprecations) {
35-
if (E_USER_DEPRECATED !== $type) {
36-
restore_error_handler();
37-
38-
return call_user_func_array('PHPUnit_Util_ErrorHandler::handleError', func_get_args());
39-
}
40-
41-
$deprecations[] = $message;
34+
ErrorAssert::assertDeprecationsAreTriggered('Passing objects as part of URI attributes to the ESI and SSI rendering strategies is deprecated', function () {
35+
$strategy = new EsiFragmentRenderer(new Esi(), $this->getInlineStrategy(true), new UriSigner('foo'));
36+
$request = Request::create('/');
37+
$reference = new ControllerReference('main_controller', array('foo' => array('a' => array(), 'b' => new \stdClass())), array());
38+
$strategy->render($reference, $request);
4239
});
43-
44-
$strategy = new EsiFragmentRenderer(new Esi(), $this->getInlineStrategy(true), new UriSigner('foo'));
45-
46-
$request = Request::create('/');
47-
48-
$reference = new ControllerReference('main_controller', array('foo' => array('a' => array(), 'b' => new \stdClass())), array());
49-
50-
$strategy->render($reference, $request);
51-
52-
restore_error_handler();
53-
54-
$this->assertCount(1, $deprecations);
55-
$this->assertContains('Passing objects as part of URI attributes to the ESI and SSI rendering strategies is deprecated', $deprecations[0]);
5640
}
5741

5842
public function testRender()

src/Symfony/Component/Yaml/Tests/InlineTest.php

Lines changed: 3 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111

1212
namespace Symfony\Component\Yaml\Tests;
1313

14+
use Symfony\Bridge\PhpUnit\ErrorAssert;
1415
use Symfony\Component\Yaml\Inline;
1516
use Symfony\Component\Yaml\Yaml;
1617

@@ -258,23 +259,9 @@ public function getScalarIndicators()
258259
*/
259260
public function testParseUnquotedScalarStartingWithPercentCharacter()
260261
{
261-
$deprecations = array();
262-
set_error_handler(function ($type, $msg) use (&$deprecations) {
263-
if (E_USER_DEPRECATED !== $type) {
264-
restore_error_handler();
265-
266-
return call_user_func_array('PHPUnit_Util_ErrorHandler::handleError', func_get_args());
267-
}
268-
269-
$deprecations[] = $msg;
262+
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 () {
263+
Inline::parse('{ foo: %foo }');
270264
});
271-
272-
Inline::parse('{ foo: %foo }');
273-
274-
restore_error_handler();
275-
276-
$this->assertCount(1, $deprecations);
277-
$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]);
278265
}
279266

280267
/**

0 commit comments

Comments
 (0)