Skip to content

Commit

Permalink
Deprecate hamcrest/hamcrest-php package (#1245)
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 May 1, 2023
2 parents 53f21dc + 98f2dc9 commit 3587d5a
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 8 deletions.
2 changes: 1 addition & 1 deletion CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ To run the unit tests for Mockery, clone the git repository, download Composer u
the instructions at [http://getcomposer.org/download/](http://getcomposer.org/download/),
then install the dependencies with `php /path/to/composer.phar install`.

This will install the required PHPUnit and Hamcrest dev dependencies and create the
This will install the required dev dependencies and create the
autoload files required by the unit tests. You may run the `vendor/bin/phpunit` command
to run the unit tests. If everything goes to plan, there will be no failed tests!

Expand Down
2 changes: 1 addition & 1 deletion docs/getting_started/upgrading.rst
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ Read the documentation for a detailed overview of ":doc:`/reference/phpunit_inte
+++++++++++++++++++++++++++++++++++++++++

As of 1.0.0 the ``\Mockery\Matcher\MustBe`` matcher is deprecated and will be removed in
Mockery 2.0.0. We recommend instead to use the PHPUnit or Hamcrest equivalents of the
Mockery 2.0.0. We recommend instead to use the PHPUnit equivalents of the
MustBe matcher.

``allows`` and ``expects``
Expand Down
16 changes: 11 additions & 5 deletions library/Mockery/Configuration.php
Original file line number Diff line number Diff line change
Expand Up @@ -253,15 +253,21 @@ public function getObjectFormatter($class, $defaultFormatter)
*/
public function setDefaultMatcher($class, $matcherClass)
{
if (!is_a($matcherClass, \Mockery\Matcher\MatcherAbstract::class, true) &&
!is_a($matcherClass, \Hamcrest\Matcher::class, true) &&
!is_a($matcherClass, \Hamcrest_Matcher::class, true)
$isHamcrest = is_a($matcherClass, \Hamcrest\Matcher::class, true) || is_a($matcherClass, \Hamcrest_Matcher::class, true);
if (
!is_a($matcherClass, \Mockery\Matcher\MatcherAbstract::class, true) &&
!$isHamcrest
) {
throw new \InvalidArgumentException(
"Matcher class must be either Hamcrest matcher or extend \Mockery\Matcher\MatcherAbstract, " .
"'$matcherClass' given."
"Matcher class must extend \Mockery\Matcher\MatcherAbstract, " .
"'$matcherClass' given."
);
}

if ($isHamcrest) {
@trigger_error('Hamcrest package has been deprecated and will be removed in 2.0', E_USER_DEPRECATED);
}

$this->_defaultMatchers[$class] = $matcherClass;
}

Expand Down
2 changes: 2 additions & 0 deletions library/Mockery/Expectation.php
Original file line number Diff line number Diff line change
Expand Up @@ -399,6 +399,8 @@ protected function _matchArg($expected, &$actual)
return $expected->match($actual);
}
if ($expected instanceof \Hamcrest\Matcher || $expected instanceof \Hamcrest_Matcher) {
@trigger_error('Hamcrest package has been deprecated and will be removed in 2.0', E_USER_DEPRECATED);

return $expected->matches($actual);
}
return false;
Expand Down
2 changes: 1 addition & 1 deletion library/Mockery/Matcher/MustBe.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
namespace Mockery\Matcher;

/**
* @deprecated 2.0 Due to ambiguity, use Hamcrest or PHPUnit equivalents
* @deprecated 2.0 Due to ambiguity, use PHPUnit equivalents
*/
class MustBe extends MatcherAbstract
{
Expand Down

0 comments on commit 3587d5a

Please sign in to comment.