Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

[PhpUnitBridge] add a triggered errors assertion helper#18880

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged
fabpot merged 1 commit intosymfony:masterfromxabbuh:error-assert
Jun 15, 2016

Conversation

@xabbuh
Copy link
Member

QA
Branch?master
Bug fix?no
New feature?yes
BC breaks?no
Deprecations?no
Tests pass?yes
Fixed tickets
LicenseMIT
Doc PR

In the past, we updated the test code several times that made sure that deprecation messages are triggered. I think we should move this code to a reusable class in the PhpUnitBridge to make it available everywhere and to be able to change a single method in case we need to update the logic.

theofidry, linaori, HeahDude, GuilhemN, and Koc reacted with thumbs up emoji
@xabbuh
Copy link
MemberAuthor

@nicolas-grekas Any idea why thedeps=low build is failing?

@GuilhemN
Copy link
Contributor

@xabbuh the phpunit-bridge is not required in several composer files such the one of the framework bundle (https://github.com/symfony/symfony/blob/master/src/Symfony/Bundle/FrameworkBundle/composer.json).

@GuilhemN
Copy link
Contributor

Anyway the tests probably won't pass as long as this isn't merged.

*/
final class ErrorAssert
{
public static function assertDeprecationsAreTriggered($expectedMessages, callable $testCode)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

should we use singular here?assertDeprecationIsTriggered or anything likesetExpectedException ?

setExpectedDeprecation ?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

Given that the method takes an array of expected messages, plural is fine.

setExpectedDeprecation is not fine for the current API. It would work if the method was register the expectation to check it later after running the test, but this is not what happens in the current API.

Copy link
Contributor

@OskarStarkOskarStarkMay 31, 2016
edited
Loading

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

Given that the method takes an array of expected messages, plural is fine.

Ok fine, but do we have many cases where we assert many deprecations?
https://github.com/symfony/symfony/pull/18880/files/b8fcced6cd5b6f324e85c232fbb853f514fe8ea3#diff-ecb644500d31b54f3fa4574298dc6156R537

setExpectedDeprecation is not fine for the current API. It would work if the method was register the expectation to check it later after running the test, but this is not what happens in the current API.

👍

@stof
Copy link
Member

@Ener-Getick we have a special phpunit launcher performing a local composer-based installation of PHPUnit (to remove unnecessary dependency which would hurt us, for instancesymfony/yaml as we don't want to run tests on the version shipped in PHPUnit and we don't use the PHPUnit feature needing it). This special wrapper includes the bridge in the phpunit installation.

@stof
Copy link
Member

@xabbuh looks like the PHPUnit setup installed the 3.1.0-beta1 version of the bridge, and so does not use the updated version of the bridge:https://travis-ci.org/symfony/symfony/jobs/133035973#L578

@GuilhemN
Copy link
Contributor

@stof thanks for the explanation, I didn't know that.

$triggeredMessages[] = $message;
});

$testCode();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

What about putting the entire function in a try/finally structure in case an exception is thrown ?

try {// ...}finally {restore_error_handler();}

nicolas-grekas reacted with thumbs up emoji
Copy link
MemberAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

done

@fabpot
Copy link
Member

ping@nicolas-grekas

$triggeredMessages = array();

set_error_handler(function ($type, $message) use ($expectedType, &$triggeredMessages) {
if ($expectedType !== $type) {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

shouldn't this be a bitfield?

Copy link
MemberAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

I don't think that that would be a good idea. I think if you really need to test for different kind of errors, you should probably rethink your code or write your own assertion code.

@xabbuhxabbuhforce-pushed theerror-assert branch 5 times, most recently from6458c99 toec0464cCompareJune 14, 2016 12:09
@nicolas-grekas
Copy link
Member

👍

$triggeredMessages[] = $message;
});

$testCode();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

Isn't it safer to usecall_user_func here as well ?

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

Nope: no code has been written that can't be run. Having it here since the beginning will enforce this forever.

Copy link
Contributor

@GuilhemNGuilhemNJun 14, 2016
edited
Loading

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

so we won't accept other callables than closure ?

Edit: if yes, then we should change the typehint toclosure

Copy link
MemberAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

@Ener-Getick But that would mean to drop support for other callables that are not anonymous functions.

Copy link
Contributor

@GuilhemNGuilhemNJun 14, 2016
edited
Loading

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

@xabbuh indeed sorry, let's forget it, I thought the syntax$bar() only worked with closures...

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

I suggest doing$testCode($this) to ease writing tests in 5.3

Copy link
Contributor

@GuilhemNGuilhemNJun 14, 2016
edited
Loading

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

@nicolas-grekas the class is static.

Edit: or did you mean adding it to the method signature ?

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

I forgot it is static :)

*/
public static function assertDeprecationsAreTriggered($expectedMessages, $testCode)
{
if (!is_callable($testCode)) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

useless here as will be checked in the second function anyway

Copy link
MemberAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

That's true but I'd like to keep it here too for two reasons: Do not confuse users by letting them deal with exceptions that have been thrown by methods they did not call if we cannot avoid that. Secondly, mitigate the risk of breaking anything if we refactor the method that we call here.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

ok fine for me :)

@nicolas-grekas
Copy link
Member

Status: reviewed

@fabpot
Copy link
Member

Thank you@xabbuh.

@fabpotfabpot merged commitb5c2095 intosymfony:masterJun 15, 2016
fabpot added a commit that referenced this pull requestJun 15, 2016
…r (xabbuh)This PR was merged into the 3.2-dev branch.Discussion----------[PhpUnitBridge] add a triggered errors assertion helper| Q             | A| ------------- | ---| Branch?       | master| Bug fix?      | no| New feature?  | yes| BC breaks?    | no| Deprecations? | no| Tests pass?   | yes| Fixed tickets || License       | MIT| Doc PR        |In the past, we updated the test code several times that made sure that deprecation messages are triggered. I think we should move this code to a reusable class in the PhpUnitBridge to make it available everywhere and to be able to change a single method in case we need to update the logic.Commits-------b5c2095 add a triggered errors assertion helper
@xabbuhxabbuh deleted the error-assert branchJune 15, 2016 19:52
fabpot added a commit that referenced this pull requestOct 21, 2016
…cation` (nicolas-grekas)This PR was merged into the 3.2-dev branch.Discussion----------[PhpUnitBridge] Replace ErrorAssert by `@expectedDeprecation`| Q             | A| ------------- | ---| Branch?       | 3.2| Bug fix?      | no| New feature?  | yes| BC breaks?    | no| Deprecations? | no| Tests pass?   | yes| Fixed tickets |#18880| License       | MIT| Doc PR        |symfony/symfony-docs#7074For 3.2, that's what the feat. freeze is for in this case. ping@xabbuhSeehttps://github.com/symfony/symfony/pull/20255/files?w=1Commits-------c344203 [PhpUnitBridge] Drop ErrorAssert in favor of @expectedDeprecation
@fabpotfabpot mentioned this pull requestOct 27, 2016
Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment

Reviewers

No reviews

Assignees

No one assigned

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

7 participants

@xabbuh@GuilhemN@stof@fabpot@nicolas-grekas@OskarStark@carsonbot

[8]ページ先頭

©2009-2025 Movatter.jp