dosfarma / ddd-testing
1.0.1
2021-03-09 10:13 UTC
Requires
- phpunit/phpunit: ^8|^9
This package is auto-updated.
Last update: 2021-04-28 11:46:26 UTC
README
帮助测试开发的工具。
PcComponentes\Ddd\Testing\Util\PhpUnit\IterableMockTrait
允许您通过可迭代的模拟对象以简单的方式在测试方法中引入模拟。
使用
示例
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
允许您简化 \JsonSerializable 模拟的可序列化参数化,使代码更具语义性和易于阅读。
使用
示例
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, ); // ... } }