Skip to content

Refactoring tests #188

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

Closed
wants to merge 1 commit into from
Closed

Refactoring tests #188

wants to merge 1 commit into from

Conversation

carusogabriel
Copy link
Contributor

I've refactored some tests, using:

  • assertCount instead of count function;
  • assertSame instead of strict comparisons ===;
  • assertArrayHasKey instead of isset function;
  • assertContains instead of in_array function;
  • assertInternalType and assertNotInternalType instead of is_* functions;
  • assertGreaterThan and assertGreaterThanOrEqual for mathematical comparisons;
  • assertEquals instead of comparisons ==.

@@ -185,13 +185,13 @@ public function testCreateValueBoolean()
$this->assertInstanceOf(PropertyInterface::class, $value);
$this->assertEquals(PropertyType::BOOLEAN, $value->getType(), 'wrong type');
$this->assertTrue($value->getBoolean(), 'boolean not true');
$this->assertTrue($value->getString() == true, 'wrong string value'); //boolean converted to string must be true
$this->assertEquals($value->getString(), true, 'wrong string value'); //boolean converted to string must be true
Copy link
Member

@dbu dbu Dec 7, 2017

Choose a reason for hiding this comment

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

i think this should be the other way round, with true being the first value. i guess assertTrue would check that the string is a boolean, which is not the case.

Copy link
Contributor Author

@carusogabriel carusogabriel Dec 7, 2017

Choose a reason for hiding this comment

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

Yep, you're right. In assertEquals, the first parameter is the $expected, in our case true, and the second one is the $actual, in our case $value->getString(). Gonna change it and search for similars.

@dbu
Copy link
Member

dbu commented Feb 28, 2018

uh, i did not merge that. looks like i missed the update when you fixed my comment. any chance that you can reopen the repository so i can merge this cleanup?

@carusogabriel
Copy link
Contributor Author

@dbu Sure. I'll use Rector this time to automate the process and find more cases. I'll reopen ASAP 😄

@dbu
Copy link
Member

dbu commented Feb 28, 2018

does rector have rules for phpunit that detect when a more specific assertion can be used?

@carusogabriel
Copy link
Contributor Author

@dbu Yes, it does. I created them myself, to automate this changes I was doing back in November/December last year.

@dbu
Copy link
Member

dbu commented Feb 28, 2018

extremely cool, i have some company project where this is direly needed \o/

@carusogabriel
Copy link
Contributor Author

So please contact @TomasVotruba, he'll help you, as he's the creator and founder of Rector.

I'm opening this PR again...

@carusogabriel carusogabriel mentioned this pull request Feb 28, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants