Skip to content

Commit

Permalink
Trigger an error in patch and throw in next minor
Browse files Browse the repository at this point in the history
Signed-off-by: Nathanael Esayeas <nathanael.esayeas@protonmail.com>
  • Loading branch information
ghostwriter committed Aug 15, 2023
1 parent d828962 commit fe754a2
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 2 deletions.
8 changes: 7 additions & 1 deletion library/Mockery/Expectation.php
Expand Up @@ -19,6 +19,7 @@

class Expectation implements ExpectationInterface
{
public const ERROR_ZERO_INVOCATION = 'shouldNotReceive(), never(), times(0) chaining additional invocation count methods has been deprecated and will throw an exception in a future version of Mockery';
/**
* Mock object to which this expectation belongs
*
Expand Down Expand Up @@ -728,7 +729,12 @@ public function times($limit = null)
}

if ($this->_expectedCount === 0) {
throw new \InvalidArgumentException('\Mockery\Expectation::shouldNotReceive() method does not accept chaining additional invocation count methods.');
@trigger_error(self::ERROR_ZERO_INVOCATION, E_USER_DEPRECATED);
// throw new \InvalidArgumentException(self::ERROR_ZERO_INVOCATION);
}

if ($limit === 0) {
$this->_countValidators = [];
}

$this->_expectedCount = $limit;
Expand Down
21 changes: 20 additions & 1 deletion tests/Unit/Regression/Issue1328Test.php
@@ -1,11 +1,12 @@
<?php

namespace Mockery\Tests\Unit\Issues;
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
Expand All @@ -25,7 +26,16 @@ public function testShouldFailWithAnInvocationCountError(): void

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);

Expand All @@ -38,7 +48,16 @@ public function testThrowsInvalidArgumentExceptionWhenInvocationCountChanges():

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);

Expand Down

0 comments on commit fe754a2

Please sign in to comment.