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

Merge into main #5656

6 changes: 6 additions & 0 deletions src/Framework/Constraint/Operator/LogicalNot.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,10 @@ public static function negate(string $string): string

preg_match('/(\'[\w\W]*\')([\w\W]*)("[\w\W]*")/i', $string, $matches);

if (count($matches) === 0) {
preg_match('/(\'[\w\W]*\')([\w\W]*)(\'[\w\W]*\')/i', $string, $matches);
}

$positives = array_map(
static fn (string $s) => '/\\b' . preg_quote($s, '/') . '/',
$positives,
Expand Down Expand Up @@ -101,6 +105,8 @@ public function precedence(): int
* Evaluates the constraint for parameter $other. Returns true if the
* constraint is met, false otherwise.
*
* @param mixed $other value or object to evaluate
*
* @throws ExpectationFailedException
*/
protected function matches(mixed $other): bool
Expand Down
32 changes: 32 additions & 0 deletions tests/unit/Framework/Assert/AssertNotEqualsTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<?php declare(strict_types=1);
/*
* This file is part of PHPUnit.
*
* (c) Sebastian Bergmann <[email protected]>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace PHPUnit\Framework;

use Exception;
use PHPUnit\Framework\Constraint\IsEqual;
use PHPUnit\Framework\Constraint\LogicalNot;

class AssertNotEqualsTest extends TestCase
{
public function testConfusingMessagesForLogicalNot(): void
{
$expectedMessage = "Failed asserting that 'test contains something' is not equal to 'test contains something'.";
$a = 'test contains something';
$b = 'test contains something';
$constraint = new LogicalNot(new IsEqual($a));

try {
Assert::assertThat($b, $constraint);
} catch (Exception $e) {
$actualMessage = $e->getMessage();
$this->assertSame($expectedMessage, $actualMessage);
}
}
}