Skip to content

Commit 500facc

Browse files
committed
update tests to use the new error assertion helper
1 parent 036ba15 commit 500facc

File tree

2 files changed

+11
-35
lines changed

2 files changed

+11
-35
lines changed

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()

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()

0 commit comments

Comments
 (0)