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

StringEndsWith matches too loosely (numeric strings) #3461

Closed
guilliamxavier opened this issue Jan 6, 2019 · 3 comments
Closed

StringEndsWith matches too loosely (numeric strings) #3461

guilliamxavier opened this issue Jan 6, 2019 · 3 comments

Comments

@guilliamxavier
Copy link
Contributor

@guilliamxavier guilliamxavier commented Jan 6, 2019

Q A
PHPUnit version 6.5.13
PHP version 7.2.10
Installation Method PHAR

PHPUnit incorrectly agrees that the string "zzz0E2" ends with "0E1"
(while it correctly disagrees that the string "0E2zzz" starts with "0E1").

Test:

<?php

class BugTest extends \PHPUnit\Framework\TestCase
{
    public function testStringStartsWith()
    {
        $this->assertStringStartsWith('0E1', '0E1zzz');
    }

    public function testStringStartsNotWith()
    {
        $this->assertStringStartsNotWith('0E1', '0E2zzz');
    }

    public function testStringEndsWith()
    {
        $this->assertStringEndsWith('0E1', 'zzz0E1');
    }

    public function testStringEndsNotWith()
    {
        $this->assertStringEndsNotWith('0E1', 'zzz0E2'); // ***
    }
}

Expected result:

PHPUnit 6.5.13 by Sebastian Bergmann and contributors.

....                                                                4 / 4 (100%)

Time: 142 ms, Memory: 8.00MB

OK (4 tests, 4 assertions)

Actual result:

PHPUnit 6.5.13 by Sebastian Bergmann and contributors.

...F                                                                4 / 4 (100%)

Time: 142 ms, Memory: 8.00MB

There was 1 failure:

1) BugTest::testStringEndsNotWith
Failed asserting that 'zzz0E2' ends not with "0E1".

/z/BugTest.php:22

FAILURES!
Tests: 4, Assertions: 4, Failures: 1.

Cause:
StringEndsWith::matches() (

return \substr($other, 0 - \strlen($this->suffix)) == $this->suffix;
) uses loose == but should use strict === ('0E2' == '0E1' is true but not '0E2' === '0E1').

@sebastianbergmann
Copy link
Owner

@sebastianbergmann sebastianbergmann commented Jan 6, 2019

Is this also the case for PHPUnit 7?

Loading

@guilliamxavier
Copy link
Contributor Author

@guilliamxavier guilliamxavier commented Jan 6, 2019

@sebastianbergmann Yes (6.5, 7.5, master, all have the issue)

Loading

@guilliamxavier guilliamxavier changed the title StringEndsWith matches too loosely StringEndsWith matches too loosely (numeric strings) Feb 1, 2019
@guilliamxavier
Copy link
Contributor Author

@guilliamxavier guilliamxavier commented Feb 19, 2019

This has been fixed in 7.5.5 / 8.0.3, thanks.

Loading

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
2 participants