-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
[PhpUnitBridge] Add the ability to expect a deprecation inside a test #35192
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of the Symfony package. | ||
* | ||
* (c) Fabien Potencier <[email protected]> | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
namespace Symfony\Bridge\PhpUnit; | ||
|
||
use Symfony\Bridge\PhpUnit\Legacy\SymfonyTestsListenerTrait; | ||
|
||
trait ExpectDeprecationTrait | ||
{ | ||
/** | ||
* @param string $message | ||
* | ||
* @return void | ||
*/ | ||
protected function expectDeprecation($message) | ||
{ | ||
if (!SymfonyTestsListenerTrait::$previousErrorHandler) { | ||
SymfonyTestsListenerTrait::$previousErrorHandler = set_error_handler([SymfonyTestsListenerTrait::class, 'handleError']); | ||
} | ||
|
||
SymfonyTestsListenerTrait::$expectedDeprecations[] = $message; | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of the Symfony package. | ||
* | ||
* (c) Fabien Potencier <[email protected]> | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
namespace Symfony\Bridge\PhpUnit\Tests; | ||
|
||
use PHPUnit\Framework\TestCase; | ||
use Symfony\Bridge\PhpUnit\ExpectDeprecationTrait; | ||
|
||
final class ExpectDeprecationTraitTest extends TestCase | ||
{ | ||
use ExpectDeprecationTrait; | ||
|
||
/** | ||
* Do not remove this test in the next major version. | ||
* | ||
* @group legacy | ||
*/ | ||
public function testOne() | ||
{ | ||
$this->expectDeprecation('foo'); | ||
@trigger_error('foo', E_USER_DEPRECATED); | ||
} | ||
|
||
/** | ||
* Do not remove this test in the next major version. | ||
* | ||
* @group legacy | ||
*/ | ||
public function testMany() | ||
{ | ||
$this->expectDeprecation('foo'); | ||
$this->expectDeprecation('bar'); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. To actually test that the feature is working, we would also need to write tests where Of course, this must not be part of the main Symfony testsuite run (here, you are writing tests as if they were testing |
||
@trigger_error('foo', E_USER_DEPRECATED); | ||
@trigger_error('bar', E_USER_DEPRECATED); | ||
} | ||
|
||
/** | ||
* Do not remove this test in the next major version. | ||
* | ||
* @group legacy | ||
* | ||
* @expectedDeprecation foo | ||
*/ | ||
public function testOneWithAnnotation() | ||
{ | ||
$this->expectDeprecation('bar'); | ||
@trigger_error('foo', E_USER_DEPRECATED); | ||
@trigger_error('bar', E_USER_DEPRECATED); | ||
} | ||
|
||
/** | ||
* Do not remove this test in the next major version. | ||
* | ||
* @group legacy | ||
* | ||
* @expectedDeprecation foo | ||
* @expectedDeprecation bar | ||
*/ | ||
public function testManyWithAnnotation() | ||
{ | ||
$this->expectDeprecation('ccc'); | ||
$this->expectDeprecation('fcy'); | ||
@trigger_error('foo', E_USER_DEPRECATED); | ||
@trigger_error('bar', E_USER_DEPRECATED); | ||
@trigger_error('ccc', E_USER_DEPRECATED); | ||
@trigger_error('fcy', E_USER_DEPRECATED); | ||
} | ||
} |
Uh oh!
There was an error while loading. Please reload this page.