pccomponentes / ddd-testing
Added test utils to ddd mini framework
Installs: 23 330
Dependents: 0
Suggesters: 0
Security: 0
Stars: 0
Watchers: 6
Forks: 3
Open Issues: 1
Requires
- phpunit/phpunit: ^8.5|^9
This package is auto-updated.
Last update: 2024-10-27 19:21:01 UTC
README
Tools for helping in test development.
PcComponentes\Ddd\Testing\Util\PhpUnit\IterableMockTrait
Allows you to introduce mocks in tested method through an iterable mock object in an easy way.
Use
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, ], ); // ... } }
PcComponentes\Ddd\Testing\Util\PhpUnit\SerializableMockTrait
Allows you to simplify the serializable parametrization of a \JsonSerializable mock, making the code more semantic and easy to read.
Use
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, ); // ... } }