mirror of
https://github.com/antonioribeiro/google2fa.git
synced 2026-04-26 00:25:52 +03:00
[GH-ISSUE #168] Bug in testing due to PHPUnit's interpretation #545
Labels
No labels
bug
pull-request
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
starred/google2fa#545
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Originally created by @alexw23 on GitHub (Jun 14, 2021).
Original GitHub issue: https://github.com/antonioribeiro/google2fa/issues/168
As was building some of my own tests I noticed that where you assert
verifyKeyNewershould be returning a timestamp, it actually returns a boolean.Take the following as an example of this (Source):
It turns out that if the "timestamp" is empty
verifyKeyNewerreturnstruenot a timestamp.And PHPunit for some reason considers these both to be equal, for some reason I have no idea.
The following example also works:
Just thought I would report this in an effort to have any expectation of how it should be working clarified.
Edit: looks like you need to be using
assertSame.@thinkverse commented on GitHub (Oct 20, 2021):
I know it's been a long time since this issue was open. But just to clarify that PHPUnit's interpretation is not wrong here.
It's interpreting the assertion correctly,
26213400is a truthy value in PHP. ThereforeassetEqualswill returntruesince a truthy value is equal to true in PHP. UsingassertSamewill fail however since the expectation and the actual value aren't of the same type, they are both truthy but one is anintand the other is aboolean.Boiled down, PHPUnit's
assertEqualsis a non-strict equality check in PHP (==),assertSamewould be a strict equality check (===).This can be seen if you try and write it out the checks yourself in plain PHP, as demonstrated here.