diff --git a/src/Framework/Constraint/Operator/LogicalNot.php b/src/Framework/Constraint/Operator/LogicalNot.php index 86635a1ea51..aca799c3d79 100644 --- a/src/Framework/Constraint/Operator/LogicalNot.php +++ b/src/Framework/Constraint/Operator/LogicalNot.php @@ -49,6 +49,7 @@ 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); } diff --git a/tests/unit/Framework/Assert/AssertNotEqualsTest.php b/tests/unit/Framework/Assert/AssertNotEqualsTest.php index 499d3f7b344..45466e0aff2 100644 --- a/tests/unit/Framework/Assert/AssertNotEqualsTest.php +++ b/tests/unit/Framework/Assert/AssertNotEqualsTest.php @@ -1,21 +1,30 @@ - + * + * 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() + 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)); + $a = 'test contains something'; + $b = 'test contains something'; + $constraint = new LogicalNot(new IsEqual($a)); + try { Assert::assertThat($b, $constraint); - } catch (\Exception $e) { + } catch (Exception $e) { $actualMessage = $e->getMessage(); $this->assertSame($expectedMessage, $actualMessage); }