diff --git a/CHANGELOG.md b/CHANGELOG.md index ff5f049bc..af09e9e09 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,7 @@ * Mock methods with static return types #1157 * Mock methods with mixed return type #1156 * Mock classes with new in initializers on PHP 8.1 #1160 +* Removes redundant PHPUnitConstraint #1158 ## 1.4.4 (2021-09-13) diff --git a/library/Mockery/Matcher/PHPUnitConstraint.php b/library/Mockery/Matcher/PHPUnitConstraint.php deleted file mode 100644 index 11874878e..000000000 --- a/library/Mockery/Matcher/PHPUnitConstraint.php +++ /dev/null @@ -1,76 +0,0 @@ -constraint = $constraint; - $this->rethrow = $rethrow; - } - - /** - * @param mixed $actual - * @return bool - */ - public function match(&$actual) - { - try { - $this->constraint->evaluate($actual); - return true; - } catch (\PHPUnit_Framework_AssertionFailedError $e) { - if ($this->rethrow) { - throw $e; - } - return false; - } catch (\PHPUnit\Framework\AssertionFailedError $e) { - if ($this->rethrow) { - throw $e; - } - return false; - } - } - - /** - * - */ - public function __toString() - { - return ''; - } -} diff --git a/tests/Mockery/Matcher/PHPUnitConstraintTest.php b/tests/Mockery/Matcher/PHPUnitConstraintTest.php deleted file mode 100644 index e66d01a1c..000000000 --- a/tests/Mockery/Matcher/PHPUnitConstraintTest.php +++ /dev/null @@ -1,95 +0,0 @@ -assertionFailedError = '\PHPUnit\Framework\AssertionFailedError'; - $this->frameworkConstraint = '\PHPUnit\Framework\Constraint'; - } else { - $this->assertionFailedError = '\PHPUnit_Framework_AssertionFailedError'; - $this->frameworkConstraint = '\PHPUnit_Framework_Constraint'; - } - - $this->constraint = \Mockery::mock($this->frameworkConstraint); - $this->matcher = new PHPUnitConstraint($this->constraint); - $this->rethrowingMatcher = new PHPUnitConstraint($this->constraint, true); - } - - public function testMatches() - { - $value1 = 'value1'; - $value2 = 'value1'; - $value3 = 'value1'; - $this->constraint - ->shouldReceive('evaluate') - ->once() - ->with($value1) - ->getMock() - ->shouldReceive('evaluate') - ->once() - ->with($value2) - ->andThrow($this->assertionFailedError) - ->getMock() - ->shouldReceive('evaluate') - ->once() - ->with($value3) - ->getMock() - ; - $this->assertTrue($this->matcher->match($value1)); - $this->assertFalse($this->matcher->match($value2)); - $this->assertTrue($this->rethrowingMatcher->match($value3)); - } - - public function testMatchesWhereNotMatchAndRethrowing() - { - $this->expectException($this->assertionFailedError); - $value = 'value'; - $this->constraint - ->shouldReceive('evaluate') - ->once() - ->with($value) - ->andThrow($this->assertionFailedError) - ; - $this->rethrowingMatcher->match($value); - } - - public function test__toString() - { - $this->assertEquals('', $this->matcher); - } -}