Files
predis/tests/PHPUnit/ArrayHasSameValuesConstraint.php
T
Daniele Alessandri 36c9bb047e [tests] Start improving test suite.
- Make use of more typehints for function parameters
- Make use of typehints for function return values
- Use @var where needed to give proper hints to IDEs and avoid warnings
- Replace MockObject::setMethods() with addMethods() and onlyMethods()
- Rewording of some phpdocs
2020-09-01 13:58:14 +02:00

59 lines
1.1 KiB
PHP

<?php
/*
* This file is part of the Predis package.
*
* (c) Daniele Alessandri <suppakilla@gmail.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
/**
* PHPUnit constraint matching arrays with same elemnts even in different order.
*/
class ArrayHasSameValuesConstraint extends \PHPUnit\Framework\Constraint\Constraint
{
protected $array;
/**
* @param array $array
*/
public function __construct(array $array)
{
$this->array = $array;
}
/**
* {@inheritdoc}
*/
public function matches($other): bool
{
if (count($this->array) !== count($other)) {
return false;
}
if (array_diff($this->array, $other)) {
return false;
}
return true;
}
/**
* {@inheritdoc}
*/
public function toString(): string
{
return 'two arrays contain the same elements.';
}
/**
* {@inheritdoc}
*/
protected function failureDescription($other): string
{
return $this->toString();
}
}