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

Skip to content

[FrameworkBundle] fix BC-breaking property in WebTestAssertionsTrait #31880

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

Merged
merged 1 commit into from
Jun 6, 2019

Conversation

nicolas-grekas
Copy link
Member

Q A
Branch? 4.3
Bug fix? yes
New feature? no
BC breaks? no
Deprecations? no
Tests pass? yes
Fixed tickets #31653
License MIT
Doc PR -

No properties should be exposed.

@nicolas-grekas
Copy link
Member Author

nicolas-grekas commented Jun 5, 2019

Why is this a trait BTW, and not plain methods on WebTestCase?
Unless I missed it, #30813 doesn't tell about that, does it?

@OskarStark
Copy link
Contributor

I can’t remember why, maybe @Pierstoval can help us

@Pierstoval
Copy link
Contributor

The trait was not discussed, I thought it was convenient to have all assertions in one place, especially when needing them statically. A fix to make the client static in the trait is welcomed, indeed.

@nicolas-grekas nicolas-grekas force-pushed the fix-webtestassertionstrait branch from 835280b to 3b50107 Compare June 6, 2019 06:53
@nicolas-grekas nicolas-grekas force-pushed the fix-webtestassertionstrait branch from 3b50107 to 6253926 Compare June 6, 2019 06:55
@@ -30,12 +30,12 @@ trait WebTestAssertionsTrait
{
public static function assertResponseIsSuccessful(string $message = ''): void
{
self::assertThat(static::getResponse(), new ResponseConstraint\ResponseIsSuccessful(), $message);
self::assertThat(self::getResponse(), new ResponseConstraint\ResponseIsSuccessful(), $message);
Copy link
Member Author

Choose a reason for hiding this comment

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

Traits should be self contained, we shouldn't provide these as extensibility points.

}

private static function getClient(): KernelBrowser
private static function getClient(KernelBrowser $newClient = null): ?KernelBrowser
Copy link
Contributor

Choose a reason for hiding this comment

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

Why would it return null? If the client is null, it should alway throw an exception, shouldn't it? If it's null, all the rest of the trait's codebase would be forced to check for null pointer 😕

Copy link
Member Author

Choose a reason for hiding this comment

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

related to my answer to your other comment: getClient(null) returns null

static::fail(\sprintf('A client must be set to make assertions on it. Did you forget to call "%s::createClient"?', __CLASS__));
static $client;

if (0 < \func_num_args()) {
Copy link
Contributor

Choose a reason for hiding this comment

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

What is the reason to not use if ($newClient) {?

Copy link
Member Author

Choose a reason for hiding this comment

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

Because we want to be able to reset the state using getClient(null), while getClient() shouldn't reset anything

Copy link
Contributor

Choose a reason for hiding this comment

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

Seems fair

@fabpot
Copy link
Member

fabpot commented Jun 6, 2019

Thank you @nicolas-grekas.

@fabpot fabpot merged commit 6253926 into symfony:4.3 Jun 6, 2019
fabpot added a commit that referenced this pull request Jun 6, 2019
…tionsTrait (nicolas-grekas)

This PR was merged into the 4.3 branch.

Discussion
----------

[FrameworkBundle] fix BC-breaking property in WebTestAssertionsTrait

| Q             | A
| ------------- | ---
| Branch?       | 4.3
| Bug fix?      | yes
| New feature?  | no
| BC breaks?    | no
| Deprecations? | no
| Tests pass?   | yes
| Fixed tickets | #31653
| License       | MIT
| Doc PR        | -

No properties should be exposed.

Commits
-------

6253926 [FrameworkBundle] fix BC-breaking property in WebTestAssertionsTrait
@nicolas-grekas nicolas-grekas deleted the fix-webtestassertionstrait branch June 6, 2019 08:36
@fabpot fabpot mentioned this pull request Jun 6, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants