Additional functionality for PHPUnit (such as assertions).
Contents
- Requirements
- Usage
AssertionTraitassertLooselyIdentical($expected, $actual, $canonicalizeKeys = false)assertSameIterable(iterable $expected, $actual)assertLooselyIdenticalIterable(iterable $expected, $actual, $canonicalizeKeys = false)assertEqualIterable(iterable $expected, $actual)looselyIdenticalTo($value, $canonicalizeKeys = false)identicalIterable(iterable $expected)looselyIdenticalIterable(iterable $expected, $canonicalizeKeys = false)equalIterable(iterable $expected)
ClockTrait
- PHP 7.1+
This trait exposes additional assertion methods to your test case.
<?phpnamespaceAcme;
useKuria\PhpUnitExtras\Traits\AssertionTrait;
usePHPUnit\Framework\TestCase;
class ExampleTest extends TestCase
{
use AssertionTrait;
functiontestFooBar()
{
$this->assertEqualIterable([1, 2, 3], new \ArrayObject([1, 2, 3]));
}
}Assert that two values have the same type and value, but consider different instances of the same class identical as long as they have identical properties.
If $canonicalizeKeys = TRUE, then array key order is ignored.
Assert that two iterables contain the same values and types in the same order
Types are compared the same way as with the === operator.
Assert that two iterables contain the same values and types in the same order, but consider different instances of the same class identical as long as they have identical properties.
If $canonicalizeKeys = TRUE, then array key order is ignored.
Assert that two iterables contain equal values in any order
Types are compared the same way as with the == operator.
Create the IsLooselyIdentical constraint. See assertLooselyIdentical().
Create the IsIdenticalIterable constraint. See assertSameIterable().
Create the IsLooselyIdenticalIterable constraint. See assertLooselyIdenticalIterable().
Create the IsEqualIterable constraint. See assertEqualIterable().
Mock current time in tests.
Only affects code that uses the kuria/clock component.
<?phpnamespaceAcme;
useKuria\PhpUnitExtras\Traits\ClockTrait;
usePHPUnit\Framework\TestCase;
class ExampleTest extends TestCase
{
use ClockTrait;
functiontestFooBar()
{
$this->atTime(1535904500, function () {
// some code that uses Kuria/Clock/Clock
});
}
}