[3.1][PhpUnitBridge] Drop ErrorAssert in favor of @expectedDeprecation

This commit is contained in:
Nicolas Grekas 2016-10-20 15:28:37 +02:00
parent a01cc6d8c4
commit 5735255467
6 changed files with 34 additions and 51 deletions

View File

@ -11,7 +11,6 @@
namespace Symfony\Bundle\FrameworkBundle\Tests\DependencyInjection; namespace Symfony\Bundle\FrameworkBundle\Tests\DependencyInjection;
use Symfony\Bridge\PhpUnit\ErrorAssert;
use Symfony\Bundle\FrameworkBundle\Tests\TestCase; use Symfony\Bundle\FrameworkBundle\Tests\TestCase;
use Symfony\Bundle\FrameworkBundle\DependencyInjection\FrameworkExtension; use Symfony\Bundle\FrameworkBundle\DependencyInjection\FrameworkExtension;
use Symfony\Component\Cache\Adapter\ApcuAdapter; use Symfony\Component\Cache\Adapter\ApcuAdapter;
@ -547,16 +546,17 @@ abstract class FrameworkExtensionTest extends TestCase
/** /**
* @group legacy * @group legacy
* @requires function Symfony\Bridge\PhpUnit\ErrorAssert::assertDeprecationsAreTriggered * @expectedDeprecation The "framework.serializer.cache" option is deprecated %s.
*/ */
public function testDeprecatedSerializerCacheOption() public function testDeprecatedSerializerCacheOption()
{ {
ErrorAssert::assertDeprecationsAreTriggered('The "framework.serializer.cache" option is deprecated', function () { $container = $this->createContainerFromFile('serializer_legacy_cache', array('kernel.debug' => true, 'kernel.container_class' => __CLASS__));
$container = $this->createContainerFromFile('serializer_legacy_cache', array('kernel.debug' => true, 'kernel.container_class' => __CLASS__));
$this->assertFalse($container->hasDefinition('serializer.mapping.cache_class_metadata_factory')); $this->assertFalse($container->hasDefinition('serializer.mapping.cache_class_metadata_factory'));
$this->assertEquals(new Reference('foo'), $container->getDefinition('serializer.mapping.class_metadata_factory')->getArgument(1)); $this->assertTrue($container->hasDefinition('serializer.mapping.class_metadata_factory'));
});
$cache = $container->getDefinition('serializer.mapping.class_metadata_factory')->getArgument(1);
$this->assertEquals(new Reference('foo'), $cache);
} }
public function testAssetHelperWhenAssetsAreEnabled() public function testAssetHelperWhenAssetsAreEnabled()

View File

@ -11,7 +11,6 @@
namespace Symfony\Bundle\FrameworkBundle\Tests\Templating; namespace Symfony\Bundle\FrameworkBundle\Tests\Templating;
use Symfony\Bridge\PhpUnit\ErrorAssert;
use Symfony\Bundle\FrameworkBundle\Tests\TestCase; use Symfony\Bundle\FrameworkBundle\Tests\TestCase;
use Symfony\Bundle\FrameworkBundle\Templating\TemplateNameParser; use Symfony\Bundle\FrameworkBundle\Templating\TemplateNameParser;
use Symfony\Bundle\FrameworkBundle\Templating\TemplateReference; use Symfony\Bundle\FrameworkBundle\Templating\TemplateReference;
@ -86,17 +85,15 @@ class TemplateNameParserTest extends TestCase
/** /**
* @group legacy * @group legacy
* @dataProvider provideAbsolutePaths * @dataProvider provideAbsolutePaths
* @requires function Symfony\Bridge\PhpUnit\ErrorAssert::assertDeprecationsAreTriggered * @expectedDeprecation Absolute template path support is deprecated since Symfony 3.1 and will be removed in 4.0.
*/ */
public function testAbsolutePathsAreDeprecated($name, $logicalName, $path, $ref) public function testAbsolutePathsAreDeprecated($name, $logicalName, $path, $ref)
{ {
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);
$template = $this->parser->parse($name);
$this->assertSame($ref->getLogicalName(), $template->getLogicalName()); $this->assertSame($ref->getLogicalName(), $template->getLogicalName());
$this->assertSame($logicalName, $template->getLogicalName()); $this->assertSame($logicalName, $template->getLogicalName());
$this->assertSame($path, $template->getPath()); $this->assertSame($path, $template->getPath());
});
} }
public function provideAbsolutePaths() public function provideAbsolutePaths()

View File

@ -14,7 +14,6 @@ namespace Symfony\Component\DependencyInjection\Tests;
require_once __DIR__.'/Fixtures/includes/classes.php'; require_once __DIR__.'/Fixtures/includes/classes.php';
require_once __DIR__.'/Fixtures/includes/ProjectExtension.php'; require_once __DIR__.'/Fixtures/includes/ProjectExtension.php';
use Symfony\Bridge\PhpUnit\ErrorAssert;
use Symfony\Component\Config\Resource\ResourceInterface; use Symfony\Component\Config\Resource\ResourceInterface;
use Symfony\Component\DependencyInjection\Alias; use Symfony\Component\DependencyInjection\Alias;
use Symfony\Component\DependencyInjection\ContainerBuilder; use Symfony\Component\DependencyInjection\ContainerBuilder;
@ -59,18 +58,18 @@ class ContainerBuilderTest extends \PHPUnit_Framework_TestCase
} }
/** /**
* @requires function Symfony\Bridge\PhpUnit\ErrorAssert::assertDeprecationsAreTriggered * @group legacy
* @expectedDeprecation The "deprecated_foo" service is deprecated. You should stop using it, as it will soon be removed.
*/ */
public function testCreateDeprecatedService() public function testCreateDeprecatedService()
{ {
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 = new Definition('stdClass'); $definition->setDeprecated(true);
$definition->setDeprecated(true);
$builder = new ContainerBuilder(); $builder = new ContainerBuilder();
$builder->setDefinition('deprecated_foo', $definition); $builder->setDefinition('deprecated_foo', $definition);
$builder->get('deprecated_foo'); $builder->compile();
}); $builder->get('deprecated_foo');
} }
public function testRegister() public function testRegister()

View File

@ -11,7 +11,6 @@
namespace Symfony\Component\DependencyInjection\Tests\Loader; namespace Symfony\Component\DependencyInjection\Tests\Loader;
use Symfony\Bridge\PhpUnit\ErrorAssert;
use Symfony\Component\DependencyInjection\ContainerInterface; use Symfony\Component\DependencyInjection\ContainerInterface;
use Symfony\Component\DependencyInjection\ContainerBuilder; use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\DependencyInjection\Reference; use Symfony\Component\DependencyInjection\Reference;
@ -558,23 +557,17 @@ class XmlFileLoaderTest extends \PHPUnit_Framework_TestCase
/** /**
* @group legacy * @group legacy
* @requires function Symfony\Bridge\PhpUnit\ErrorAssert::assertDeprecationsAreTriggered * @expectedDeprecation Using the attribute "class" is deprecated for the service "bar" which is defined as an alias %s.
* @expectedDeprecation Using the element "tag" is deprecated for the service "bar" which is defined as an alias %s.
* @expectedDeprecation Using the element "factory" is deprecated for the service "bar" which is defined as an alias %s.
*/ */
public function testAliasDefinitionContainsUnsupportedElements() public function testAliasDefinitionContainsUnsupportedElements()
{ {
$deprecations = array( $container = new ContainerBuilder();
'Using the attribute "class" is deprecated for the service "bar" which is defined as an alias', $loader = new XmlFileLoader($container, new FileLocator(self::$fixturesPath.'/xml'));
'Using the element "tag" is deprecated for the service "bar" which is defined as an alias',
'Using the element "factory" is deprecated for the service "bar" which is defined as an alias',
);
ErrorAssert::assertDeprecationsAreTriggered($deprecations, function () { $loader->load('legacy_invalid_alias_definition.xml');
$container = new ContainerBuilder();
$loader = new XmlFileLoader($container, new FileLocator(self::$fixturesPath.'/xml'));
$loader->load('legacy_invalid_alias_definition.xml'); $this->assertTrue($container->has('bar'));
$this->assertTrue($container->has('bar'));
});
} }
} }

