Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Use expectException method instead of deprecated annotation #13377

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 19 additions & 10 deletions components/phpunit_bridge.rst
Original file line number Diff line number Diff line change
Expand Up @@ -215,21 +215,30 @@ Write Assertions about Deprecations

When adding deprecations to your code, you might like writing tests that verify
that they are triggered as required. To do so, the bridge provides the
``@expectedDeprecation`` annotation that you can use on your test methods.
:method:`Symfony\\Bridge\\PhpUnit\\ExpectDeprecationTrait::expectDeprecation` method that you can use on your test methods.
It requires you to pass the expected message, given in the same format as for
the `PHPUnit's assertStringMatchesFormat()`_ method. If you expect more than one
deprecation message for a given test method, you can use the annotation several
deprecation message for a given test method, you can use the method several
times (order matters)::

/**
* @group legacy
* @expectedDeprecation This "%s" method is deprecated.
* @expectedDeprecation The second argument of the "%s" method is deprecated.
*/
public function testDeprecatedCode()
use PHPUnit\Framework\TestCase;
use Symfony\Bridge\PhpUnit\ExpectDeprecationTrait;

class MyTest extends TestCase
{
@trigger_error('This "Foo" method is deprecated.', E_USER_DEPRECATED);
@trigger_error('The second argument of the "Bar" method is deprecated.', E_USER_DEPRECATED);
use ExpectDeprecationTrait;

/**
* @group legacy
*/
public function testDeprecatedCode()
{
$this->expectDeprecation("This "%s" method is deprecated.");
$this->expectDeprecation("The second argument of the "%s" method is deprecated.");

@trigger_error('This "Foo" method is deprecated.', E_USER_DEPRECATED);
@trigger_error('The second argument of the "Bar" method is deprecated.', E_USER_DEPRECATED);
}
}

Time-sensitive Tests
Expand Down