Skip to content

Commit 4a15e66

Browse files
minor symfony#19067 [3.1] update tests to use the new error assertion helper (xabbuh)
This PR was merged into the 3.1 branch. Discussion ---------- [3.1] update tests to use the new error assertion helper | Q | A | ------------- | --- | Branch? | 3.1 | Bug fix? | no | New feature? | no | BC breaks? | no | Deprecations? | no | Tests pass? | yes | Fixed tickets | | License | MIT | Doc PR | Commits ------- 9c7512b update tests to use the new error assertion helper
2 parents aaa4039 + 9c7512b commit 4a15e66

File tree

6 files changed

+31
-94
lines changed

6 files changed

+31
-94
lines changed

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: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@
2121
use Symfony\Component\DependencyInjection\ContainerInterface;
2222
use Symfony\Component\DependencyInjection\Definition;
2323
use Symfony\Component\DependencyInjection\Exception\RuntimeException;
24-
use Symfony\Component\DependencyInjection\Exception\InactiveScopeException;
2524
use Symfony\Component\DependencyInjection\Exception\ServiceCircularReferenceException;
2625
use Symfony\Component\DependencyInjection\Exception\ServiceNotFoundException;
2726
use Symfony\Component\DependencyInjection\Loader\ClosureLoader;

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)