View File

@ -11,7 +11,6 @@
namespace Symfony\Component\HttpKernel\Tests\Fragment; namespace Symfony\Component\HttpKernel\Tests\Fragment;
use Symfony\Bridge\PhpUnit\ErrorAssert;
use Symfony\Component\HttpKernel\Controller\ControllerReference; use Symfony\Component\HttpKernel\Controller\ControllerReference;
use Symfony\Component\HttpKernel\Fragment\EsiFragmentRenderer; use Symfony\Component\HttpKernel\Fragment\EsiFragmentRenderer;
use Symfony\Component\HttpKernel\HttpCache\Esi; use Symfony\Component\HttpKernel\HttpCache\Esi;
@ -28,16 +27,14 @@ class EsiFragmentRendererTest extends \PHPUnit_Framework_TestCase
/** /**
* @group legacy * @group legacy
* @requires function Symfony\Bridge\PhpUnit\ErrorAssert::assertDeprecationsAreTriggered * @expectedDeprecation Passing non-scalar values as part of URI attributes to the ESI and SSI rendering strategies is deprecated %s.
*/ */
public function testRenderFallbackWithObjectAttributesIsDeprecated() public function testRenderFallbackWithObjectAttributesIsDeprecated()
{ {
ErrorAssert::assertDeprecationsAreTriggered('Passing non-scalar values 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'));
$strategy = new EsiFragmentRenderer(new Esi(), $this->getInlineStrategy(true), new UriSigner('foo')); $request = Request::create('/');
$request = Request::create('/'); $reference = new ControllerReference('main_controller', array('foo' => array('a' => array(), 'b' => new \stdClass())), array());
$reference = new ControllerReference('main_controller', array('foo' => array('a' => array(), 'b' => new \stdClass())), array()); $strategy->render($reference, $request);
$strategy->render($reference, $request);
});
} }
public function testRender() public function testRender()

View File

@ -11,7 +11,6 @@
namespace Symfony\Component\Yaml\Tests; namespace Symfony\Component\Yaml\Tests;
use Symfony\Bridge\PhpUnit\ErrorAssert;
use Symfony\Component\Yaml\Inline; use Symfony\Component\Yaml\Inline;
use Symfony\Component\Yaml\Yaml; use Symfony\Component\Yaml\Yaml;
@ -255,14 +254,12 @@ class InlineTest extends \PHPUnit_Framework_TestCase
/** /**
* @group legacy * @group legacy
* @requires function Symfony\Bridge\PhpUnit\ErrorAssert::assertDeprecationsAreTriggered * @expectedDeprecation Not quoting the scalar "%bar " starting with the "%" indicator character is deprecated since Symfony 3.1 and will throw a ParseException in 4.0.
* throws \Symfony\Component\Yaml\Exception\ParseException in 4.0 * throws \Symfony\Component\Yaml\Exception\ParseException in 4.0
*/ */
public function testParseUnquotedScalarStartingWithPercentCharacter() public function testParseUnquotedScalarStartingWithPercentCharacter()
{ {
ErrorAssert::assertDeprecationsAreTriggered('Not quoting the scalar "%foo " starting with the "%" indicator character is deprecated since Symfony 3.1 and will throw a ParseException in 4.0.', function () { Inline::parse('{ foo: %bar }');
Inline::parse('{ foo: %foo }');
});
} }
/** /**