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

Replace usage of deprecated $canonicalize phpunit parameter #238

Merged
merged 7 commits into from Jul 1, 2019
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
24 changes: 14 additions & 10 deletions exercises/allergies/allergies_test.php
Expand Up @@ -7,6 +7,8 @@ class AllergiesTest extends PHPUnit\Framework\TestCase

/**
* @dataProvider provideListOfAllergen
*
* @param Allergen $allergen
*/
public function testNoAllergiesMeansNotAllergicToAnything($allergen)
{
Expand All @@ -17,6 +19,8 @@ public function testNoAllergiesMeansNotAllergicToAnything($allergen)

/**
* @dataProvider provideListOfAllergen
*
* @param Allergen $allergicTo
*/
public function testAllergiesToOneAllergen($allergicTo)
{
Expand All @@ -26,7 +30,7 @@ public function testAllergiesToOneAllergen($allergicTo)
$otherAllergen = array_filter(Allergen::allergenList(), function ($allergen) use ($allergicTo) {
return $allergen != $allergicTo;
});
$self = $this;
$self = $this;
Copy link
Contributor

Choose a reason for hiding this comment

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

Please can we remove this temporary variable $self, as it's no longer necessary

array_map(function ($allergen) use ($allergies, $self) {
$self->assertFalse($allergies->isAllergicTo($allergen));
Copy link
Contributor

Choose a reason for hiding this comment

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

hmm this is weird, passing $self through here, not sure why it isn't just $this->assertFalse() inside the closure 🤔

Copy link
Contributor

Choose a reason for hiding this comment

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

Prior to PHP 5.4 $this wasn't bound automatically inside anonymous functions, so it was possibly written with that in mind? The test was originally written in 2016, when 5.4 had only just reached it's end of life and keeping PHP up to date wasn't as common.

It should probably be removed now, however, as 5.4 has been EOL'd for four years.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Let me know if you guys want me to remove this :)

Also: Hi Ross! :P

Copy link
Contributor

Choose a reason for hiding this comment

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

I think it makes sense to remove it, as it's bad practice now and the tests are something students should be looking at while they're working through a problem.

Thoughts @petemcfarlane?

Copy link
Contributor

Choose a reason for hiding this comment

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

Yeah 💯

Copy link
Contributor Author

Choose a reason for hiding this comment

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

If you guys want this change, could you please request it? (i.e review with "changes requested")

/cc @DerTee

}, $otherAllergen);
Expand Down Expand Up @@ -58,48 +62,48 @@ public function testIsAllergicToLotsOfStuffs()
{
$allergies = new Allergies(248);

$this->assertEquals([
$this->assertEqualsCanonicalizing([
new Allergen(Allergen::CATS),
new Allergen(Allergen::CHOCOLATE),
new Allergen(Allergen::POLLEN),
new Allergen(Allergen::STRAWBERRIES),
new Allergen(Allergen::TOMATOES),
], $allergies->getList(), "\$canonicalize = true", $delta = 0.0, $maxDepth = 10, $canonicalize = true);
], $allergies->getList());
}

public function testIsAllergicToEggsAndPeanuts()
{
$allergies = new Allergies(3);

$this->assertEquals([
$this->assertEqualsCanonicalizing([
new Allergen(Allergen::EGGS),
new Allergen(Allergen::PEANUTS),
], $allergies->getList(), "\$canonicalize = true", $delta = 0.0, $maxDepth = 10, $canonicalize = true);
], $allergies->getList());
}

public function testIsAllergicToEgssAndShellfish()
public function testIsAllergicToEggsAndShellfish()
{
$allergies = new Allergies(5);

$this->assertEquals([
$this->assertEqualsCanonicalizing([
new Allergen(Allergen::EGGS),
new Allergen(Allergen::SHELLFISH),
], $allergies->getList(), "\$canonicalize = true", $delta = 0.0, $maxDepth = 10, $canonicalize = true);
], $allergies->getList());
}

public function testIgnoreNonAllergenScorePart()
{
$allergies = new Allergies(509);

$this->assertEquals([
$this->assertEqualsCanonicalizing([
new Allergen(Allergen::CATS),
new Allergen(Allergen::CHOCOLATE),
new Allergen(Allergen::EGGS),
new Allergen(Allergen::POLLEN),
new Allergen(Allergen::SHELLFISH),
new Allergen(Allergen::STRAWBERRIES),
new Allergen(Allergen::TOMATOES),
], $allergies->getList(), "\$canonicalize = true", $delta = 0.0, $maxDepth = 10, $canonicalize = true);
], $allergies->getList());
}

/**
Expand Down
10 changes: 3 additions & 7 deletions exercises/grade-school/grade-school_test.php
Expand Up @@ -23,21 +23,17 @@ public function testAddStudent()
$this->assertContains('Claire', $this->school->grade(2));
}

public function testAddStudentsinSameGrade()
public function testAddStudentsInSameGrade()
{
$this->school->add("Marc", 2);
$this->school->add("Virginie", 2);
$this->school->add("Claire", 2);

$students = $this->school->grade(2) ;
$this->assertCount(3, $students);
$this->assertEquals(
$this->assertEqualsCanonicalizing(
['Claire', 'Marc', 'Virginie'],
$students,
$message = '',
$delta = 0.0,
$maxDepth = 10,
$canonicalize = true
$students
);
}

Expand Down