-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
Add ability to set expected deprecation message inside a test #25757
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
Conversation
Also, it nicely mirrors |
$this->error = new $AssertionFailedError('Only tests with the `@group legacy` annotation can have `@expectedDeprecation`.'); | ||
} | ||
|
||
$test->getTestResultObject()->beStrictAboutTestsThatDoNotTestAnything(false); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've moved this to end tests but because we reset the value using $this->reportUselessTests this code does not seem to have the intended affect and we still to add $this->addToAssertionCount(1);
to the test to make it not risky.
Note this is a new feature, so should target 4.1/master. |
/** | ||
* Sets an expected deprecation message. | ||
* | ||
* @param $msg |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
one line, missing type
8260080
to
da0d168
Compare
The current solution with have problems in isolated tests. |
@alexpott: Couldn't you port the changes you made in https://www.drupal.org/project/drupal/issues/2936802 over to this PR to address that? |
4.1.0 | ||
----- | ||
|
||
* support for adding expected deprecations via `SymfonyTestsListenerTrait::expectDeprecation()` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What about adding a new class to make this a bit more friendly,
eg SymfonyTestHelper::expectDeprecation()
at the root of the bridge's namespace?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Calling anything on a trait definitely smells.
Keeping it in sync with $this->expectDeprecation()
called inside tests would be the best imho.
ping? |
@alexpott , do you mind me finishing this? |
@vudaltsov not at all! That would be fantastic. |
…n inside a test (fancyweb) This PR was merged into the 5.1-dev branch. Discussion ---------- [PhpUnitBridge] Add the ability to expect a deprecation inside a test | Q | A | ------------- | --- | Branch? | master | Bug fix? | no | New feature? | yes | Deprecations? | no | Tickets | - | License | MIT | Doc PR | todo Replaces #25757 Proposed implementation uses a dedicated trait for a better DX. Using `$this->expectDeprecation()` feels natural. Unfortunately it is not currently possible to test the cases that should produce errors or risky, so there are some things that are not testable here. I plan to propose another feature for the PhpUnitBridge to be able to test those kind of things. If it's accepted, we will then be able to strenghten the tests of this one. Commits ------- a3a9280 [PhpUnitBridge] Add the ability to expect a deprecation inside a test
It could be useful to have the ability to dynamic set expected deprecations within tests. In https://www.drupal.org/project/drupal/issues/2858482 we are deprecating a lot of dynamically generated routes and these routes have tests that can't set an expected deprecation message because each test case has something like a provider which results in different deprecation messages.