Tools for helping in test development.
Allows you to introduce mocks in tested method through an iterable mock object in an easy way.
Example:
use PcComponentes\Ddd\Testing\Util\PhpUnit\IterableMockTrait;
use PHPUnit\Framework\TestCase;
final class Testing extends TestCase
{
use IterableMockTrait;
public function testMethod()
{
$mockedItem1 = $this->createMock(\stdClass::class);
// Assertions in mock
$mockedItem2 = $this->createMock(\stdClass::class);
// Assertions in mock
$mockedIterator = $this->addIterableValuesToMock(
$this->createMock(\Iterator::class), // Your iterable mock
[
$mockedItem1,
$mockedItem2,
],
);
// ...
}
}
Allows you to simplify the serializable parametrization of a \JsonSerializable mock, making the code more semantic and easy to read.
Example:
use PcComponentes\Ddd\Testing\Util\PhpUnit\SerializableMockTrait;
use PHPUnit\Framework\TestCase;
final class Testing extends TestCase
{
use SerializableMockTrait;
public function testMethod()
{
$valueToReturnOnSerialize = 'some compatible with serialization method declared';
$serializableMock = $this->addJsonSerializationToMock(
$this->createMock(\JsonSerializable::class), // Your mock which implements jsonSerialize method
$this->once(), // Or other InvocationOrder
$valueToReturnOnSerialize,
);
// ...
}
}