Skip to content

Commit

Permalink
Refactor library/Mockery/Matcher/* (#1389)
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 Mar 6, 2024
2 parents c02e11d + a651505 commit ee709e1
Show file tree
Hide file tree
Showing 22 changed files with 382 additions and 279 deletions.
25 changes: 14 additions & 11 deletions library/Mockery/Matcher/AndAnyOtherArgs.php
Expand Up @@ -4,32 +4,35 @@
* Mockery (https://docs.mockery.io/)
*
* @copyright https://github.com/mockery/mockery/blob/HEAD/COPYRIGHT.md
* @license https://github.com/mockery/mockery/blob/HEAD/LICENSE BSD 3-Clause License
* @link https://github.com/mockery/mockery for the canonical source repository
* @license https://github.com/mockery/mockery/blob/HEAD/LICENSE BSD 3-Clause License
* @link https://github.com/mockery/mockery for the canonical source repository
*/

namespace Mockery\Matcher;

class AndAnyOtherArgs extends MatcherAbstract
{
/**
* Check if the actual value matches the expected.
* Return a string representation of this Matcher
*
* @param mixed $actual
* @return bool
* @return string
*/
public function match(&$actual)
public function __toString()
{
return true;
return '<AndAnyOthers>';
}

/**
* Return a string representation of this Matcher
* Check if the actual value matches the expected.
*
* @return string
* @template TMixed
*
* @param TMixed $actual
*
* @return bool
*/
public function __toString()
public function match(&$actual)
{
return '<AndAnyOthers>';
return true;
}
}
25 changes: 14 additions & 11 deletions library/Mockery/Matcher/Any.php
Expand Up @@ -4,32 +4,35 @@
* Mockery (https://docs.mockery.io/)
*
* @copyright https://github.com/mockery/mockery/blob/HEAD/COPYRIGHT.md
* @license https://github.com/mockery/mockery/blob/HEAD/LICENSE BSD 3-Clause License
* @link https://github.com/mockery/mockery for the canonical source repository
* @license https://github.com/mockery/mockery/blob/HEAD/LICENSE BSD 3-Clause License
* @link https://github.com/mockery/mockery for the canonical source repository
*/

namespace Mockery\Matcher;

class Any extends MatcherAbstract
{
/**
* Check if the actual value matches the expected.
* Return a string representation of this Matcher
*
* @param mixed $actual
* @return bool
* @return string
*/
public function match(&$actual)
public function __toString()
{
return true;
return '<Any>';
}

/**
* Return a string representation of this Matcher
* Check if the actual value matches the expected.
*
* @return string
* @template TMixed
*
* @param TMixed $actual
*
* @return bool
*/
public function __toString()
public function match(&$actual)
{
return '<Any>';
return true;
}
}
21 changes: 11 additions & 10 deletions library/Mockery/Matcher/AnyArgs.php
Expand Up @@ -4,27 +4,28 @@
* Mockery (https://docs.mockery.io/)
*
* @copyright https://github.com/mockery/mockery/blob/HEAD/COPYRIGHT.md
* @license https://github.com/mockery/mockery/blob/HEAD/LICENSE BSD 3-Clause License
* @link https://github.com/mockery/mockery for the canonical source repository
* @license https://github.com/mockery/mockery/blob/HEAD/LICENSE BSD 3-Clause License
* @link https://github.com/mockery/mockery for the canonical source repository
*/

namespace Mockery\Matcher;

class AnyArgs extends MatcherAbstract implements ArgumentListMatcher
{
/**
* @inheritdoc
*/
public function match(&$actual)
public function __toString()
{
return true;
return '<Any Arguments>';
}

/**
* @inheritdoc
* @template TMixed
*
* @param TMixed $actual
*
* @return bool
*/
public function __toString()
public function match(&$actual)
{
return '<Any Arguments>';
return true;
}
}
29 changes: 17 additions & 12 deletions library/Mockery/Matcher/AnyOf.php
Expand Up @@ -4,33 +4,38 @@
* Mockery (https://docs.mockery.io/)
*
* @copyright https://github.com/mockery/mockery/blob/HEAD/COPYRIGHT.md
* @license https://github.com/mockery/mockery/blob/HEAD/LICENSE BSD 3-Clause License
* @link https://github.com/mockery/mockery for the canonical source repository
* @license https://github.com/mockery/mockery/blob/HEAD/LICENSE BSD 3-Clause License
* @link https://github.com/mockery/mockery for the canonical source repository
*/

namespace Mockery\Matcher;

use function in_array;

class AnyOf extends MatcherAbstract
{
/**
* Check if the actual value does not match the expected (in this
* case it's specifically NOT expected).
* Return a string representation of this Matcher
*
* @param mixed $actual
* @return bool
* @return string
*/
public function match(&$actual)
public function __toString()
{
return in_array($actual, $this->_expected, true);
return '<AnyOf>';
}

/**
* Return a string representation of this Matcher
* Check if the actual value does not match the expected (in this
* case it's specifically NOT expected).
*
* @return string
* @template TMixed
*
* @param TMixed $actual
*
* @return bool
*/
public function __toString()
public function match(&$actual)
{
return '<AnyOf>';
return in_array($actual, $this->_expected, true);

Check failure on line 39 in library/Mockery/Matcher/AnyOf.php

View workflow job for this annotation

GitHub Actions / Psalm

InvalidArgument

library/Mockery/Matcher/AnyOf.php:39:34: InvalidArgument: Argument 2 of in_array expects array<array-key, mixed>, but Mockery\Matcher\TExpected provided (see https://psalm.dev/004)
}
}
4 changes: 2 additions & 2 deletions library/Mockery/Matcher/ArgumentListMatcher.php
Expand Up @@ -4,8 +4,8 @@
* Mockery (https://docs.mockery.io/)
*
* @copyright https://github.com/mockery/mockery/blob/HEAD/COPYRIGHT.md
* @license https://github.com/mockery/mockery/blob/HEAD/LICENSE BSD 3-Clause License
* @link https://github.com/mockery/mockery for the canonical source repository
* @license https://github.com/mockery/mockery/blob/HEAD/LICENSE BSD 3-Clause License
* @link https://github.com/mockery/mockery for the canonical source repository
*/

namespace Mockery\Matcher;
Expand Down
27 changes: 14 additions & 13 deletions library/Mockery/Matcher/Closure.php
Expand Up @@ -4,34 +4,35 @@
* Mockery (https://docs.mockery.io/)
*
* @copyright https://github.com/mockery/mockery/blob/HEAD/COPYRIGHT.md
* @license https://github.com/mockery/mockery/blob/HEAD/LICENSE BSD 3-Clause License
* @link https://github.com/mockery/mockery for the canonical source repository
* @license https://github.com/mockery/mockery/blob/HEAD/LICENSE BSD 3-Clause License
* @link https://github.com/mockery/mockery for the canonical source repository
*/

namespace Mockery\Matcher;

class Closure extends MatcherAbstract
{
/**
* Check if the actual value matches the expected.
* Return a string representation of this Matcher
*
* @param mixed $actual
* @return bool
* @return string
*/
public function match(&$actual)
public function __toString()
{
$closure = $this->_expected;
$result = $closure($actual);
return $result === true;
return '<Closure===true>';
}

/**
* Return a string representation of this Matcher
* Check if the actual value matches the expected.
*
* @return string
* @template TMixed
*
* @param TMixed $actual
*
* @return bool
*/
public function __toString()
public function match(&$actual)
{
return '<Closure===true>';
return ($this->_expected)($actual) === true;

Check failure on line 36 in library/Mockery/Matcher/Closure.php

View workflow job for this annotation

GitHub Actions / Psalm

InvalidFunctionCall

library/Mockery/Matcher/Closure.php:36:16: InvalidFunctionCall: Cannot treat type Mockery\Matcher\TExpected as callable (see https://psalm.dev/064)
}
}
44 changes: 25 additions & 19 deletions library/Mockery/Matcher/Contains.php
Expand Up @@ -4,18 +4,40 @@
* Mockery (https://docs.mockery.io/)
*
* @copyright https://github.com/mockery/mockery/blob/HEAD/COPYRIGHT.md
* @license https://github.com/mockery/mockery/blob/HEAD/LICENSE BSD 3-Clause License
* @link https://github.com/mockery/mockery for the canonical source repository
* @license https://github.com/mockery/mockery/blob/HEAD/LICENSE BSD 3-Clause License
* @link https://github.com/mockery/mockery for the canonical source repository
*/

namespace Mockery\Matcher;

use function array_values;
use function implode;

class Contains extends MatcherAbstract
{
/**
* Return a string representation of this Matcher
*
* @return string
*/
public function __toString()
{
$return = '<Contains[';
$elements = [];
foreach ($this->_expected as $v) {

Check failure on line 27 in library/Mockery/Matcher/Contains.php

View workflow job for this annotation

GitHub Actions / Psalm

UndefinedClass

library/Mockery/Matcher/Contains.php:27:18: UndefinedClass: Class, interface or enum named Mockery\Matcher\TExpected does not exist (see https://psalm.dev/019)
$elements[] = (string) $v;
}
$return .= implode(', ', $elements) . ']>';
return $return;
}

/**
* Check if the actual value matches the expected.
*
* @param mixed $actual
* @template TMixed
*
* @param TMixed $actual
*
* @return bool
*/
public function match(&$actual)
Expand All @@ -35,20 +57,4 @@ public function match(&$actual)
}
return true;
}

/**
* Return a string representation of this Matcher
*
* @return string
*/
public function __toString()
{
$return = '<Contains[';
$elements = array();
foreach ($this->_expected as $v) {
$elements[] = (string) $v;
}
$return .= implode(', ', $elements) . ']>';
return $return;
}
}
37 changes: 22 additions & 15 deletions library/Mockery/Matcher/Ducktype.php
Expand Up @@ -4,40 +4,47 @@
* Mockery (https://docs.mockery.io/)
*
* @copyright https://github.com/mockery/mockery/blob/HEAD/COPYRIGHT.md
* @license https://github.com/mockery/mockery/blob/HEAD/LICENSE BSD 3-Clause License
* @link https://github.com/mockery/mockery for the canonical source repository
* @license https://github.com/mockery/mockery/blob/HEAD/LICENSE BSD 3-Clause License
* @link https://github.com/mockery/mockery for the canonical source repository
*/

namespace Mockery\Matcher;

use function implode;
use function is_object;
use function method_exists;

class Ducktype extends MatcherAbstract
{
/**
* Return a string representation of this Matcher
*
* @return string
*/
public function __toString()
{
return '<Ducktype[' . implode(', ', $this->_expected) . ']>';

Check failure on line 26 in library/Mockery/Matcher/Ducktype.php

View workflow job for this annotation

GitHub Actions / Psalm

InvalidArgument

library/Mockery/Matcher/Ducktype.php:26:45: InvalidArgument: Argument 2 of implode expects array<array-key, null|object{__tostring()}|scalar>, but Mockery\Matcher\TExpected provided (see https://psalm.dev/004)
}

/**
* Check if the actual value matches the expected.
*
* @param mixed $actual
* @template TMixed
*
* @param TMixed $actual
*
* @return bool
*/
public function match(&$actual)
{
if (!is_object($actual)) {
if (! is_object($actual)) {
return false;
}
foreach ($this->_expected as $method) {

Check failure on line 43 in library/Mockery/Matcher/Ducktype.php

View workflow job for this annotation

GitHub Actions / Psalm

UndefinedClass

library/Mockery/Matcher/Ducktype.php:43:18: UndefinedClass: Class, interface or enum named Mockery\Matcher\TExpected does not exist (see https://psalm.dev/019)
if (!method_exists($actual, $method)) {
if (! method_exists($actual, $method)) {
return false;
}
}
return true;
}

/**
* Return a string representation of this Matcher
*
* @return string
*/
public function __toString()
{
return '<Ducktype[' . implode(', ', $this->_expected) . ']>';
}
}

0 comments on commit ee709e1

Please sign in to comment.