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

Fixed testsuite with sebastian/comparator release #29751

Merged
merged 8 commits into from Feb 23, 2023

Conversation

nicosomb
Copy link
Contributor

Questions Answers
Branch? 8.0.x
Description? With latest sebastian/comparator release, some tests failed.
Type? bug fix
Category? TE
BC breaks? no
Deprecations? no
Fixed ticket? Fixes #29652
Related PRs
How to test? Launch composer test-all
Possible impacts?

I tried to change code, but after reading some PR related to sebastianbergmann/comparator#102, I updated the testsuite. Tell me if it's ok for you.

(I don't like fix tests when there is a bug... I'd prefer fix the code)

@nicosomb nicosomb requested a review from a team as a code owner September 26, 2022 12:02
@prestonBot prestonBot added 8.0.x Branch Bug fix Type: Bug fix labels Sep 26, 2022
@nicosomb nicosomb requested review from FabienPapet, matks and atomiix and removed request for FabienPapet and matks October 31, 2022 12:24
@FabienPapet FabienPapet dismissed their stale review October 31, 2022 12:30

Ok for me as the application code is not updated.

FabienPapet
FabienPapet previously approved these changes Oct 31, 2022
kpodemski
kpodemski previously approved these changes Nov 11, 2022
Copy link
Contributor

@kpodemski kpodemski left a comment

Choose a reason for hiding this comment

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

It looks ok, and I've seen others making similar changes in their CI's.

One question tho, I think we should change sebastian/comparator version in the same PR, right?

@nicosomb
Copy link
Contributor Author

@PrestaShop/prestashop-core-developers I need your opinion on this PR please.

Copy link
Contributor

@matks matks left a comment

Choose a reason for hiding this comment

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

One question tho, I think we should change sebastian/comparator version in the same PR, right?

Good idea 💯

matks
matks previously approved these changes Nov 17, 2022
Copy link
Contributor

@jolelievre jolelievre left a comment

Choose a reason for hiding this comment

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

I personally am against this solution (explained in my comments), that's why use request changes but if you reach a global consensus don't hesitate to dismiss my review.

@@ -61,6 +61,6 @@ public function testGetTotalRateBug()

$totalRate = $tax_calculator->getTotalRate();

$this->assertEquals(27.233, $totalRate);
$this->assertEquals(27.232999999999997, $totalRate);
Copy link
Contributor

Choose a reason for hiding this comment

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

I don't quite agree with this solution 🤔 Nor do I agree with the modification made in PHPUnit
PHP imprecision is at fault here, not the code we developed so the expected value is indeed 27.233

Considering the problems of float computing we should be able to define an acceptable precision in our tests to avoid using such values which make no sense Besides what guaranties that one day it will not become 27.232999999999996 😅

In that sense I think PHPUnit previous loose check method made more sense.

Copy link
Contributor

Choose a reason for hiding this comment

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

Alternatively, we could use something like:

Suggested change
$this->assertEquals(27.232999999999997, $totalRate);
$this->assertEqualsWithDelta(27.233, $totalRate, PrestashopTestSettings::EPSILON);

At least it's explicit. But I don't know if this method is available on older PHPUnit version that are used for versions under PHP8 It's supposed to be available in PHPUnit 8.5 at least (which of course is not compatible with PHP 7.2 and 7.3) Maybe for inferior versions we can hook into PHPUnit to add our custom implementation like a polyfill

Copy link
Member

Choose a reason for hiding this comment

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

I don't know the specifics about this but it definitely looks like updating this like so is hiding a bug in tax calculation.

Copy link
Contributor

Choose a reason for hiding this comment

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

As discussed during our meeting the idea here is to introduce a new method to PHPUnit base class that can be used in any unit tests easily, it can be:

  • by adding a base class that extends the default TestCase
  • by creating a trait with the added method (advantage no need to change the default class to use the method, it can be used in integration tests as well without the need to have a base class for each type of unit/integration/... tests)

We need a method assertAlmostEquals assertEqualsWithEpsilon (not sure about the naming), internally it behaves as the previous assertEquals used to behave meaning for float values it accepts an offset based on the PHP const PHP_FLOAT_EPSILON

Copy link
Contributor

Choose a reason for hiding this comment

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

The goal is to keep the real expected values (which are correct the error comes from unprecise float approximation/rounding) but to use a method that explicitly allows less precision, this way we can identify which parts of our code will need to be refactored (probably using DecimalNumber)

@nicosomb
Copy link
Contributor Author

I improved the ExtendedTestCaseMethodsTrait file (not a big fan of the name, I know). The code looks better, but I still have to fix the ToolsTest class.

atomiix
atomiix previously approved these changes Feb 21, 2023
atomiix
atomiix previously approved these changes Feb 21, 2023
Copy link
Contributor

@jolelievre jolelievre left a comment

Choose a reason for hiding this comment

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

Just one final suggestion

tests/Resources/TestCase/ExtendedTestCaseMethodsTrait.php Outdated Show resolved Hide resolved
tests/Resources/TestCase/ExtendedTestCaseMethodsTrait.php Outdated Show resolved Hide resolved
Copy link
Contributor

@jolelievre jolelievre left a comment

Choose a reason for hiding this comment

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

Thanks @nicosomb

@nicosomb
Copy link
Contributor Author

@Progi1984
Copy link
Contributor

@nicosomb Errors in Automated Tests are OK. Don't worry ;)

@mflasquin
Copy link
Contributor

As you said @nicosomb go merge 😄 thank you

@mflasquin mflasquin merged commit c2e72f2 into PrestaShop:8.0.x Feb 23, 2023
@nicosomb nicosomb added this to the 8.0.2 milestone Feb 23, 2023
@nicosomb nicosomb deleted the fix-testsuite branch February 23, 2023 09:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
8.0.x Branch Bug fix Type: Bug fix
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

10 participants