Skip to content
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

Use dedicated assertInstanceOf assertion #181

Merged
merged 1 commit into from
Dec 29, 2018
Merged

Use dedicated assertInstanceOf assertion #181

merged 1 commit into from
Dec 29, 2018

Conversation

carusogabriel
Copy link
Contributor

Using this dedicated assertion, we can have better error messages:

-$this->assertTrue($error instanceof \RuntimeException); // Failed asserting that false is true.
+$this->assertInstanceOf(\RuntimeException::class, $error); // Failed asserting that an object is an instance of class "RuntimeException".

Copy link
Member

@clue clue left a comment

Choose a reason for hiding this comment

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

@carusogabriel Thanks for filing this PR, I can see some use for this 👍

I'm currently undecided because this was actually done on purpose. While the assertInstanceOf() method does indeed provide some better error reporting in case of a test failure (is this a real issue here?), using instanceof aids with static analysis and IDEs, so that it "understands" the methods that are invoked after this check.

Just sharing my thoughts for now, I guess I'm okay with it either way.

@kelunik
Copy link
Contributor

kelunik commented Nov 12, 2018

At least PHPStorm also understands assertInstanceOf for static analysis IIRC.

@afk11
Copy link

afk11 commented Dec 24, 2018

@clue In general, IDE capabilities (which vary greatly from one to the other) shouldn't have a bearing on design decisions. Adding something like this after the assertion would preserve IDE's ability to carry out static analysis.

/** @var \RuntimeException $error */

Copy link
Member

@clue clue left a comment

Choose a reason for hiding this comment

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

@carusogabriel Thanks for looking into this and for your patience!

Changes LGTM, let's get this in :shipit: 👍

@WyriHaximus WyriHaximus merged commit 1218d5a into reactphp:master Dec 29, 2018
@clue clue added this to the v1.2.0 milestone Dec 29, 2018
@carusogabriel carusogabriel deleted the assert-instace-of branch December 29, 2018 17:29
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.

6 participants