Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Prevent
shouldNotReceive
from getting overridden (#1329)
Co-authored-by: Danny-Smart <113538899+Danny-Smart@users.noreply.github.com>
- Loading branch information
Showing
2 changed files
with
90 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
<?php | ||
|
||
namespace Mockery\Tests\Unit\Regression; | ||
|
||
use DateTime; | ||
use InvalidArgumentException; | ||
use Mockery; | ||
use Mockery\Exception\InvalidCountException; | ||
use Mockery\Expectation; | ||
use PHPUnit\Framework\TestCase; | ||
|
||
final class Issue1328Test extends TestCase | ||
{ | ||
public function testShouldFailWithAnInvocationCountError(): void | ||
{ | ||
$this->expectException(InvalidCountException::class); | ||
|
||
$mock = Mockery::mock(DateTime::class); | ||
|
||
$mock->shouldNotReceive("format"); | ||
|
||
$mock->format("Y"); | ||
|
||
Mockery::close(); | ||
} | ||
|
||
public function testThrowsInvalidArgumentExceptionWhenInvocationCountChanges(): void | ||
{ | ||
set_error_handler( | ||
static function (int $errorCode, string $errorMessage): void { | ||
restore_error_handler(); | ||
throw new InvalidArgumentException($errorMessage, $errorCode); | ||
}, | ||
E_ALL | ||
); | ||
|
||
$this->expectException(InvalidArgumentException::class); | ||
$this->expectExceptionMessage(Expectation::ERROR_ZERO_INVOCATION); | ||
|
||
$mock = Mockery::mock(DateTime::class); | ||
|
||
$mock->shouldNotReceive("format")->once(); | ||
|
||
$mock->format("Y"); | ||
|
||
Mockery::close(); | ||
} | ||
|
||
public function testThrowsInvalidArgumentExceptionForChainingAdditionalInvocationCountMethod(): void | ||
{ | ||
set_error_handler( | ||
static function (int $errorCode, string $errorMessage): void { | ||
restore_error_handler(); | ||
throw new InvalidArgumentException($errorMessage, $errorCode); | ||
}, | ||
E_ALL | ||
); | ||
|
||
$this->expectException(InvalidArgumentException::class); | ||
$this->expectExceptionMessage(Expectation::ERROR_ZERO_INVOCATION); | ||
|
||
$mock = Mockery::mock(DateTime::class); | ||
|
||
$mock->shouldNotReceive("format")->times(0); | ||
|
||
$mock->format("Y"); | ||
|
||
Mockery::close(); | ||
} | ||
} |