diff --git a/README.md b/README.md index 82589e0..a85dbd0 100644 --- a/README.md +++ b/README.md @@ -26,7 +26,7 @@ A simple deserialization. ## Requirements * php: ^8.2 - * chubbyphp/chubbyphp-decode-encode: ^1.1 + * chubbyphp/chubbyphp-decode-encode: ^1.2 * psr/http-message: ^1.1|^2.0 * psr/log: ^2.0|^3.0.2 diff --git a/composer.json b/composer.json index 1cd541d..c5cef62 100644 --- a/composer.json +++ b/composer.json @@ -14,26 +14,26 @@ "ext-dom": "*", "ext-json": "*", "ext-mbstring": "*", - "chubbyphp/chubbyphp-decode-encode": "^1.1", + "chubbyphp/chubbyphp-decode-encode": "^1.2", "psr/http-message": "^1.1|^2.0", "psr/log": "^2.0|^3.0.2" }, "require-dev": { - "chubbyphp/chubbyphp-container": "^2.2", + "chubbyphp/chubbyphp-container": "^2.3", "chubbyphp/chubbyphp-dev-helper": "dev-master", - "chubbyphp/chubbyphp-laminas-config-factory": "^1.3", - "chubbyphp/chubbyphp-mock": "^1.8", + "chubbyphp/chubbyphp-laminas-config-factory": "^1.4", + "chubbyphp/chubbyphp-mock": "^2.0@dev", "doctrine/collections": "^2.2.2", "doctrine/persistence": "^4.0", - "infection/infection": "^0.29.8", + "infection/infection": "^0.29.13", "php-coveralls/php-coveralls": "^2.7.0", "phpstan/extension-installer": "^1.4.3", - "phpstan/phpstan": "^2.0.3", - "phpunit/phpunit": "^11.5.0", + "phpstan/phpstan": "^2.1.6", + "phpunit/phpunit": "^11.5.10", "pimple/pimple": "^3.5", "psr/container": "^2.0.2", "symfony/config": "^5.4.46|^6.4.14|^7.2", - "symfony/dependency-injection": "^5.4.46|^6.4.14|^7.2" + "symfony/dependency-injection": "^5.4.48|^6.4.19|^7.2" }, "autoload": { "psr-4": { "Chubbyphp\\Deserialization\\": "src/" } diff --git a/tests/Unit/Denormalizer/CallbackFieldDenormalizerTest.php b/tests/Unit/Denormalizer/CallbackFieldDenormalizerTest.php index 20499c3..583ddab 100644 --- a/tests/Unit/Denormalizer/CallbackFieldDenormalizerTest.php +++ b/tests/Unit/Denormalizer/CallbackFieldDenormalizerTest.php @@ -7,8 +7,7 @@ use Chubbyphp\Deserialization\Denormalizer\CallbackFieldDenormalizer; use Chubbyphp\Deserialization\Denormalizer\DenormalizerContextInterface; use Chubbyphp\Deserialization\Denormalizer\DenormalizerInterface; -use Chubbyphp\Mock\MockByCallsTrait; -use PHPUnit\Framework\MockObject\MockObject; +use Chubbyphp\Mock\MockObjectBuilder; use PHPUnit\Framework\TestCase; /** @@ -18,8 +17,6 @@ */ final class CallbackFieldDenormalizerTest extends TestCase { - use MockByCallsTrait; - public function testDenormalizeField(): void { $object = new class { @@ -38,8 +35,10 @@ public function setName(string $name): self } }; - /** @var DenormalizerContextInterface|MockObject $context */ - $context = $this->getMockByCalls(DenormalizerContextInterface::class); + $builder = new MockObjectBuilder(); + + /** @var DenormalizerContextInterface $context */ + $context = $builder->create(DenormalizerContextInterface::class, []); $fieldDenormalizer = new CallbackFieldDenormalizer( static function ( diff --git a/tests/Unit/Denormalizer/ConvertTypeFieldDenormalizerTest.php b/tests/Unit/Denormalizer/ConvertTypeFieldDenormalizerTest.php index 327b30c..b954e39 100644 --- a/tests/Unit/Denormalizer/ConvertTypeFieldDenormalizerTest.php +++ b/tests/Unit/Denormalizer/ConvertTypeFieldDenormalizerTest.php @@ -8,9 +8,9 @@ use Chubbyphp\Deserialization\Denormalizer\ConvertTypeFieldDenormalizer; use Chubbyphp\Deserialization\Denormalizer\DenormalizerContextInterface; use Chubbyphp\Deserialization\DeserializerLogicException; -use Chubbyphp\Mock\Call; -use Chubbyphp\Mock\MockByCallsTrait; -use PHPUnit\Framework\MockObject\MockObject; +use Chubbyphp\Mock\MockMethod\WithoutReturn; +use Chubbyphp\Mock\MockObjectBuilder; +use PHPUnit\Framework\Attributes\DoesNotPerformAssertions; use PHPUnit\Framework\TestCase; /** @@ -20,177 +20,199 @@ */ final class ConvertTypeFieldDenormalizerTest extends TestCase { - use MockByCallsTrait; - public function testDenormalizeFieldWithInvalidType(): void { $this->expectException(DeserializerLogicException::class); $this->expectExceptionMessage('Convert type "type" is not supported'); - /** @var AccessorInterface|MockObject $accessor */ - $accessor = $this->getMockByCalls(AccessorInterface::class); + $builder = new MockObjectBuilder(); + + /** @var AccessorInterface $accessor */ + $accessor = $builder->create(AccessorInterface::class, []); new ConvertTypeFieldDenormalizer($accessor, 'type'); } + #[DoesNotPerformAssertions] public function testDenormalizeFieldWithNull(): void { $object = new \stdClass(); + $builder = new MockObjectBuilder(); - /** @var AccessorInterface|MockObject $accessor */ - $accessor = $this->getMockByCalls(AccessorInterface::class, [ - Call::create('setValue')->with($object, null), + /** @var AccessorInterface $accessor */ + $accessor = $builder->create(AccessorInterface::class, [ + new WithoutReturn('setValue', [$object, null]), ]); - /** @var DenormalizerContextInterface|MockObject $context */ - $context = $this->getMockByCalls(DenormalizerContextInterface::class); + /** @var DenormalizerContextInterface $context */ + $context = $builder->create(DenormalizerContextInterface::class, []); $fieldDenormalizer = new ConvertTypeFieldDenormalizer($accessor, ConvertTypeFieldDenormalizer::TYPE_INT); $fieldDenormalizer->denormalizeField('value', $object, null, $context); } + #[DoesNotPerformAssertions] public function testDenormalizeFieldWithArray(): void { $object = new \stdClass(); + $builder = new MockObjectBuilder(); - /** @var AccessorInterface|MockObject $accessor */ - $accessor = $this->getMockByCalls(AccessorInterface::class, [ - Call::create('setValue')->with($object, []), + /** @var AccessorInterface $accessor */ + $accessor = $builder->create(AccessorInterface::class, [ + new WithoutReturn('setValue', [$object, []]), ]); - /** @var DenormalizerContextInterface|MockObject $context */ - $context = $this->getMockByCalls(DenormalizerContextInterface::class); + /** @var DenormalizerContextInterface $context */ + $context = $builder->create(DenormalizerContextInterface::class, []); $fieldDenormalizer = new ConvertTypeFieldDenormalizer($accessor, ConvertTypeFieldDenormalizer::TYPE_INT); $fieldDenormalizer->denormalizeField('value', $object, [], $context); } + #[DoesNotPerformAssertions] public function testDenormalizeFieldWithFloatWhichCantBeConvertedToBool(): void { $object = new \stdClass(); + $builder = new MockObjectBuilder(); - /** @var AccessorInterface|MockObject $accessor */ - $accessor = $this->getMockByCalls(AccessorInterface::class, [ - Call::create('setValue')->with($object, 1.0), + /** @var AccessorInterface $accessor */ + $accessor = $builder->create(AccessorInterface::class, [ + new WithoutReturn('setValue', [$object, 1.0]), ]); - /** @var DenormalizerContextInterface|MockObject $context */ - $context = $this->getMockByCalls(DenormalizerContextInterface::class); + /** @var DenormalizerContextInterface $context */ + $context = $builder->create(DenormalizerContextInterface::class, []); $fieldDenormalizer = new ConvertTypeFieldDenormalizer($accessor, ConvertTypeFieldDenormalizer::TYPE_BOOL); $fieldDenormalizer->denormalizeField('value', $object, 1.0, $context); } + #[DoesNotPerformAssertions] public function testDenormalizeFieldWithIntWhichCantBeConvertedToBool(): void { $object = new \stdClass(); + $builder = new MockObjectBuilder(); - /** @var AccessorInterface|MockObject $accessor */ - $accessor = $this->getMockByCalls(AccessorInterface::class, [ - Call::create('setValue')->with($object, 1), + /** @var AccessorInterface $accessor */ + $accessor = $builder->create(AccessorInterface::class, [ + new WithoutReturn('setValue', [$object, 1]), ]); - /** @var DenormalizerContextInterface|MockObject $context */ - $context = $this->getMockByCalls(DenormalizerContextInterface::class); + /** @var DenormalizerContextInterface $context */ + $context = $builder->create(DenormalizerContextInterface::class, []); $fieldDenormalizer = new ConvertTypeFieldDenormalizer($accessor, ConvertTypeFieldDenormalizer::TYPE_BOOL); $fieldDenormalizer->denormalizeField('value', $object, 1, $context); } + #[DoesNotPerformAssertions] public function testDenormalizeFieldWithStringConvertedToTrue(): void { $object = new \stdClass(); + $builder = new MockObjectBuilder(); - /** @var AccessorInterface|MockObject $accessor */ - $accessor = $this->getMockByCalls(AccessorInterface::class, [ - Call::create('setValue')->with($object, true), + /** @var AccessorInterface $accessor */ + $accessor = $builder->create(AccessorInterface::class, [ + new WithoutReturn('setValue', [$object, true]), ]); - /** @var DenormalizerContextInterface|MockObject $context */ - $context = $this->getMockByCalls(DenormalizerContextInterface::class); + /** @var DenormalizerContextInterface $context */ + $context = $builder->create(DenormalizerContextInterface::class, []); $fieldDenormalizer = new ConvertTypeFieldDenormalizer($accessor, ConvertTypeFieldDenormalizer::TYPE_BOOL); $fieldDenormalizer->denormalizeField('value', $object, 'true', $context); } + #[DoesNotPerformAssertions] public function testDenormalizeFieldWithStringConvertedToFalse(): void { $object = new \stdClass(); + $builder = new MockObjectBuilder(); - /** @var AccessorInterface|MockObject $accessor */ - $accessor = $this->getMockByCalls(AccessorInterface::class, [ - Call::create('setValue')->with($object, false), + /** @var AccessorInterface $accessor */ + $accessor = $builder->create(AccessorInterface::class, [ + new WithoutReturn('setValue', [$object, false]), ]); - /** @var DenormalizerContextInterface|MockObject $context */ - $context = $this->getMockByCalls(DenormalizerContextInterface::class); + /** @var DenormalizerContextInterface $context */ + $context = $builder->create(DenormalizerContextInterface::class, []); $fieldDenormalizer = new ConvertTypeFieldDenormalizer($accessor, ConvertTypeFieldDenormalizer::TYPE_BOOL); $fieldDenormalizer->denormalizeField('value', $object, 'false', $context); } + #[DoesNotPerformAssertions] public function testDenormalizeFieldWithStringWhichCantBeConvertedToBool(): void { $object = new \stdClass(); + $builder = new MockObjectBuilder(); - /** @var AccessorInterface|MockObject $accessor */ - $accessor = $this->getMockByCalls(AccessorInterface::class, [ - Call::create('setValue')->with($object, 'test'), + /** @var AccessorInterface $accessor */ + $accessor = $builder->create(AccessorInterface::class, [ + new WithoutReturn('setValue', [$object, 'test']), ]); - /** @var DenormalizerContextInterface|MockObject $context */ - $context = $this->getMockByCalls(DenormalizerContextInterface::class); + /** @var DenormalizerContextInterface $context */ + $context = $builder->create(DenormalizerContextInterface::class, []); $fieldDenormalizer = new ConvertTypeFieldDenormalizer($accessor, ConvertTypeFieldDenormalizer::TYPE_BOOL); $fieldDenormalizer->denormalizeField('value', $object, 'test', $context); } + #[DoesNotPerformAssertions] public function testDenormalizeFieldWithBoolWhichCantBeConvertedToFloat(): void { $object = new \stdClass(); + $builder = new MockObjectBuilder(); - /** @var AccessorInterface|MockObject $accessor */ - $accessor = $this->getMockByCalls(AccessorInterface::class, [ - Call::create('setValue')->with($object, true), + /** @var AccessorInterface $accessor */ + $accessor = $builder->create(AccessorInterface::class, [ + new WithoutReturn('setValue', [$object, true]), ]); - /** @var DenormalizerContextInterface|MockObject $context */ - $context = $this->getMockByCalls(DenormalizerContextInterface::class); + /** @var DenormalizerContextInterface $context */ + $context = $builder->create(DenormalizerContextInterface::class, []); $fieldDenormalizer = new ConvertTypeFieldDenormalizer($accessor, ConvertTypeFieldDenormalizer::TYPE_FLOAT); $fieldDenormalizer->denormalizeField('value', $object, true, $context); } + #[DoesNotPerformAssertions] public function testDenormalizeFieldWithIntegerConvertedToFloat(): void { $object = new \stdClass(); - /** @var AccessorInterface|MockObject $accessor */ - $accessor = $this->getMockByCalls(AccessorInterface::class, [ - Call::create('setValue')->with($object, 1.0), + $builder = new MockObjectBuilder(); + + /** @var AccessorInterface $accessor */ + $accessor = $builder->create(AccessorInterface::class, [ + new WithoutReturn('setValue', [$object, 1.0]), ]); - /** @var DenormalizerContextInterface|MockObject $context */ - $context = $this->getMockByCalls(DenormalizerContextInterface::class); + /** @var DenormalizerContextInterface $context */ + $context = $builder->create(DenormalizerContextInterface::class, []); $fieldDenormalizer = new ConvertTypeFieldDenormalizer($accessor, ConvertTypeFieldDenormalizer::TYPE_FLOAT); $fieldDenormalizer->denormalizeField('value', $object, 1, $context); } + #[DoesNotPerformAssertions] public function testDenormalizeFieldWithSpecialIntegerConvertedToFloat(): void { $object = new \stdClass(); - /** @var AccessorInterface|MockObject $accessor */ - $accessor = $this->getMockByCalls(AccessorInterface::class, [ - Call::create('setValue')->with($object, 1337.0), - Call::create('setValue')->with($object, 1337.0), - Call::create('setValue')->with($object, 1337.0), - Call::create('setValue')->with($object, 1337.0), + $builder = new MockObjectBuilder(); + + /** @var AccessorInterface $accessor */ + $accessor = $builder->create(AccessorInterface::class, [ + new WithoutReturn('setValue', [$object, 1337.0]), + new WithoutReturn('setValue', [$object, 1337.0]), + new WithoutReturn('setValue', [$object, 1337.0]), + new WithoutReturn('setValue', [$object, 1337.0]), ]); - /** @var DenormalizerContextInterface|MockObject $context */ - $context = $this->getMockByCalls(DenormalizerContextInterface::class); + /** @var DenormalizerContextInterface $context */ + $context = $builder->create(DenormalizerContextInterface::class, []); $fieldDenormalizer = new ConvertTypeFieldDenormalizer($accessor, ConvertTypeFieldDenormalizer::TYPE_FLOAT); @@ -200,180 +222,213 @@ public function testDenormalizeFieldWithSpecialIntegerConvertedToFloat(): void $fieldDenormalizer->denormalizeField('value', $object, 1337e0, $context); } + #[DoesNotPerformAssertions] public function testDenormalizeFieldWithStringWhichCantBeConvertedToFloat(): void { $object = new \stdClass(); - /** @var AccessorInterface|MockObject $accessor */ - $accessor = $this->getMockByCalls(AccessorInterface::class, [ - Call::create('setValue')->with($object, '5.5.5'), + $builder = new MockObjectBuilder(); + + /** @var AccessorInterface $accessor */ + $accessor = $builder->create(AccessorInterface::class, [ + new WithoutReturn('setValue', [$object, '5.5.5']), ]); - /** @var DenormalizerContextInterface|MockObject $context */ - $context = $this->getMockByCalls(DenormalizerContextInterface::class); + /** @var DenormalizerContextInterface $context */ + $context = $builder->create(DenormalizerContextInterface::class, []); $fieldDenormalizer = new ConvertTypeFieldDenormalizer($accessor, ConvertTypeFieldDenormalizer::TYPE_FLOAT); $fieldDenormalizer->denormalizeField('value', $object, '5.5.5', $context); } + #[DoesNotPerformAssertions] public function testDenormalizeFieldWithStringConvertedToFloat(): void { $object = new \stdClass(); - /** @var AccessorInterface|MockObject $accessor */ - $accessor = $this->getMockByCalls(AccessorInterface::class, [ - Call::create('setValue')->with($object, 5.5), + $builder = new MockObjectBuilder(); + + /** @var AccessorInterface $accessor */ + $accessor = $builder->create(AccessorInterface::class, [ + new WithoutReturn('setValue', [$object, 5.5]), ]); - /** @var DenormalizerContextInterface|MockObject $context */ - $context = $this->getMockByCalls(DenormalizerContextInterface::class); + /** @var DenormalizerContextInterface $context */ + $context = $builder->create(DenormalizerContextInterface::class, []); $fieldDenormalizer = new ConvertTypeFieldDenormalizer($accessor, ConvertTypeFieldDenormalizer::TYPE_FLOAT); $fieldDenormalizer->denormalizeField('value', $object, '5.500', $context); } + #[DoesNotPerformAssertions] public function testDenormalizeFieldWithBoolWhichCantBeConvertedToInteger(): void { $object = new \stdClass(); - /** @var AccessorInterface|MockObject $accessor */ - $accessor = $this->getMockByCalls(AccessorInterface::class, [ - Call::create('setValue')->with($object, true), + $builder = new MockObjectBuilder(); + + /** @var AccessorInterface $accessor */ + $accessor = $builder->create(AccessorInterface::class, [ + new WithoutReturn('setValue', [$object, true]), ]); - /** @var DenormalizerContextInterface|MockObject $context */ - $context = $this->getMockByCalls(DenormalizerContextInterface::class); + /** @var DenormalizerContextInterface $context */ + $context = $builder->create(DenormalizerContextInterface::class, []); $fieldDenormalizer = new ConvertTypeFieldDenormalizer($accessor, ConvertTypeFieldDenormalizer::TYPE_INT); $fieldDenormalizer->denormalizeField('value', $object, true, $context); } + #[DoesNotPerformAssertions] public function testDenormalizeFieldWithFloatConvertedToInteger(): void { $object = new \stdClass(); - /** @var AccessorInterface|MockObject $accessor */ - $accessor = $this->getMockByCalls(AccessorInterface::class, [ - Call::create('setValue')->with($object, 5), + $builder = new MockObjectBuilder(); + + /** @var AccessorInterface $accessor */ + $accessor = $builder->create(AccessorInterface::class, [ + new WithoutReturn('setValue', [$object, 5]), ]); - /** @var DenormalizerContextInterface|MockObject $context */ - $context = $this->getMockByCalls(DenormalizerContextInterface::class); + /** @var DenormalizerContextInterface $context */ + $context = $builder->create(DenormalizerContextInterface::class, []); $fieldDenormalizer = new ConvertTypeFieldDenormalizer($accessor, ConvertTypeFieldDenormalizer::TYPE_INT); $fieldDenormalizer->denormalizeField('value', $object, 5.0, $context); } + #[DoesNotPerformAssertions] public function testDenormalizeFieldWithFloatWhichCantBeConvertedToInteger(): void { $object = new \stdClass(); - /** @var AccessorInterface|MockObject $accessor */ - $accessor = $this->getMockByCalls(AccessorInterface::class, [ - Call::create('setValue')->with($object, 5.1), + $builder = new MockObjectBuilder(); + + /** @var AccessorInterface $accessor */ + $accessor = $builder->create(AccessorInterface::class, [ + new WithoutReturn('setValue', [$object, 5.1]), ]); - /** @var DenormalizerContextInterface|MockObject $context */ - $context = $this->getMockByCalls(DenormalizerContextInterface::class); + /** @var DenormalizerContextInterface $context */ + $context = $builder->create(DenormalizerContextInterface::class, []); $fieldDenormalizer = new ConvertTypeFieldDenormalizer($accessor, ConvertTypeFieldDenormalizer::TYPE_INT); $fieldDenormalizer->denormalizeField('value', $object, 5.1, $context); } + #[DoesNotPerformAssertions] public function testDenormalizeFieldWithStringWhichCantBeConvertedToInteger(): void { $object = new \stdClass(); - /** @var AccessorInterface|MockObject $accessor */ - $accessor = $this->getMockByCalls(AccessorInterface::class, [ - Call::create('setValue')->with($object, 'test'), + $builder = new MockObjectBuilder(); + + /** @var AccessorInterface $accessor */ + $accessor = $builder->create(AccessorInterface::class, [ + new WithoutReturn('setValue', [$object, 'test']), ]); - /** @var DenormalizerContextInterface|MockObject $context */ - $context = $this->getMockByCalls(DenormalizerContextInterface::class); + /** @var DenormalizerContextInterface $context */ + $context = $builder->create(DenormalizerContextInterface::class, []); $fieldDenormalizer = new ConvertTypeFieldDenormalizer($accessor, ConvertTypeFieldDenormalizer::TYPE_INT); $fieldDenormalizer->denormalizeField('value', $object, 'test', $context); } + #[DoesNotPerformAssertions] public function testDenormalizeFieldWithStringConvertedToInteger(): void { $object = new \stdClass(); - /** @var AccessorInterface|MockObject $accessor */ - $accessor = $this->getMockByCalls(AccessorInterface::class, [ - Call::create('setValue')->with($object, 5), + $builder = new MockObjectBuilder(); + + /** @var AccessorInterface $accessor */ + $accessor = $builder->create(AccessorInterface::class, [ + new WithoutReturn('setValue', [$object, 5]), ]); - /** @var DenormalizerContextInterface|MockObject $context */ - $context = $this->getMockByCalls(DenormalizerContextInterface::class); + /** @var DenormalizerContextInterface $context */ + $context = $builder->create(DenormalizerContextInterface::class, []); $fieldDenormalizer = new ConvertTypeFieldDenormalizer($accessor, ConvertTypeFieldDenormalizer::TYPE_INT); $fieldDenormalizer->denormalizeField('value', $object, '5', $context); } + #[DoesNotPerformAssertions] public function testDenormalizeFieldWithBoolWhichCantBeConvertedToString(): void { $object = new \stdClass(); - /** @var AccessorInterface|MockObject $accessor */ - $accessor = $this->getMockByCalls(AccessorInterface::class, [ - Call::create('setValue')->with($object, true), + $builder = new MockObjectBuilder(); + + /** @var AccessorInterface $accessor */ + $accessor = $builder->create(AccessorInterface::class, [ + new WithoutReturn('setValue', [$object, true]), ]); - /** @var DenormalizerContextInterface|MockObject $context */ - $context = $this->getMockByCalls(DenormalizerContextInterface::class); + /** @var DenormalizerContextInterface $context */ + $context = $builder->create(DenormalizerContextInterface::class, []); $fieldDenormalizer = new ConvertTypeFieldDenormalizer($accessor, ConvertTypeFieldDenormalizer::TYPE_STRING); $fieldDenormalizer->denormalizeField('value', $object, true, $context); } + #[DoesNotPerformAssertions] public function testDenormalizeFieldWithFloatConvertedToString(): void { $object = new \stdClass(); - /** @var AccessorInterface|MockObject $accessor */ - $accessor = $this->getMockByCalls(AccessorInterface::class, [ - Call::create('setValue')->with($object, '5.5'), + $builder = new MockObjectBuilder(); + + /** @var AccessorInterface $accessor */ + $accessor = $builder->create(AccessorInterface::class, [ + new WithoutReturn('setValue', [$object, '5.5']), ]); - /** @var DenormalizerContextInterface|MockObject $context */ - $context = $this->getMockByCalls(DenormalizerContextInterface::class); + /** @var DenormalizerContextInterface $context */ + $context = $builder->create(DenormalizerContextInterface::class, []); $fieldDenormalizer = new ConvertTypeFieldDenormalizer($accessor, ConvertTypeFieldDenormalizer::TYPE_STRING); $fieldDenormalizer->denormalizeField('value', $object, 5.5, $context); } + #[DoesNotPerformAssertions] public function testDenormalizeFieldWithIntegerConvertedToString(): void { $object = new \stdClass(); - /** @var AccessorInterface|MockObject $accessor */ - $accessor = $this->getMockByCalls(AccessorInterface::class, [ - Call::create('setValue')->with($object, '5'), + $builder = new MockObjectBuilder(); + + /** @var AccessorInterface $accessor */ + $accessor = $builder->create(AccessorInterface::class, [ + new WithoutReturn('setValue', [$object, '5']), ]); - /** @var DenormalizerContextInterface|MockObject $context */ - $context = $this->getMockByCalls(DenormalizerContextInterface::class); + /** @var DenormalizerContextInterface $context */ + $context = $builder->create(DenormalizerContextInterface::class, []); $fieldDenormalizer = new ConvertTypeFieldDenormalizer($accessor, ConvertTypeFieldDenormalizer::TYPE_STRING); $fieldDenormalizer->denormalizeField('value', $object, 5, $context); } + #[DoesNotPerformAssertions] public function testDenormalizeFieldWithSpecialIntegerConvertedToString(): void { $object = new \stdClass(); - /** @var AccessorInterface|MockObject $accessor */ - $accessor = $this->getMockByCalls(AccessorInterface::class, [ - Call::create('setValue')->with($object, '1337'), - Call::create('setValue')->with($object, '1337'), - Call::create('setValue')->with($object, '1337'), - Call::create('setValue')->with($object, '1337'), + $builder = new MockObjectBuilder(); + + /** @var AccessorInterface $accessor */ + $accessor = $builder->create(AccessorInterface::class, [ + new WithoutReturn('setValue', [$object, '1337']), + new WithoutReturn('setValue', [$object, '1337']), + new WithoutReturn('setValue', [$object, '1337']), + new WithoutReturn('setValue', [$object, '1337']), ]); - /** @var DenormalizerContextInterface|MockObject $context */ - $context = $this->getMockByCalls(DenormalizerContextInterface::class); + /** @var DenormalizerContextInterface $context */ + $context = $builder->create(DenormalizerContextInterface::class, []); $fieldDenormalizer = new ConvertTypeFieldDenormalizer($accessor, ConvertTypeFieldDenormalizer::TYPE_STRING); @@ -383,50 +438,59 @@ public function testDenormalizeFieldWithSpecialIntegerConvertedToString(): void $fieldDenormalizer->denormalizeField('value', $object, 1337e0, $context); } + #[DoesNotPerformAssertions] public function testDenormalizeFieldWithEmptyToNullDisabled(): void { $object = new \stdClass(); - /** @var AccessorInterface|MockObject $accessor */ - $accessor = $this->getMockByCalls(AccessorInterface::class, [ - Call::create('setValue')->with($object, ''), + $builder = new MockObjectBuilder(); + + /** @var AccessorInterface $accessor */ + $accessor = $builder->create(AccessorInterface::class, [ + new WithoutReturn('setValue', [$object, '']), ]); - /** @var DenormalizerContextInterface|MockObject $context */ - $context = $this->getMockByCalls(DenormalizerContextInterface::class); + /** @var DenormalizerContextInterface $context */ + $context = $builder->create(DenormalizerContextInterface::class, []); $fieldDenormalizer = new ConvertTypeFieldDenormalizer($accessor, ConvertTypeFieldDenormalizer::TYPE_FLOAT); $fieldDenormalizer->denormalizeField('value', $object, '', $context); } + #[DoesNotPerformAssertions] public function testDenormalizeFieldWithObjectToString(): void { $object = new \stdClass(); $valueObject = new \stdClass(); - /** @var AccessorInterface|MockObject $accessor */ - $accessor = $this->getMockByCalls(AccessorInterface::class, [ - Call::create('setValue')->with($object, $valueObject), + $builder = new MockObjectBuilder(); + + /** @var AccessorInterface $accessor */ + $accessor = $builder->create(AccessorInterface::class, [ + new WithoutReturn('setValue', [$object, $valueObject]), ]); - /** @var DenormalizerContextInterface|MockObject $context */ - $context = $this->getMockByCalls(DenormalizerContextInterface::class); + /** @var DenormalizerContextInterface $context */ + $context = $builder->create(DenormalizerContextInterface::class, []); $fieldDenormalizer = new ConvertTypeFieldDenormalizer($accessor, ConvertTypeFieldDenormalizer::TYPE_STRING); $fieldDenormalizer->denormalizeField('value', $object, $valueObject, $context); } + #[DoesNotPerformAssertions] public function testDenormalizeFieldWithEmptyToNullEnabled(): void { $object = new \stdClass(); - /** @var AccessorInterface|MockObject $accessor */ - $accessor = $this->getMockByCalls(AccessorInterface::class, [ - Call::create('setValue')->with($object, null), + $builder = new MockObjectBuilder(); + + /** @var AccessorInterface $accessor */ + $accessor = $builder->create(AccessorInterface::class, [ + new WithoutReturn('setValue', [$object, null]), ]); - /** @var DenormalizerContextInterface|MockObject $context */ - $context = $this->getMockByCalls(DenormalizerContextInterface::class); + /** @var DenormalizerContextInterface $context */ + $context = $builder->create(DenormalizerContextInterface::class, []); $fieldDenormalizer = new ConvertTypeFieldDenormalizer($accessor, ConvertTypeFieldDenormalizer::TYPE_FLOAT, true); $fieldDenormalizer->denormalizeField('value', $object, '', $context); diff --git a/tests/Unit/Denormalizer/DateTimeImmutableFieldDenormalizerTest.php b/tests/Unit/Denormalizer/DateTimeImmutableFieldDenormalizerTest.php index edb92aa..9fc5685 100644 --- a/tests/Unit/Denormalizer/DateTimeImmutableFieldDenormalizerTest.php +++ b/tests/Unit/Denormalizer/DateTimeImmutableFieldDenormalizerTest.php @@ -7,10 +7,10 @@ use Chubbyphp\Deserialization\Accessor\AccessorInterface; use Chubbyphp\Deserialization\Denormalizer\DateTimeImmutableFieldDenormalizer; use Chubbyphp\Deserialization\Denormalizer\DenormalizerContextInterface; -use Chubbyphp\Mock\Argument\ArgumentCallback; -use Chubbyphp\Mock\Call; -use Chubbyphp\Mock\MockByCallsTrait; -use PHPUnit\Framework\MockObject\MockObject; +use Chubbyphp\Mock\MockMethod\WithCallback; +use Chubbyphp\Mock\MockMethod\WithoutReturn; +use Chubbyphp\Mock\MockObjectBuilder; +use PHPUnit\Framework\Attributes\DoesNotPerformAssertions; use PHPUnit\Framework\TestCase; /** @@ -20,234 +20,268 @@ */ final class DateTimeImmutableFieldDenormalizerTest extends TestCase { - use MockByCallsTrait; - public function testDenormalizeField(): void { $object = new \stdClass(); - - /** @var AccessorInterface|MockObject $accessor */ - $accessor = $this->getMockByCalls(AccessorInterface::class, [ - Call::create('setValue')->with($object, new ArgumentCallback( - static function ($value): void { - self::assertInstanceOf(\DateTimeImmutable::class, $value); - self::assertSame('2017-01-01', $value->format('Y-m-d')); - } - )), + $builder = new MockObjectBuilder(); + + /** @var AccessorInterface $accessor */ + $accessor = $builder->create(AccessorInterface::class, [ + new WithCallback('setValue', static function ($object, $value): void { + self::assertInstanceOf(\DateTimeImmutable::class, $value); + self::assertSame('2017-01-01', $value->format('Y-m-d')); + }), ]); - /** @var DenormalizerContextInterface|MockObject $context */ - $context = $this->getMockByCalls(DenormalizerContextInterface::class); + /** @var DenormalizerContextInterface $context */ + $context = $builder->create(DenormalizerContextInterface::class, []); $fieldDenormalizer = new DateTimeImmutableFieldDenormalizer($accessor); $fieldDenormalizer->denormalizeField('date', $object, '2017-01-01', $context); } + #[DoesNotPerformAssertions] public function testDenormalizeInvalidMonthField(): void { $object = new \stdClass(); - /** @var AccessorInterface|MockObject $accessor */ - $accessor = $this->getMockByCalls(AccessorInterface::class, [ - Call::create('setValue')->with($object, '2017-13-01'), + $builder = new MockObjectBuilder(); + + /** @var AccessorInterface $accessor */ + $accessor = $builder->create(AccessorInterface::class, [ + new WithoutReturn('setValue', [$object, '2017-13-01']), ]); - /** @var DenormalizerContextInterface|MockObject $context */ - $context = $this->getMockByCalls(DenormalizerContextInterface::class); + /** @var DenormalizerContextInterface $context */ + $context = $builder->create(DenormalizerContextInterface::class, []); $fieldDenormalizer = new DateTimeImmutableFieldDenormalizer($accessor); $fieldDenormalizer->denormalizeField('date', $object, '2017-13-01', $context); } + #[DoesNotPerformAssertions] public function testDenormalizeInvalidDayField(): void { $object = new \stdClass(); - /** @var AccessorInterface|MockObject $accessor */ - $accessor = $this->getMockByCalls(AccessorInterface::class, [ - Call::create('setValue')->with($object, '2017-02-31'), + $builder = new MockObjectBuilder(); + + /** @var AccessorInterface $accessor */ + $accessor = $builder->create(AccessorInterface::class, [ + new WithoutReturn('setValue', [$object, '2017-02-31']), ]); - /** @var DenormalizerContextInterface|MockObject $context */ - $context = $this->getMockByCalls(DenormalizerContextInterface::class); + /** @var DenormalizerContextInterface $context */ + $context = $builder->create(DenormalizerContextInterface::class, []); $fieldDenormalizer = new DateTimeImmutableFieldDenormalizer($accessor); $fieldDenormalizer->denormalizeField('date', $object, '2017-02-31', $context); } + #[DoesNotPerformAssertions] public function testDenormalizeInvalidWithAllZeroField(): void { $object = new \stdClass(); - /** @var AccessorInterface|MockObject $accessor */ - $accessor = $this->getMockByCalls(AccessorInterface::class, [ - Call::create('setValue')->with($object, '0000-00-00'), + $builder = new MockObjectBuilder(); + + /** @var AccessorInterface $accessor */ + $accessor = $builder->create(AccessorInterface::class, [ + new WithoutReturn('setValue', [$object, '0000-00-00']), ]); - /** @var DenormalizerContextInterface|MockObject $context */ - $context = $this->getMockByCalls(DenormalizerContextInterface::class); + /** @var DenormalizerContextInterface $context */ + $context = $builder->create(DenormalizerContextInterface::class, []); $fieldDenormalizer = new DateTimeImmutableFieldDenormalizer($accessor); $fieldDenormalizer->denormalizeField('date', $object, '0000-00-00', $context); } + #[DoesNotPerformAssertions] public function testDenormalizeEmptyField(): void { $object = new \stdClass(); - /** @var AccessorInterface|MockObject $accessor */ - $accessor = $this->getMockByCalls(AccessorInterface::class, [ - Call::create('setValue')->with($object, ''), + $builder = new MockObjectBuilder(); + + /** @var AccessorInterface $accessor */ + $accessor = $builder->create(AccessorInterface::class, [ + new WithoutReturn('setValue', [$object, '']), ]); - /** @var DenormalizerContextInterface|MockObject $context */ - $context = $this->getMockByCalls(DenormalizerContextInterface::class); + /** @var DenormalizerContextInterface $context */ + $context = $builder->create(DenormalizerContextInterface::class, []); $fieldDenormalizer = new DateTimeImmutableFieldDenormalizer($accessor); $fieldDenormalizer->denormalizeField('date', $object, '', $context); } + #[DoesNotPerformAssertions] public function testDenormalizeWhitespaceOnlyField(): void { $object = new \stdClass(); - /** @var AccessorInterface|MockObject $accessor */ - $accessor = $this->getMockByCalls(AccessorInterface::class, [ - Call::create('setValue')->with($object, ' '), + $builder = new MockObjectBuilder(); + + /** @var AccessorInterface $accessor */ + $accessor = $builder->create(AccessorInterface::class, [ + new WithoutReturn('setValue', [$object, ' ']), ]); - /** @var DenormalizerContextInterface|MockObject $context */ - $context = $this->getMockByCalls(DenormalizerContextInterface::class); + /** @var DenormalizerContextInterface $context */ + $context = $builder->create(DenormalizerContextInterface::class, []); $fieldDenormalizer = new DateTimeImmutableFieldDenormalizer($accessor); $fieldDenormalizer->denormalizeField('date', $object, ' ', $context); } + #[DoesNotPerformAssertions] public function testDenormalizeNullField(): void { $object = new \stdClass(); - /** @var AccessorInterface|MockObject $accessor */ - $accessor = $this->getMockByCalls(AccessorInterface::class, [ - Call::create('setValue')->with($object, null), + $builder = new MockObjectBuilder(); + + /** @var AccessorInterface $accessor */ + $accessor = $builder->create(AccessorInterface::class, [ + new WithoutReturn('setValue', [$object, null]), ]); - /** @var DenormalizerContextInterface|MockObject $context */ - $context = $this->getMockByCalls(DenormalizerContextInterface::class); + /** @var DenormalizerContextInterface $context */ + $context = $builder->create(DenormalizerContextInterface::class, []); $fieldDenormalizer = new DateTimeImmutableFieldDenormalizer($accessor); $fieldDenormalizer->denormalizeField('date', $object, null, $context); } + #[DoesNotPerformAssertions] public function testDenormalizeNullStringField(): void { $object = new \stdClass(); - /** @var AccessorInterface|MockObject $accessor */ - $accessor = $this->getMockByCalls(AccessorInterface::class, [ - Call::create('setValue')->with($object, 'null'), + $builder = new MockObjectBuilder(); + + /** @var AccessorInterface $accessor */ + $accessor = $builder->create(AccessorInterface::class, [ + new WithoutReturn('setValue', [$object, 'null']), ]); - /** @var DenormalizerContextInterface|MockObject $context */ - $context = $this->getMockByCalls(DenormalizerContextInterface::class); + /** @var DenormalizerContextInterface $context */ + $context = $builder->create(DenormalizerContextInterface::class, []); $fieldDenormalizer = new DateTimeImmutableFieldDenormalizer($accessor); $fieldDenormalizer->denormalizeField('date', $object, 'null', $context); } + #[DoesNotPerformAssertions] public function testDenormalizeZeroField(): void { $object = new \stdClass(); - /** @var AccessorInterface|MockObject $accessor */ - $accessor = $this->getMockByCalls(AccessorInterface::class, [ - Call::create('setValue')->with($object, 0), + $builder = new MockObjectBuilder(); + + /** @var AccessorInterface $accessor */ + $accessor = $builder->create(AccessorInterface::class, [ + new WithoutReturn('setValue', [$object, 0]), ]); - /** @var DenormalizerContextInterface|MockObject $context */ - $context = $this->getMockByCalls(DenormalizerContextInterface::class); + /** @var DenormalizerContextInterface $context */ + $context = $builder->create(DenormalizerContextInterface::class, []); $fieldDenormalizer = new DateTimeImmutableFieldDenormalizer($accessor); $fieldDenormalizer->denormalizeField('date', $object, 0, $context); } + #[DoesNotPerformAssertions] public function testDenormalizeZeroStringField(): void { $object = new \stdClass(); - /** @var AccessorInterface|MockObject $accessor */ - $accessor = $this->getMockByCalls(AccessorInterface::class, [ - Call::create('setValue')->with($object, '0'), + $builder = new MockObjectBuilder(); + + /** @var AccessorInterface $accessor */ + $accessor = $builder->create(AccessorInterface::class, [ + new WithoutReturn('setValue', [$object, '0']), ]); - /** @var DenormalizerContextInterface|MockObject $context */ - $context = $this->getMockByCalls(DenormalizerContextInterface::class); + /** @var DenormalizerContextInterface $context */ + $context = $builder->create(DenormalizerContextInterface::class, []); $fieldDenormalizer = new DateTimeImmutableFieldDenormalizer($accessor); $fieldDenormalizer->denormalizeField('date', $object, '0', $context); } + #[DoesNotPerformAssertions] public function testDenormalizeArrayField(): void { $object = new \stdClass(); - /** @var AccessorInterface|MockObject $accessor */ - $accessor = $this->getMockByCalls(AccessorInterface::class, [ - Call::create('setValue')->with($object, []), + $builder = new MockObjectBuilder(); + + /** @var AccessorInterface $accessor */ + $accessor = $builder->create(AccessorInterface::class, [ + new WithoutReturn('setValue', [$object, []]), ]); - /** @var DenormalizerContextInterface|MockObject $context */ - $context = $this->getMockByCalls(DenormalizerContextInterface::class); + /** @var DenormalizerContextInterface $context */ + $context = $builder->create(DenormalizerContextInterface::class, []); $fieldDenormalizer = new DateTimeImmutableFieldDenormalizer($accessor); $fieldDenormalizer->denormalizeField('date', $object, [], $context); } + #[DoesNotPerformAssertions] public function testDenormalizeObjectField(): void { $object = new \stdClass(); $date = new \stdClass(); - /** @var AccessorInterface|MockObject $accessor */ - $accessor = $this->getMockByCalls(AccessorInterface::class, [ - Call::create('setValue')->with($object, $date), + $builder = new MockObjectBuilder(); + + /** @var AccessorInterface $accessor */ + $accessor = $builder->create(AccessorInterface::class, [ + new WithoutReturn('setValue', [$object, $date]), ]); - /** @var DenormalizerContextInterface|MockObject $context */ - $context = $this->getMockByCalls(DenormalizerContextInterface::class); + /** @var DenormalizerContextInterface $context */ + $context = $builder->create(DenormalizerContextInterface::class, []); $fieldDenormalizer = new DateTimeImmutableFieldDenormalizer($accessor); $fieldDenormalizer->denormalizeField('date', $object, $date, $context); } + #[DoesNotPerformAssertions] public function testDenormalizeFieldWithEmptyToNullDisabled(): void { $object = new \stdClass(); - /** @var AccessorInterface|MockObject $accessor */ - $accessor = $this->getMockByCalls(AccessorInterface::class, [ - Call::create('setValue')->with($object, ''), + $builder = new MockObjectBuilder(); + + /** @var AccessorInterface $accessor */ + $accessor = $builder->create(AccessorInterface::class, [ + new WithoutReturn('setValue', [$object, '']), ]); - /** @var DenormalizerContextInterface|MockObject $context */ - $context = $this->getMockByCalls(DenormalizerContextInterface::class); + $context = $builder->create(DenormalizerContextInterface::class, []); $fieldDenormalizer = new DateTimeImmutableFieldDenormalizer($accessor); $fieldDenormalizer->denormalizeField('date', $object, '', $context); } + #[DoesNotPerformAssertions] public function testDenormalizeFieldWithEmptyToNullEnabled(): void { $object = new \stdClass(); - /** @var AccessorInterface|MockObject $accessor */ - $accessor = $this->getMockByCalls(AccessorInterface::class, [ - Call::create('setValue')->with($object, null), + $builder = new MockObjectBuilder(); + + /** @var AccessorInterface $accessor */ + $accessor = $builder->create(AccessorInterface::class, [ + new WithoutReturn('setValue', [$object, null]), ]); - /** @var DenormalizerContextInterface|MockObject $context */ - $context = $this->getMockByCalls(DenormalizerContextInterface::class); + $context = $builder->create(DenormalizerContextInterface::class, []); $fieldDenormalizer = new DateTimeImmutableFieldDenormalizer($accessor, true); $fieldDenormalizer->denormalizeField('date', $object, '', $context); @@ -257,21 +291,21 @@ public function testDenormalizeFieldWithTimezone(): void { $object = new \stdClass(); - /** @var DenormalizerContextInterface|MockObject $context */ - $context = $this->getMockByCalls(DenormalizerContextInterface::class); - - /** @var AccessorInterface|MockObject $fieldDenormalizer */ - $fieldDenormalizer = $this->getMockByCalls(AccessorInterface::class, [ - Call::create('setValue')->with($object, new ArgumentCallback( - static function ($value): void { - self::assertInstanceOf(\DateTimeImmutable::class, $value); - self::assertSame('2016-12-31 23:00:00', $value->format('Y-m-d H:i:s')); - } - )), + $builder = new MockObjectBuilder(); + + /** @var DenormalizerContextInterface $context */ + $context = $builder->create(DenormalizerContextInterface::class, []); + + /** @var AccessorInterface $accessor */ + $accessor = $builder->create(AccessorInterface::class, [ + new WithCallback('setValue', static function ($object, $value): void { + self::assertInstanceOf(\DateTimeImmutable::class, $value); + self::assertSame('2016-12-31 23:00:00', $value->format('Y-m-d H:i:s')); + }), ]); $fieldDenormalizer = new DateTimeImmutableFieldDenormalizer( - $fieldDenormalizer, + $accessor, false, new \DateTimeZone('Europe/Zurich') ); diff --git a/tests/Unit/Denormalizer/DenormalizerContextBuilderTest.php b/tests/Unit/Denormalizer/DenormalizerContextBuilderTest.php index e701d7f..6a4a801 100644 --- a/tests/Unit/Denormalizer/DenormalizerContextBuilderTest.php +++ b/tests/Unit/Denormalizer/DenormalizerContextBuilderTest.php @@ -6,8 +6,7 @@ use Chubbyphp\Deserialization\Denormalizer\DenormalizerContextBuilder; use Chubbyphp\Deserialization\Denormalizer\DenormalizerContextInterface; -use Chubbyphp\Mock\MockByCallsTrait; -use PHPUnit\Framework\MockObject\MockObject; +use Chubbyphp\Mock\MockObjectBuilder; use PHPUnit\Framework\TestCase; use Psr\Http\Message\ServerRequestInterface; @@ -18,8 +17,6 @@ */ final class DenormalizerContextBuilderTest extends TestCase { - use MockByCallsTrait; - public function testCreate(): void { $context = DenormalizerContextBuilder::create()->getContext(); @@ -34,8 +31,10 @@ public function testCreate(): void public function testCreateWithOverridenSettings(): void { - /** @var MockObject|ServerRequestInterface $request */ - $request = $this->getMockByCalls(ServerRequestInterface::class); + $builder = new MockObjectBuilder(); + + /** @var ServerRequestInterface $request */ + $request = $builder->create(ServerRequestInterface::class, []); $context = DenormalizerContextBuilder::create() ->setAllowedAdditionalFields(['allowed_field']) diff --git a/tests/Unit/Denormalizer/DenormalizerContextTest.php b/tests/Unit/Denormalizer/DenormalizerContextTest.php index e42b351..7c9cc5b 100644 --- a/tests/Unit/Denormalizer/DenormalizerContextTest.php +++ b/tests/Unit/Denormalizer/DenormalizerContextTest.php @@ -5,8 +5,7 @@ namespace Chubbyphp\Tests\Deserialization\Unit\Denormalizer; use Chubbyphp\Deserialization\Denormalizer\DenormalizerContext; -use Chubbyphp\Mock\MockByCallsTrait; -use PHPUnit\Framework\MockObject\MockObject; +use Chubbyphp\Mock\MockObjectBuilder; use PHPUnit\Framework\TestCase; use Psr\Http\Message\ServerRequestInterface; @@ -17,8 +16,6 @@ */ final class DenormalizerContextTest extends TestCase { - use MockByCallsTrait; - public function testCreate(): void { $context = new DenormalizerContext(); @@ -33,8 +30,10 @@ public function testCreate(): void public function testCreateWithOverridenSettings(): void { - /** @var MockObject|ServerRequestInterface $request */ - $request = $this->getMockByCalls(ServerRequestInterface::class); + $builder = new MockObjectBuilder(); + + /** @var ServerRequestInterface $request */ + $request = $builder->create(ServerRequestInterface::class, []); $context = new DenormalizerContext( $request, @@ -52,8 +51,10 @@ public function testCreateWithOverridenSettings(): void public function testWithAttributes(): void { - /** @var MockObject|ServerRequestInterface $request */ - $request = $this->getMockByCalls(ServerRequestInterface::class); + $builder = new MockObjectBuilder(); + + /** @var ServerRequestInterface $request */ + $request = $builder->create(ServerRequestInterface::class, []); $context = new DenormalizerContext($request, ['attribute' => 'value'], ['allowed_field']); @@ -67,8 +68,10 @@ public function testWithAttributes(): void public function testWithAttribute(): void { - /** @var MockObject|ServerRequestInterface $request */ - $request = $this->getMockByCalls(ServerRequestInterface::class); + $builder = new MockObjectBuilder(); + + /** @var ServerRequestInterface $request */ + $request = $builder->create(ServerRequestInterface::class, []); $context = new DenormalizerContext($request, ['attribute' => 'value'], ['allowed_field']); diff --git a/tests/Unit/Denormalizer/DenormalizerObjectMappingRegistryTest.php b/tests/Unit/Denormalizer/DenormalizerObjectMappingRegistryTest.php index 5a57c27..07148d7 100644 --- a/tests/Unit/Denormalizer/DenormalizerObjectMappingRegistryTest.php +++ b/tests/Unit/Denormalizer/DenormalizerObjectMappingRegistryTest.php @@ -7,11 +7,10 @@ use Chubbyphp\Deserialization\Denormalizer\DenormalizerObjectMappingRegistry; use Chubbyphp\Deserialization\DeserializerLogicException; use Chubbyphp\Deserialization\Mapping\DenormalizationObjectMappingInterface; -use Chubbyphp\Mock\Call; -use Chubbyphp\Mock\MockByCallsTrait; +use Chubbyphp\Mock\MockMethod\WithReturn; +use Chubbyphp\Mock\MockObjectBuilder; use Chubbyphp\Tests\Deserialization\Resources\Model\AbstractManyModel; use Doctrine\Persistence\Proxy; -use PHPUnit\Framework\MockObject\MockObject; use PHPUnit\Framework\TestCase; /** @@ -21,13 +20,13 @@ */ final class DenormalizerObjectMappingRegistryTest extends TestCase { - use MockByCallsTrait; - public function testGetObjectMapping(): void { - /** @var DenormalizationObjectMappingInterface|MockObject $denormalizationObjectMapping */ - $denormalizationObjectMapping = $this->getMockByCalls(DenormalizationObjectMappingInterface::class, [ - Call::create('getClass')->with()->willReturn(\stdClass::class), + $builder = new MockObjectBuilder(); + + /** @var DenormalizationObjectMappingInterface $denormalizationObjectMapping */ + $denormalizationObjectMapping = $builder->create(DenormalizationObjectMappingInterface::class, [ + new WithReturn('getClass', [], \stdClass::class), ]); $registry = new DenormalizerObjectMappingRegistry([$denormalizationObjectMapping]); @@ -51,9 +50,11 @@ public function testGetObjectMappingFromDoctrineProxy(): void { $object = $this->getProxyObject(); - /** @var DenormalizationObjectMappingInterface|MockObject $denormalizationObjectMapping */ - $denormalizationObjectMapping = $this->getMockByCalls(DenormalizationObjectMappingInterface::class, [ - Call::create('getClass')->with()->willReturn(AbstractManyModel::class), + $builder = new MockObjectBuilder(); + + /** @var DenormalizationObjectMappingInterface $denormalizationObjectMapping */ + $denormalizationObjectMapping = $builder->create(DenormalizationObjectMappingInterface::class, [ + new WithReturn('getClass', [], AbstractManyModel::class), ]); $registry = new DenormalizerObjectMappingRegistry([$denormalizationObjectMapping]); @@ -68,19 +69,11 @@ private function getProxyObject(): object return new class extends AbstractManyModel implements Proxy { private bool $initialized = false; - /** - * Initializes this proxy if its not yet initialized. - * - * Acts as a no-op if already initialized. - */ public function __load(): void { $this->initialized = true; } - /** - * Returns whether this proxy is initialized or not. - */ public function __isInitialized(): bool { return $this->initialized; diff --git a/tests/Unit/Denormalizer/DenormalizerTest.php b/tests/Unit/Denormalizer/DenormalizerTest.php index 114f29b..8a2a090 100644 --- a/tests/Unit/Denormalizer/DenormalizerTest.php +++ b/tests/Unit/Denormalizer/DenormalizerTest.php @@ -14,10 +14,12 @@ use Chubbyphp\Deserialization\Mapping\DenormalizationFieldMappingInterface; use Chubbyphp\Deserialization\Mapping\DenormalizationObjectMappingInterface; use Chubbyphp\Deserialization\Policy\PolicyInterface; -use Chubbyphp\Mock\Argument\ArgumentInstanceOf; -use Chubbyphp\Mock\Call; -use Chubbyphp\Mock\MockByCallsTrait; -use PHPUnit\Framework\MockObject\MockObject; +use Chubbyphp\Mock\MockMethod\WithCallback; +use Chubbyphp\Mock\MockMethod\WithException; +use Chubbyphp\Mock\MockMethod\WithoutReturn; +use Chubbyphp\Mock\MockMethod\WithReturn; +use Chubbyphp\Mock\MockObjectBuilder; +use PHPUnit\Framework\Attributes\DoesNotPerformAssertions; use PHPUnit\Framework\TestCase; use Psr\Log\LoggerInterface; @@ -28,60 +30,71 @@ */ final class DenormalizerTest extends TestCase { - use MockByCallsTrait; - public function testDenormalizeWithNew(): void { $object = new \stdClass(); $factory = static fn () => $object; - /** @var DenormalizerContextInterface|MockObject $context */ - $context = $this->getMockByCalls(DenormalizerContextInterface::class, [ - Call::create('isClearMissing')->with()->willReturn(false), - Call::create('getAllowedAdditionalFields')->with()->willReturn(null), + $builder = new MockObjectBuilder(); + + /** @var DenormalizerContextInterface $context */ + $context = $builder->create(DenormalizerContextInterface::class, [ + new WithReturn('isClearMissing', [], false), + new WithReturn('getAllowedAdditionalFields', [], null), ]); - /** @var MockObject|PolicyInterface $namePolicy */ - $namePolicy = $this->getMockByCalls(PolicyInterface::class, [ - Call::create('isCompliant')->with('name', $object, $context)->willReturn(true), + /** @var PolicyInterface $namePolicy */ + $namePolicy = $builder->create(PolicyInterface::class, [ + new WithReturn('isCompliant', ['name', $object, $context], true), ]); - /** @var FieldDenormalizerInterface|MockObject $nameFieldDenormalizer */ - $nameFieldDenormalizer = $this->getMockByCalls(FieldDenormalizerInterface::class, [ - Call::create('denormalizeField') - ->with('name', $object, 'name', $context, new ArgumentInstanceOf(DenormalizerInterface::class)), + /** @var FieldDenormalizerInterface $nameFieldDenormalizer */ + $nameFieldDenormalizer = $builder->create(FieldDenormalizerInterface::class, [ + new WithCallback('denormalizeField', static function ( + string $givenPath, + object $givenObject, + mixed $givenValue, + DenormalizerContextInterface $givenContext, + ?DenormalizerInterface $givenDenormalizer = null + ) use ($object, $context): void { + self::assertSame('name', $givenPath); + self::assertSame($object, $givenObject); + self::assertSame('name', $givenValue); + self::assertSame($context, $givenContext); + self::assertInstanceOf(DenormalizerInterface::class, $givenDenormalizer); + }), ]); - /** @var DenormalizationFieldMappingInterface|MockObject $denormalizationNameFieldMapping */ - $denormalizationNameFieldMapping = $this->getMockByCalls(DenormalizationFieldMappingInterface::class, [ - Call::create('getName')->with()->willReturn('name'), - Call::create('getPolicy')->with()->willReturn($namePolicy), - Call::create('getFieldDenormalizer')->with()->willReturn($nameFieldDenormalizer), + /** @var DenormalizationFieldMappingInterface $denormalizationNameFieldMapping */ + $denormalizationNameFieldMapping = $builder->create(DenormalizationFieldMappingInterface::class, [ + new WithReturn('getName', [], 'name'), + new WithReturn('getPolicy', [], $namePolicy), + new WithReturn('getFieldDenormalizer', [], $nameFieldDenormalizer), ]); - /** @var DenormalizationFieldMappingInterface|MockObject $denormalizationValueFieldMapping */ - $denormalizationValueFieldMapping = $this->getMockByCalls(DenormalizationFieldMappingInterface::class, [ - Call::create('getName')->with()->willReturn('value'), + /** @var DenormalizationFieldMappingInterface $denormalizationValueFieldMapping */ + $denormalizationValueFieldMapping = $builder->create(DenormalizationFieldMappingInterface::class, [ + new WithReturn('getName', [], 'value'), ]); - /** @var DenormalizationObjectMappingInterface|MockObject $objectMapping */ - $objectMapping = $this->getMockByCalls(DenormalizationObjectMappingInterface::class, [ - Call::create('getDenormalizationFactory')->with('', null)->willReturn($factory), - Call::create('getDenormalizationFieldMappings')->with('', null)->willReturn([ + /** @var DenormalizationObjectMappingInterface $objectMapping */ + $objectMapping = $builder->create(DenormalizationObjectMappingInterface::class, [ + new WithReturn('getDenormalizationFactory', ['', null], $factory), + new WithReturn('getDenormalizationFieldMappings', ['', null], [ $denormalizationNameFieldMapping, $denormalizationValueFieldMapping, ]), ]); - /** @var DenormalizerObjectMappingRegistryInterface|MockObject $registry */ - $registry = $this->getMockByCalls(DenormalizerObjectMappingRegistryInterface::class, [ - Call::create('getObjectMapping')->with(\stdClass::class)->willReturn($objectMapping), + /** @var DenormalizerObjectMappingRegistryInterface $registry */ + $registry = $builder->create(DenormalizerObjectMappingRegistryInterface::class, [ + new WithReturn('getObjectMapping', [\stdClass::class], $objectMapping), ]); - /** @var LoggerInterface|MockObject $logger */ - $logger = $this->getMockByCalls(LoggerInterface::class, [ - Call::create('info')->with('deserialize: path {path}', ['path' => 'name']), + /** @var LoggerInterface $logger */ + $logger = $builder->create(LoggerInterface::class, [ + new WithoutReturn('info', ['deserialize: path {path}', ['path' => 'name']]), ]); $denormalizer = new Denormalizer($registry, $logger); @@ -95,52 +108,65 @@ public function testDenormalizeWithNewAndType(): void $factory = static fn () => $object; - /** @var DenormalizerContextInterface|MockObject $context */ - $context = $this->getMockByCalls(DenormalizerContextInterface::class, [ - Call::create('isClearMissing')->with()->willReturn(false), - Call::create('getAllowedAdditionalFields')->with()->willReturn(null), + $builder = new MockObjectBuilder(); + + /** @var DenormalizerContextInterface $context */ + $context = $builder->create(DenormalizerContextInterface::class, [ + new WithReturn('isClearMissing', [], false), + new WithReturn('getAllowedAdditionalFields', [], null), ]); - /** @var MockObject|PolicyInterface $namePolicy */ - $namePolicy = $this->getMockByCalls(PolicyInterface::class, [ - Call::create('isCompliant')->with('name', $object, $context)->willReturn(true), + /** @var PolicyInterface $namePolicy */ + $namePolicy = $builder->create(PolicyInterface::class, [ + new WithReturn('isCompliant', ['name', $object, $context], true), ]); - /** @var FieldDenormalizerInterface|MockObject $nameFieldDenormalizer */ - $nameFieldDenormalizer = $this->getMockByCalls(FieldDenormalizerInterface::class, [ - Call::create('denormalizeField') - ->with('name', $object, 'name', $context, new ArgumentInstanceOf(DenormalizerInterface::class)), + /** @var FieldDenormalizerInterface $nameFieldDenormalizer */ + $nameFieldDenormalizer = $builder->create(FieldDenormalizerInterface::class, [ + new WithCallback('denormalizeField', static function ( + string $givenPath, + object $givenObject, + mixed $givenValue, + DenormalizerContextInterface $givenContext, + ?DenormalizerInterface $givenDenormalizer = null + ) use ($object, $context): void { + self::assertSame('name', $givenPath); + self::assertSame($object, $givenObject); + self::assertSame('name', $givenValue); + self::assertSame($context, $givenContext); + self::assertInstanceOf(DenormalizerInterface::class, $givenDenormalizer); + }), ]); - /** @var DenormalizationFieldMappingInterface|MockObject $denormalizationNameFieldMapping */ - $denormalizationNameFieldMapping = $this->getMockByCalls(DenormalizationFieldMappingInterface::class, [ - Call::create('getName')->with()->willReturn('name'), - Call::create('getPolicy')->with()->willReturn($namePolicy), - Call::create('getFieldDenormalizer')->with()->willReturn($nameFieldDenormalizer), + /** @var DenormalizationFieldMappingInterface $denormalizationNameFieldMapping */ + $denormalizationNameFieldMapping = $builder->create(DenormalizationFieldMappingInterface::class, [ + new WithReturn('getName', [], 'name'), + new WithReturn('getPolicy', [], $namePolicy), + new WithReturn('getFieldDenormalizer', [], $nameFieldDenormalizer), ]); - /** @var DenormalizationFieldMappingInterface|MockObject $denormalizationValueFieldMapping */ - $denormalizationValueFieldMapping = $this->getMockByCalls(DenormalizationFieldMappingInterface::class, [ - Call::create('getName')->with()->willReturn('value'), + /** @var DenormalizationFieldMappingInterface $denormalizationValueFieldMapping */ + $denormalizationValueFieldMapping = $builder->create(DenormalizationFieldMappingInterface::class, [ + new WithReturn('getName', [], 'value'), ]); - /** @var DenormalizationObjectMappingInterface|MockObject $objectMapping */ - $objectMapping = $this->getMockByCalls(DenormalizationObjectMappingInterface::class, [ - Call::create('getDenormalizationFactory')->with('', 'object')->willReturn($factory), - Call::create('getDenormalizationFieldMappings')->with('', 'object')->willReturn([ + /** @var DenormalizationObjectMappingInterface $objectMapping */ + $objectMapping = $builder->create(DenormalizationObjectMappingInterface::class, [ + new WithReturn('getDenormalizationFactory', ['', 'object'], $factory), + new WithReturn('getDenormalizationFieldMappings', ['', 'object'], [ $denormalizationNameFieldMapping, $denormalizationValueFieldMapping, ]), ]); - /** @var DenormalizerObjectMappingRegistryInterface|MockObject $registry */ - $registry = $this->getMockByCalls(DenormalizerObjectMappingRegistryInterface::class, [ - Call::create('getObjectMapping')->with(\stdClass::class)->willReturn($objectMapping), + /** @var DenormalizerObjectMappingRegistryInterface $registry */ + $registry = $builder->create(DenormalizerObjectMappingRegistryInterface::class, [ + new WithReturn('getObjectMapping', [\stdClass::class], $objectMapping), ]); - /** @var LoggerInterface|MockObject $logger */ - $logger = $this->getMockByCalls(LoggerInterface::class, [ - Call::create('info')->with('deserialize: path {path}', ['path' => 'name']), + /** @var LoggerInterface $logger */ + $logger = $builder->create(LoggerInterface::class, [ + new WithoutReturn('info', ['deserialize: path {path}', ['path' => 'name']]), ]); $denormalizer = new Denormalizer($registry, $logger); @@ -155,51 +181,64 @@ public function testDenormalizeWithExisting(): void { $object = new \stdClass(); - /** @var DenormalizerContextInterface|MockObject $context */ - $context = $this->getMockByCalls(DenormalizerContextInterface::class, [ - Call::create('isClearMissing')->with()->willReturn(false), - Call::create('getAllowedAdditionalFields')->with()->willReturn(null), + $builder = new MockObjectBuilder(); + + /** @var DenormalizerContextInterface $context */ + $context = $builder->create(DenormalizerContextInterface::class, [ + new WithReturn('isClearMissing', [], false), + new WithReturn('getAllowedAdditionalFields', [], null), ]); - /** @var MockObject|PolicyInterface $namePolicy */ - $namePolicy = $this->getMockByCalls(PolicyInterface::class, [ - Call::create('isCompliant')->with('name', $object, $context)->willReturn(true), + /** @var PolicyInterface $namePolicy */ + $namePolicy = $builder->create(PolicyInterface::class, [ + new WithReturn('isCompliant', ['name', $object, $context], true), ]); - /** @var FieldDenormalizerInterface|MockObject $nameFieldDenormalizer */ - $nameFieldDenormalizer = $this->getMockByCalls(FieldDenormalizerInterface::class, [ - Call::create('denormalizeField') - ->with('name', $object, 'name', $context, new ArgumentInstanceOf(DenormalizerInterface::class)), + /** @var FieldDenormalizerInterface $nameFieldDenormalizer */ + $nameFieldDenormalizer = $builder->create(FieldDenormalizerInterface::class, [ + new WithCallback('denormalizeField', static function ( + string $givenPath, + object $givenObject, + mixed $givenValue, + DenormalizerContextInterface $givenContext, + ?DenormalizerInterface $givenDenormalizer = null + ) use ($object, $context): void { + self::assertSame('name', $givenPath); + self::assertSame($object, $givenObject); + self::assertSame('name', $givenValue); + self::assertSame($context, $givenContext); + self::assertInstanceOf(DenormalizerInterface::class, $givenDenormalizer); + }), ]); - /** @var DenormalizationFieldMappingInterface|MockObject $denormalizationNameFieldMapping */ - $denormalizationNameFieldMapping = $this->getMockByCalls(DenormalizationFieldMappingInterface::class, [ - Call::create('getName')->with()->willReturn('name'), - Call::create('getPolicy')->with()->willReturn($namePolicy), - Call::create('getFieldDenormalizer')->with()->willReturn($nameFieldDenormalizer), + /** @var DenormalizationFieldMappingInterface $denormalizationNameFieldMapping */ + $denormalizationNameFieldMapping = $builder->create(DenormalizationFieldMappingInterface::class, [ + new WithReturn('getName', [], 'name'), + new WithReturn('getPolicy', [], $namePolicy), + new WithReturn('getFieldDenormalizer', [], $nameFieldDenormalizer), ]); - /** @var DenormalizationFieldMappingInterface|MockObject $denormalizationValueFieldMapping */ - $denormalizationValueFieldMapping = $this->getMockByCalls(DenormalizationFieldMappingInterface::class, [ - Call::create('getName')->with()->willReturn('value'), + /** @var DenormalizationFieldMappingInterface $denormalizationValueFieldMapping */ + $denormalizationValueFieldMapping = $builder->create(DenormalizationFieldMappingInterface::class, [ + new WithReturn('getName', [], 'value'), ]); - /** @var DenormalizationObjectMappingInterface|MockObject $objectMapping */ - $objectMapping = $this->getMockByCalls(DenormalizationObjectMappingInterface::class, [ - Call::create('getDenormalizationFieldMappings')->with('', null)->willReturn([ + /** @var DenormalizationObjectMappingInterface $objectMapping */ + $objectMapping = $builder->create(DenormalizationObjectMappingInterface::class, [ + new WithReturn('getDenormalizationFieldMappings', ['', null], [ $denormalizationNameFieldMapping, $denormalizationValueFieldMapping, ]), ]); - /** @var DenormalizerObjectMappingRegistryInterface|MockObject $registry */ - $registry = $this->getMockByCalls(DenormalizerObjectMappingRegistryInterface::class, [ - Call::create('getObjectMapping')->with(\stdClass::class)->willReturn($objectMapping), + /** @var DenormalizerObjectMappingRegistryInterface $registry */ + $registry = $builder->create(DenormalizerObjectMappingRegistryInterface::class, [ + new WithReturn('getObjectMapping', [\stdClass::class], $objectMapping), ]); - /** @var LoggerInterface|MockObject $logger */ - $logger = $this->getMockByCalls(LoggerInterface::class, [ - Call::create('info')->with('deserialize: path {path}', ['path' => 'name']), + /** @var LoggerInterface $logger */ + $logger = $builder->create(LoggerInterface::class, [ + new WithoutReturn('info', ['deserialize: path {path}', ['path' => 'name']]), ]); $denormalizer = new Denormalizer($registry, $logger); @@ -211,64 +250,88 @@ public function testDenormalizeWithMoreThanOneDefinitionForOneField(): void { $object = new \stdClass(); - /** @var DenormalizerContextInterface|MockObject $context */ - $context = $this->getMockByCalls(DenormalizerContextInterface::class, [ - Call::create('getAllowedAdditionalFields')->with()->willReturn(null), + $builder = new MockObjectBuilder(); + + /** @var DenormalizerContextInterface $context */ + $context = $builder->create(DenormalizerContextInterface::class, [ + new WithReturn('getAllowedAdditionalFields', [], null), ]); - /** @var MockObject|PolicyInterface $namePolicy1 */ - $namePolicy1 = $this->getMockByCalls(PolicyInterface::class, [ - Call::create('isCompliant')->with('name', $object, $context)->willReturn(true), + /** @var PolicyInterface $namePolicy1 */ + $namePolicy1 = $builder->create(PolicyInterface::class, [ + new WithReturn('isCompliant', ['name', $object, $context], true), ]); - /** @var FieldDenormalizerInterface|MockObject $nameFieldDenormalizer1 */ - $nameFieldDenormalizer1 = $this->getMockByCalls(FieldDenormalizerInterface::class, [ - Call::create('denormalizeField') - ->with('name', $object, 'name', $context, new ArgumentInstanceOf(DenormalizerInterface::class)), + /** @var FieldDenormalizerInterface $nameFieldDenormalizer1 */ + $nameFieldDenormalizer1 = $builder->create(FieldDenormalizerInterface::class, [ + new WithCallback('denormalizeField', static function ( + string $givenPath, + object $givenObject, + mixed $givenValue, + DenormalizerContextInterface $givenContext, + ?DenormalizerInterface $givenDenormalizer = null + ) use ($object, $context): void { + self::assertSame('name', $givenPath); + self::assertSame($object, $givenObject); + self::assertSame('name', $givenValue); + self::assertSame($context, $givenContext); + self::assertInstanceOf(DenormalizerInterface::class, $givenDenormalizer); + }), ]); /** @var DenormalizationFieldMappingInterface $denormalizationNameFieldMapping1 */ - $denormalizationNameFieldMapping1 = $this->getMockByCalls(DenormalizationFieldMappingInterface::class, [ - Call::create('getName')->with()->willReturn('name'), - Call::create('getPolicy')->with()->willReturn($namePolicy1), - Call::create('getFieldDenormalizer')->with()->willReturn($nameFieldDenormalizer1), + $denormalizationNameFieldMapping1 = $builder->create(DenormalizationFieldMappingInterface::class, [ + new WithReturn('getName', [], 'name'), + new WithReturn('getPolicy', [], $namePolicy1), + new WithReturn('getFieldDenormalizer', [], $nameFieldDenormalizer1), ]); - /** @var MockObject|PolicyInterface $namePolicy2 */ - $namePolicy2 = $this->getMockByCalls(PolicyInterface::class, [ - Call::create('isCompliant')->with('name', $object, $context)->willReturn(true), + /** @var PolicyInterface $namePolicy2 */ + $namePolicy2 = $builder->create(PolicyInterface::class, [ + new WithReturn('isCompliant', ['name', $object, $context], true), ]); /** @var FieldDenormalizerInterface $nameFieldDenormalizer2 */ - $nameFieldDenormalizer2 = $this->getMockByCalls(FieldDenormalizerInterface::class, [ - Call::create('denormalizeField') - ->with('name', $object, 'name', $context, new ArgumentInstanceOf(DenormalizerInterface::class)), + $nameFieldDenormalizer2 = $builder->create(FieldDenormalizerInterface::class, [ + new WithCallback('denormalizeField', static function ( + string $givenPath, + object $givenObject, + mixed $givenValue, + DenormalizerContextInterface $givenContext, + ?DenormalizerInterface $givenDenormalizer = null + ) use ($object, $context): void { + self::assertSame('name', $givenPath); + self::assertSame($object, $givenObject); + self::assertSame('name', $givenValue); + self::assertSame($context, $givenContext); + self::assertInstanceOf(DenormalizerInterface::class, $givenDenormalizer); + }), ]); /** @var DenormalizationFieldMappingInterface $denormalizationNameFieldMapping2 */ - $denormalizationNameFieldMapping2 = $this->getMockByCalls(DenormalizationFieldMappingInterface::class, [ - Call::create('getName')->with()->willReturn('name'), - Call::create('getPolicy')->with()->willReturn($namePolicy2), - Call::create('getFieldDenormalizer')->with()->willReturn($nameFieldDenormalizer2), + $denormalizationNameFieldMapping2 = $builder->create(DenormalizationFieldMappingInterface::class, [ + new WithReturn('getName', [], 'name'), + new WithReturn('getPolicy', [], $namePolicy2), + new WithReturn('getFieldDenormalizer', [], $nameFieldDenormalizer2), ]); - /** @var DenormalizationObjectMappingInterface|MockObject $objectMapping */ - $objectMapping = $this->getMockByCalls(DenormalizationObjectMappingInterface::class, [ - Call::create('getDenormalizationFieldMappings')->with('', null)->willReturn([ + /** @var DenormalizationObjectMappingInterface $objectMapping */ + $objectMapping = $builder->create(DenormalizationObjectMappingInterface::class, [ + new WithReturn('getDenormalizationFieldMappings', ['', null], [ $denormalizationNameFieldMapping1, $denormalizationNameFieldMapping2, ]), ]); - /** @var DenormalizerObjectMappingRegistryInterface|MockObject $registry */ - $registry = $this->getMockByCalls(DenormalizerObjectMappingRegistryInterface::class, [ - Call::create('getObjectMapping')->with(\stdClass::class)->willReturn($objectMapping), + /** @var DenormalizerObjectMappingRegistryInterface $registry */ + $registry = $builder->create(DenormalizerObjectMappingRegistryInterface::class, [ + new WithReturn('getObjectMapping', [\stdClass::class], $objectMapping), ]); - /** @var LoggerInterface|MockObject $logger */ - $logger = $this->getMockByCalls(LoggerInterface::class, [ - Call::create('info')->with('deserialize: path {path}', ['path' => 'name']), - Call::create('info')->with('deserialize: path {path}', ['path' => 'name']), + /** @var LoggerInterface $logger */ + $logger = $builder->create(LoggerInterface::class, [ + new WithoutReturn('info', ['deserialize: path {path}', ['path' => 'name']]), + new WithoutReturn('info', ['deserialize: path {path}', ['path' => 'name']]), ]); $denormalizer = new Denormalizer($registry, $logger); @@ -282,66 +345,90 @@ public function testIsCleanMissing(): void $factory = static fn () => $object; - /** @var DenormalizerContextInterface|MockObject $context */ - $context = $this->getMockByCalls(DenormalizerContextInterface::class, [ - Call::create('isClearMissing')->with()->willReturn(true), - Call::create('getAllowedAdditionalFields')->with()->willReturn(null), - ]); - - /** @var MockObject|PolicyInterface $namePolicy */ - $namePolicy = $this->getMockByCalls(PolicyInterface::class, [ - Call::create('isCompliant')->with('name', $object, $context)->willReturn(true), - ]); - - /** @var FieldDenormalizerInterface|MockObject $nameFieldDenormalizer */ - $nameFieldDenormalizer = $this->getMockByCalls(FieldDenormalizerInterface::class, [ - Call::create('denormalizeField') - ->with('name', $object, 'name', $context, new ArgumentInstanceOf(DenormalizerInterface::class)), - ]); - - /** @var DenormalizationFieldMappingInterface|MockObject $denormalizationNameFieldMapping */ - $denormalizationNameFieldMapping = $this->getMockByCalls(DenormalizationFieldMappingInterface::class, [ - Call::create('getName')->with()->willReturn('name'), - Call::create('getPolicy')->with()->willReturn($namePolicy), - Call::create('getFieldDenormalizer')->with()->willReturn($nameFieldDenormalizer), - ]); - - /** @var MockObject|PolicyInterface $valuePolicy */ - $valuePolicy = $this->getMockByCalls(PolicyInterface::class, [ - Call::create('isCompliant')->with('value', $object, $context)->willReturn(true), - ]); - - /** @var FieldDenormalizerInterface|MockObject $valueFieldDenormalizer */ - $valueFieldDenormalizer = $this->getMockByCalls(FieldDenormalizerInterface::class, [ - Call::create('denormalizeField') - ->with('value', $object, null, $context, new ArgumentInstanceOf(DenormalizerInterface::class)), - ]); - - /** @var DenormalizationFieldMappingInterface|MockObject $denormalizationValueFieldMapping */ - $denormalizationValueFieldMapping = $this->getMockByCalls(DenormalizationFieldMappingInterface::class, [ - Call::create('getName')->with()->willReturn('value'), - Call::create('getPolicy')->with()->willReturn($valuePolicy), - Call::create('getFieldDenormalizer')->with()->willReturn($valueFieldDenormalizer), - ]); - - /** @var DenormalizationObjectMappingInterface|MockObject $objectMapping */ - $objectMapping = $this->getMockByCalls(DenormalizationObjectMappingInterface::class, [ - Call::create('getDenormalizationFactory')->with('', 'object')->willReturn($factory), - Call::create('getDenormalizationFieldMappings')->with('', 'object')->willReturn([ + $builder = new MockObjectBuilder(); + + /** @var DenormalizerContextInterface $context */ + $context = $builder->create(DenormalizerContextInterface::class, [ + new WithReturn('isClearMissing', [], true), + new WithReturn('getAllowedAdditionalFields', [], null), + ]); + + /** @var PolicyInterface $namePolicy */ + $namePolicy = $builder->create(PolicyInterface::class, [ + new WithReturn('isCompliant', ['name', $object, $context], true), + ]); + + /** @var FieldDenormalizerInterface $nameFieldDenormalizer */ + $nameFieldDenormalizer = $builder->create(FieldDenormalizerInterface::class, [ + new WithCallback('denormalizeField', static function ( + string $givenPath, + object $givenObject, + mixed $givenValue, + DenormalizerContextInterface $givenContext, + ?DenormalizerInterface $givenDenormalizer = null + ) use ($object, $context): void { + self::assertSame('name', $givenPath); + self::assertSame($object, $givenObject); + self::assertSame('name', $givenValue); + self::assertSame($context, $givenContext); + self::assertInstanceOf(DenormalizerInterface::class, $givenDenormalizer); + }), + ]); + + /** @var DenormalizationFieldMappingInterface $denormalizationNameFieldMapping */ + $denormalizationNameFieldMapping = $builder->create(DenormalizationFieldMappingInterface::class, [ + new WithReturn('getName', [], 'name'), + new WithReturn('getPolicy', [], $namePolicy), + new WithReturn('getFieldDenormalizer', [], $nameFieldDenormalizer), + ]); + + /** @var PolicyInterface $valuePolicy */ + $valuePolicy = $builder->create(PolicyInterface::class, [ + new WithReturn('isCompliant', ['value', $object, $context], true), + ]); + + /** @var FieldDenormalizerInterface $valueFieldDenormalizer */ + $valueFieldDenormalizer = $builder->create(FieldDenormalizerInterface::class, [ + new WithCallback('denormalizeField', static function ( + string $givenPath, + object $givenObject, + mixed $givenValue, + DenormalizerContextInterface $givenContext, + ?DenormalizerInterface $givenDenormalizer = null + ) use ($object, $context): void { + self::assertSame('value', $givenPath); + self::assertSame($object, $givenObject); + self::assertNull($givenValue); + self::assertSame($context, $givenContext); + self::assertInstanceOf(DenormalizerInterface::class, $givenDenormalizer); + }), + ]); + + /** @var DenormalizationFieldMappingInterface $denormalizationValueFieldMapping */ + $denormalizationValueFieldMapping = $builder->create(DenormalizationFieldMappingInterface::class, [ + new WithReturn('getName', [], 'value'), + new WithReturn('getPolicy', [], $valuePolicy), + new WithReturn('getFieldDenormalizer', [], $valueFieldDenormalizer), + ]); + + /** @var DenormalizationObjectMappingInterface $objectMapping */ + $objectMapping = $builder->create(DenormalizationObjectMappingInterface::class, [ + new WithReturn('getDenormalizationFactory', ['', 'object'], $factory), + new WithReturn('getDenormalizationFieldMappings', ['', 'object'], [ $denormalizationNameFieldMapping, $denormalizationValueFieldMapping, ]), ]); - /** @var DenormalizerObjectMappingRegistryInterface|MockObject $registry */ - $registry = $this->getMockByCalls(DenormalizerObjectMappingRegistryInterface::class, [ - Call::create('getObjectMapping')->with(\stdClass::class)->willReturn($objectMapping), + /** @var DenormalizerObjectMappingRegistryInterface $registry */ + $registry = $builder->create(DenormalizerObjectMappingRegistryInterface::class, [ + new WithReturn('getObjectMapping', [\stdClass::class], $objectMapping), ]); - /** @var LoggerInterface|MockObject $logger */ - $logger = $this->getMockByCalls(LoggerInterface::class, [ - Call::create('info')->with('deserialize: path {path}', ['path' => 'name']), - Call::create('info')->with('deserialize: path {path}', ['path' => 'value']), + /** @var LoggerInterface $logger */ + $logger = $builder->create(LoggerInterface::class, [ + new WithoutReturn('info', ['deserialize: path {path}', ['path' => 'name']]), + new WithoutReturn('info', ['deserialize: path {path}', ['path' => 'value']]), ]); $denormalizer = new Denormalizer($registry, $logger); @@ -359,25 +446,24 @@ public function testDenormalizeWithNotWorkingFactory(): void $factory = static fn () => 'string'; - /** @var DenormalizerContextInterface|MockObject $context */ - $context = $this->getMockByCalls(DenormalizerContextInterface::class); + $builder = new MockObjectBuilder(); - /** @var DenormalizationObjectMappingInterface|MockObject $objectMapping */ - $objectMapping = $this->getMockByCalls(DenormalizationObjectMappingInterface::class, [ - Call::create('getDenormalizationFactory')->with('', null)->willReturn($factory), + /** @var DenormalizerContextInterface $context */ + $context = $builder->create(DenormalizerContextInterface::class, []); + + /** @var DenormalizationObjectMappingInterface $objectMapping */ + $objectMapping = $builder->create(DenormalizationObjectMappingInterface::class, [ + new WithReturn('getDenormalizationFactory', ['', null], $factory), ]); - /** @var DenormalizerObjectMappingRegistryInterface|MockObject $registry */ - $registry = $this->getMockByCalls(DenormalizerObjectMappingRegistryInterface::class, [ - Call::create('getObjectMapping')->with(\stdClass::class)->willReturn($objectMapping), + /** @var DenormalizerObjectMappingRegistryInterface $registry */ + $registry = $builder->create(DenormalizerObjectMappingRegistryInterface::class, [ + new WithReturn('getObjectMapping', [\stdClass::class], $objectMapping), ]); - /** @var LoggerInterface|MockObject $logger */ - $logger = $this->getMockByCalls(LoggerInterface::class, [ - Call::create('error') - ->with('deserialize: {exception}', [ - 'exception' => 'Factory does not return object, "string" given at path: ""', - ]), + /** @var LoggerInterface $logger */ + $logger = $builder->create(LoggerInterface::class, [ + new WithoutReturn('error', ['deserialize: {exception}', ['exception' => 'Factory does not return object, "string" given at path: ""']]), ]); $denormalizer = new Denormalizer($registry, $logger); @@ -393,42 +479,42 @@ public function testDenormalizeWithAdditionalData(): void $factory = static fn () => $object; - /** @var DenormalizerContextInterface|MockObject $context */ - $context = $this->getMockByCalls(DenormalizerContextInterface::class, [ - Call::create('isClearMissing')->with()->willReturn(false), - Call::create('isClearMissing')->with()->willReturn(false), - Call::create('getAllowedAdditionalFields')->with()->willReturn([]), + $builder = new MockObjectBuilder(); + + /** @var DenormalizerContextInterface $context */ + $context = $builder->create(DenormalizerContextInterface::class, [ + new WithReturn('isClearMissing', [], false), + new WithReturn('isClearMissing', [], false), + new WithReturn('getAllowedAdditionalFields', [], []), ]); - /** @var DenormalizationFieldMappingInterface|MockObject $denormalizationNameFieldMapping */ - $denormalizationNameFieldMapping = $this->getMockByCalls(DenormalizationFieldMappingInterface::class, [ - Call::create('getName')->with()->willReturn('name'), + /** @var DenormalizationFieldMappingInterface $denormalizationNameFieldMapping */ + $denormalizationNameFieldMapping = $builder->create(DenormalizationFieldMappingInterface::class, [ + new WithReturn('getName', [], 'name'), ]); - /** @var DenormalizationFieldMappingInterface|MockObject $denormalizationValueFieldMapping */ - $denormalizationValueFieldMapping = $this->getMockByCalls(DenormalizationFieldMappingInterface::class, [ - Call::create('getName')->with()->willReturn('value'), + /** @var DenormalizationFieldMappingInterface $denormalizationValueFieldMapping */ + $denormalizationValueFieldMapping = $builder->create(DenormalizationFieldMappingInterface::class, [ + new WithReturn('getName', [], 'value'), ]); - /** @var DenormalizationObjectMappingInterface|MockObject $objectMapping */ - $objectMapping = $this->getMockByCalls(DenormalizationObjectMappingInterface::class, [ - Call::create('getDenormalizationFactory')->with('', null)->willReturn($factory), - Call::create('getDenormalizationFieldMappings')->with('', null)->willReturn([ + /** @var DenormalizationObjectMappingInterface $objectMapping */ + $objectMapping = $builder->create(DenormalizationObjectMappingInterface::class, [ + new WithReturn('getDenormalizationFactory', ['', null], $factory), + new WithReturn('getDenormalizationFieldMappings', ['', null], [ $denormalizationNameFieldMapping, $denormalizationValueFieldMapping, ]), ]); - /** @var DenormalizerObjectMappingRegistryInterface|MockObject $registry */ - $registry = $this->getMockByCalls(DenormalizerObjectMappingRegistryInterface::class, [ - Call::create('getObjectMapping')->with(\stdClass::class)->willReturn($objectMapping), + /** @var DenormalizerObjectMappingRegistryInterface $registry */ + $registry = $builder->create(DenormalizerObjectMappingRegistryInterface::class, [ + new WithReturn('getObjectMapping', [\stdClass::class], $objectMapping), ]); - /** @var LoggerInterface|MockObject $logger */ - $logger = $this->getMockByCalls(LoggerInterface::class, [ - Call::create('notice')->with('deserialize: {exception}', [ - 'exception' => 'There are additional field(s) at paths: "additionalData"', - ]), + /** @var LoggerInterface $logger */ + $logger = $builder->create(LoggerInterface::class, [ + new WithoutReturn('notice', ['deserialize: {exception}', ['exception' => 'There are additional field(s) at paths: "additionalData"']]), ]); $denormalizer = new Denormalizer($registry, $logger); @@ -444,87 +530,90 @@ public function testDenormalizeWithKeyCastToIntegerAdditionalDataExpectsExceptio $factory = static fn () => $object; - /** @var DenormalizerContextInterface|MockObject $context */ - $context = $this->getMockByCalls(DenormalizerContextInterface::class, [ - Call::create('isClearMissing')->with()->willReturn(false), - Call::create('isClearMissing')->with()->willReturn(false), - Call::create('getAllowedAdditionalFields')->with()->willReturn([]), + $builder = new MockObjectBuilder(); + + /** @var DenormalizerContextInterface $context */ + $context = $builder->create(DenormalizerContextInterface::class, [ + new WithReturn('isClearMissing', [], false), + new WithReturn('isClearMissing', [], false), + new WithReturn('getAllowedAdditionalFields', [], []), ]); - /** @var DenormalizationFieldMappingInterface|MockObject $denormalizationNameFieldMapping */ - $denormalizationNameFieldMapping = $this->getMockByCalls(DenormalizationFieldMappingInterface::class, [ - Call::create('getName')->with()->willReturn('name'), + /** @var DenormalizationFieldMappingInterface $denormalizationNameFieldMapping */ + $denormalizationNameFieldMapping = $builder->create(DenormalizationFieldMappingInterface::class, [ + new WithReturn('getName', [], 'name'), ]); - /** @var DenormalizationFieldMappingInterface|MockObject $denormalizationValueFieldMapping */ - $denormalizationValueFieldMapping = $this->getMockByCalls(DenormalizationFieldMappingInterface::class, [ - Call::create('getName')->with()->willReturn('value'), + /** @var DenormalizationFieldMappingInterface $denormalizationValueFieldMapping */ + $denormalizationValueFieldMapping = $builder->create(DenormalizationFieldMappingInterface::class, [ + new WithReturn('getName', [], 'value'), ]); - /** @var DenormalizationObjectMappingInterface|MockObject $objectMapping */ - $objectMapping = $this->getMockByCalls(DenormalizationObjectMappingInterface::class, [ - Call::create('getDenormalizationFactory')->with('', null)->willReturn($factory), - Call::create('getDenormalizationFieldMappings')->with('', null)->willReturn([ + /** @var DenormalizationObjectMappingInterface $objectMapping */ + $objectMapping = $builder->create(DenormalizationObjectMappingInterface::class, [ + new WithReturn('getDenormalizationFactory', ['', null], $factory), + new WithReturn('getDenormalizationFieldMappings', ['', null], [ $denormalizationNameFieldMapping, $denormalizationValueFieldMapping, ]), ]); - /** @var DenormalizerObjectMappingRegistryInterface|MockObject $registry */ - $registry = $this->getMockByCalls(DenormalizerObjectMappingRegistryInterface::class, [ - Call::create('getObjectMapping')->with(\stdClass::class)->willReturn($objectMapping), + /** @var DenormalizerObjectMappingRegistryInterface $registry */ + $registry = $builder->create(DenormalizerObjectMappingRegistryInterface::class, [ + new WithReturn('getObjectMapping', [\stdClass::class], $objectMapping), ]); - /** @var LoggerInterface|MockObject $logger */ - $logger = $this->getMockByCalls(LoggerInterface::class, [ - Call::create('notice')->with('deserialize: {exception}', [ - 'exception' => 'There are additional field(s) at paths: "1"', - ]), + /** @var LoggerInterface $logger */ + $logger = $builder->create(LoggerInterface::class, [ + new WithoutReturn('notice', ['deserialize: {exception}', ['exception' => 'There are additional field(s) at paths: "1"']]), ]); $denormalizer = new Denormalizer($registry, $logger); $denormalizer->denormalize(\stdClass::class, ['1' => 'additionalData'], $context); } + #[DoesNotPerformAssertions] public function testDenormalizeWithAdditionalDataAndAllowIt(): void { $object = new \stdClass(); $factory = static fn () => $object; - /** @var DenormalizerContextInterface|MockObject $context */ - $context = $this->getMockByCalls(DenormalizerContextInterface::class, [ - Call::create('isClearMissing')->with()->willReturn(false), - Call::create('isClearMissing')->with()->willReturn(false), - Call::create('getAllowedAdditionalFields')->with()->willReturn(null), + $builder = new MockObjectBuilder(); + + /** @var DenormalizerContextInterface $context */ + $context = $builder->create(DenormalizerContextInterface::class, [ + new WithReturn('isClearMissing', [], false), + new WithReturn('isClearMissing', [], false), + new WithReturn('getAllowedAdditionalFields', [], null), ]); - /** @var DenormalizationFieldMappingInterface|MockObject $denormalizationNameFieldMapping */ - $denormalizationNameFieldMapping = $this->getMockByCalls(DenormalizationFieldMappingInterface::class, [ - Call::create('getName')->with()->willReturn('name'), + /** @var DenormalizationFieldMappingInterface $denormalizationNameFieldMapping */ + $denormalizationNameFieldMapping = $builder->create(DenormalizationFieldMappingInterface::class, [ + new WithReturn('getName', [], 'name'), ]); - /** @var DenormalizationFieldMappingInterface|MockObject $denormalizationValueFieldMapping */ - $denormalizationValueFieldMapping = $this->getMockByCalls(DenormalizationFieldMappingInterface::class, [ - Call::create('getName')->with()->willReturn('value'), + /** @var DenormalizationFieldMappingInterface $denormalizationValueFieldMapping */ + $denormalizationValueFieldMapping = $builder->create(DenormalizationFieldMappingInterface::class, [ + new WithReturn('getName', [], 'value'), ]); - /** @var DenormalizationObjectMappingInterface|MockObject $objectMapping */ - $objectMapping = $this->getMockByCalls(DenormalizationObjectMappingInterface::class, [ - Call::create('getDenormalizationFactory')->with('', null)->willReturn($factory), - Call::create('getDenormalizationFieldMappings')->with('', null)->willReturn([ + /** @var DenormalizationObjectMappingInterface $objectMapping */ + $objectMapping = $builder->create(DenormalizationObjectMappingInterface::class, [ + new WithReturn('getDenormalizationFactory', ['', null], $factory), + new WithReturn('getDenormalizationFieldMappings', ['', null], [ $denormalizationNameFieldMapping, $denormalizationValueFieldMapping, ]), ]); - /** @var DenormalizerObjectMappingRegistryInterface|MockObject $registry */ - $registry = $this->getMockByCalls(DenormalizerObjectMappingRegistryInterface::class, [ - Call::create('getObjectMapping')->with(\stdClass::class)->willReturn($objectMapping), + /** @var DenormalizerObjectMappingRegistryInterface $registry */ + $registry = $builder->create(DenormalizerObjectMappingRegistryInterface::class, [ + new WithReturn('getObjectMapping', [\stdClass::class], $objectMapping), ]); - /** @var LoggerInterface|MockObject $logger */ - $logger = $this->getMockByCalls(LoggerInterface::class); + /** @var LoggerInterface $logger */ + $logger = $builder->create(LoggerInterface::class, []); $denormalizer = new Denormalizer($registry, $logger); $denormalizer->denormalize(\stdClass::class, ['additionalData' => 'additionalData'], $context); @@ -537,19 +626,19 @@ public function testDenormalizeWithMissingObjectMapping(): void $exception = DeserializerLogicException::createMissingMapping(\stdClass::class); - /** @var DenormalizerContextInterface|MockObject $context */ - $context = $this->getMockByCalls(DenormalizerContextInterface::class); + $builder = new MockObjectBuilder(); + + /** @var DenormalizerContextInterface $context */ + $context = $builder->create(DenormalizerContextInterface::class, []); - /** @var DenormalizerObjectMappingRegistryInterface|MockObject $registry */ - $registry = $this->getMockByCalls(DenormalizerObjectMappingRegistryInterface::class, [ - Call::create('getObjectMapping')->with(\stdClass::class)->willThrowException($exception), + /** @var DenormalizerObjectMappingRegistryInterface $registry */ + $registry = $builder->create(DenormalizerObjectMappingRegistryInterface::class, [ + new WithException('getObjectMapping', [\stdClass::class], $exception), ]); - /** @var LoggerInterface|MockObject $logger */ - $logger = $this->getMockByCalls(LoggerInterface::class, [ - Call::create('error')->with('deserialize: {exception}', [ - 'exception' => 'There is no mapping for class: "stdClass"', - ]), + /** @var LoggerInterface $logger */ + $logger = $builder->create(LoggerInterface::class, [ + new WithReturn('error', ['deserialize: {exception}', ['exception' => 'There is no mapping for class: "stdClass"']], null), ]); $denormalizer = new Denormalizer($registry, $logger); @@ -562,44 +651,46 @@ public function testDenormalizeWithNotCompliantPolicy(): void $factory = static fn () => $object; - /** @var DenormalizerContextInterface|MockObject $context */ - $context = $this->getMockByCalls(DenormalizerContextInterface::class, [ - Call::create('isClearMissing')->with()->willReturn(false), - Call::create('getAllowedAdditionalFields')->with()->willReturn(null), + $builder = new MockObjectBuilder(); + + /** @var DenormalizerContextInterface $context */ + $context = $builder->create(DenormalizerContextInterface::class, [ + new WithReturn('isClearMissing', [], false), + new WithReturn('getAllowedAdditionalFields', [], null), ]); - /** @var MockObject|PolicyInterface $namePolicy */ - $namePolicy = $this->getMockByCalls(PolicyInterface::class, [ - Call::create('isCompliant')->with('name', $object, $context)->willReturn(false), + /** @var PolicyInterface $namePolicy */ + $namePolicy = $builder->create(PolicyInterface::class, [ + new WithReturn('isCompliant', ['name', $object, $context], false), ]); - /** @var DenormalizationFieldMappingInterface|MockObject $denormalizationNameFieldMapping */ - $denormalizationNameFieldMapping = $this->getMockByCalls(DenormalizationFieldMappingInterface::class, [ - Call::create('getName')->with()->willReturn('name'), - Call::create('getPolicy')->with()->willReturn($namePolicy), + /** @var DenormalizationFieldMappingInterface $denormalizationNameFieldMapping */ + $denormalizationNameFieldMapping = $builder->create(DenormalizationFieldMappingInterface::class, [ + new WithReturn('getName', [], 'name'), + new WithReturn('getPolicy', [], $namePolicy), ]); - /** @var DenormalizationFieldMappingInterface|MockObject $denormalizationValueFieldMapping */ - $denormalizationValueFieldMapping = $this->getMockByCalls(DenormalizationFieldMappingInterface::class, [ - Call::create('getName')->with()->willReturn('value'), + /** @var DenormalizationFieldMappingInterface $denormalizationValueFieldMapping */ + $denormalizationValueFieldMapping = $builder->create(DenormalizationFieldMappingInterface::class, [ + new WithReturn('getName', [], 'value'), ]); - /** @var DenormalizationObjectMappingInterface|MockObject $objectMapping */ - $objectMapping = $this->getMockByCalls(DenormalizationObjectMappingInterface::class, [ - Call::create('getDenormalizationFactory')->with('', null)->willReturn($factory), - Call::create('getDenormalizationFieldMappings')->with('', null)->willReturn([ + /** @var DenormalizationObjectMappingInterface $objectMapping */ + $objectMapping = $builder->create(DenormalizationObjectMappingInterface::class, [ + new WithReturn('getDenormalizationFactory', ['', null], $factory), + new WithReturn('getDenormalizationFieldMappings', ['', null], [ $denormalizationNameFieldMapping, $denormalizationValueFieldMapping, ]), ]); - /** @var DenormalizerObjectMappingRegistryInterface|MockObject $registry */ - $registry = $this->getMockByCalls(DenormalizerObjectMappingRegistryInterface::class, [ - Call::create('getObjectMapping')->with(\stdClass::class)->willReturn($objectMapping), + /** @var DenormalizerObjectMappingRegistryInterface $registry */ + $registry = $builder->create(DenormalizerObjectMappingRegistryInterface::class, [ + new WithReturn('getObjectMapping', [\stdClass::class], $objectMapping), ]); - /** @var LoggerInterface|MockObject $logger */ - $logger = $this->getMockByCalls(LoggerInterface::class); + /** @var LoggerInterface $logger */ + $logger = $builder->create(LoggerInterface::class, []); $denormalizer = new Denormalizer($registry, $logger); @@ -611,15 +702,17 @@ public function testDenormalizeWithInvalidType(): void $this->expectException(DeserializerRuntimeException::class); $this->expectExceptionMessage('Type is not a string, "array" given at path: ""'); - /** @var DenormalizerContextInterface|MockObject $context */ - $context = $this->getMockByCalls(DenormalizerContextInterface::class); + $builder = new MockObjectBuilder(); + + /** @var DenormalizerContextInterface $context */ + $context = $builder->create(DenormalizerContextInterface::class, []); - /** @var DenormalizerObjectMappingRegistryInterface|MockObject $registry */ - $registry = $this->getMockByCalls(DenormalizerObjectMappingRegistryInterface::class); + /** @var DenormalizerObjectMappingRegistryInterface $registry */ + $registry = $builder->create(DenormalizerObjectMappingRegistryInterface::class, []); - /** @var LoggerInterface|MockObject $logger */ - $logger = $this->getMockByCalls(LoggerInterface::class, [ - Call::create('error')->with('deserialize: {exception}', ['exception' => 'Type is not a string, "array" given at path: ""']), + /** @var LoggerInterface $logger */ + $logger = $builder->create(LoggerInterface::class, [ + new WithReturn('error', ['deserialize: {exception}', ['exception' => 'Type is not a string, "array" given at path: ""']], null), ]); $denormalizer = new Denormalizer($registry, $logger); diff --git a/tests/Unit/Denormalizer/FieldDenormalizerTest.php b/tests/Unit/Denormalizer/FieldDenormalizerTest.php index 30bcb23..889505c 100644 --- a/tests/Unit/Denormalizer/FieldDenormalizerTest.php +++ b/tests/Unit/Denormalizer/FieldDenormalizerTest.php @@ -7,9 +7,9 @@ use Chubbyphp\Deserialization\Accessor\AccessorInterface; use Chubbyphp\Deserialization\Denormalizer\DenormalizerContextInterface; use Chubbyphp\Deserialization\Denormalizer\FieldDenormalizer; -use Chubbyphp\Mock\Call; -use Chubbyphp\Mock\MockByCallsTrait; -use PHPUnit\Framework\MockObject\MockObject; +use Chubbyphp\Mock\MockMethod\WithReturn; +use Chubbyphp\Mock\MockObjectBuilder; +use PHPUnit\Framework\Attributes\DoesNotPerformAssertions; use PHPUnit\Framework\TestCase; /** @@ -19,51 +19,56 @@ */ final class FieldDenormalizerTest extends TestCase { - use MockByCallsTrait; - + #[DoesNotPerformAssertions] public function testDenormalizeField(): void { $object = new \stdClass(); - /** @var AccessorInterface|MockObject $accessor */ - $accessor = $this->getMockByCalls(AccessorInterface::class, [ - Call::create('setValue')->with($object, 'name'), + $builder = new MockObjectBuilder(); + + /** @var AccessorInterface $accessor */ + $accessor = $builder->create(AccessorInterface::class, [ + new WithReturn('setValue', [$object, 'name'], null), ]); - /** @var DenormalizerContextInterface|MockObject $context */ - $context = $this->getMockByCalls(DenormalizerContextInterface::class); + /** @var DenormalizerContextInterface $context */ + $context = $builder->create(DenormalizerContextInterface::class, []); $fieldDenormalizer = new FieldDenormalizer($accessor); $fieldDenormalizer->denormalizeField('name', $object, 'name', $context); } + #[DoesNotPerformAssertions] public function testDenormalizeFieldWithEmptyToNullDisabled(): void { $object = new \stdClass(); - /** @var AccessorInterface|MockObject $accessor */ - $accessor = $this->getMockByCalls(AccessorInterface::class, [ - Call::create('setValue')->with($object, ''), + $builder = new MockObjectBuilder(); + + /** @var AccessorInterface $accessor */ + $accessor = $builder->create(AccessorInterface::class, [ + new WithReturn('setValue', [$object, ''], null), ]); - /** @var DenormalizerContextInterface|MockObject $context */ - $context = $this->getMockByCalls(DenormalizerContextInterface::class); + $context = $builder->create(DenormalizerContextInterface::class, []); $fieldDenormalizer = new FieldDenormalizer($accessor); $fieldDenormalizer->denormalizeField('name', $object, '', $context); } + #[DoesNotPerformAssertions] public function testDenormalizeFieldWithEmptyToNullEnabled(): void { $object = new \stdClass(); - /** @var AccessorInterface|MockObject $accessor */ - $accessor = $this->getMockByCalls(AccessorInterface::class, [ - Call::create('setValue')->with($object, null), + $builder = new MockObjectBuilder(); + + /** @var AccessorInterface $accessor */ + $accessor = $builder->create(AccessorInterface::class, [ + new WithReturn('setValue', [$object, null], null), ]); - /** @var DenormalizerContextInterface|MockObject $context */ - $context = $this->getMockByCalls(DenormalizerContextInterface::class); + $context = $builder->create(DenormalizerContextInterface::class, []); $fieldDenormalizer = new FieldDenormalizer($accessor, true); $fieldDenormalizer->denormalizeField('name', $object, '', $context); diff --git a/tests/Unit/Denormalizer/Relation/EmbedManyFieldDenormalizerTest.php b/tests/Unit/Denormalizer/Relation/EmbedManyFieldDenormalizerTest.php index bb4f19c..1d6babe 100644 --- a/tests/Unit/Denormalizer/Relation/EmbedManyFieldDenormalizerTest.php +++ b/tests/Unit/Denormalizer/Relation/EmbedManyFieldDenormalizerTest.php @@ -10,10 +10,11 @@ use Chubbyphp\Deserialization\Denormalizer\Relation\EmbedManyFieldDenormalizer; use Chubbyphp\Deserialization\DeserializerLogicException; use Chubbyphp\Deserialization\DeserializerRuntimeException; -use Chubbyphp\Mock\Call; -use Chubbyphp\Mock\MockByCallsTrait; +use Chubbyphp\Mock\MockMethod\WithoutReturn; +use Chubbyphp\Mock\MockMethod\WithReturn; +use Chubbyphp\Mock\MockObjectBuilder; use Doctrine\Common\Collections\Collection; -use PHPUnit\Framework\MockObject\MockObject; +use PHPUnit\Framework\Attributes\DoesNotPerformAssertions; use PHPUnit\Framework\TestCase; /** @@ -23,8 +24,6 @@ */ final class EmbedManyFieldDenormalizerTest extends TestCase { - use MockByCallsTrait; - public function testDenormalizeFieldWithMissingDenormalizer(): void { $this->expectException(DeserializerLogicException::class); @@ -32,11 +31,13 @@ public function testDenormalizeFieldWithMissingDenormalizer(): void $parent = new \stdClass(); - /** @var AccessorInterface|MockObject $accessor */ - $accessor = $this->getMockByCalls(AccessorInterface::class); + $builder = new MockObjectBuilder(); + + /** @var AccessorInterface $accessor */ + $accessor = $builder->create(AccessorInterface::class, []); - /** @var DenormalizerContextInterface|MockObject $context */ - $context = $this->getMockByCalls(DenormalizerContextInterface::class); + /** @var DenormalizerContextInterface $context */ + $context = $builder->create(DenormalizerContextInterface::class, []); $fieldDenormalizer = new EmbedManyFieldDenormalizer(\stdClass::class, $accessor); $fieldDenormalizer->denormalizeField('children', $parent, [['name' => 'name']], $context); @@ -49,14 +50,16 @@ public function testDenormalizeFieldWithoutArrayDenormalizer(): void $parent = new \stdClass(); - /** @var AccessorInterface|MockObject $accessor */ - $accessor = $this->getMockByCalls(AccessorInterface::class); + $builder = new MockObjectBuilder(); - /** @var DenormalizerContextInterface|MockObject $context */ - $context = $this->getMockByCalls(DenormalizerContextInterface::class); + /** @var AccessorInterface $accessor */ + $accessor = $builder->create(AccessorInterface::class, []); - /** @var DenormalizerInterface|MockObject $denormalizer */ - $denormalizer = $this->getMockByCalls(DenormalizerInterface::class); + /** @var DenormalizerContextInterface $context */ + $context = $builder->create(DenormalizerContextInterface::class, []); + + /** @var DenormalizerInterface $denormalizer */ + $denormalizer = $builder->create(DenormalizerInterface::class, []); $fieldDenormalizer = new EmbedManyFieldDenormalizer(\stdClass::class, $accessor); $fieldDenormalizer->denormalizeField('children', $parent, 'test', $context, $denormalizer); @@ -69,194 +72,212 @@ public function testDenormalizeFieldWithArrayButStringChildDenormalizer(): void $parent = new \stdClass(); - /** @var AccessorInterface|MockObject $accessor */ - $accessor = $this->getMockByCalls(AccessorInterface::class, [ - Call::create('getValue')->with($parent)->willReturn([]), + $builder = new MockObjectBuilder(); + + /** @var AccessorInterface $accessor */ + $accessor = $builder->create(AccessorInterface::class, [ + new WithReturn('getValue', [$parent], []), ]); - /** @var DenormalizerContextInterface|MockObject $context */ - $context = $this->getMockByCalls(DenormalizerContextInterface::class); + /** @var DenormalizerContextInterface $context */ + $context = $builder->create(DenormalizerContextInterface::class, []); - /** @var DenormalizerInterface|MockObject $denormalizer */ - $denormalizer = $this->getMockByCalls(DenormalizerInterface::class); + /** @var DenormalizerInterface $denormalizer */ + $denormalizer = $builder->create(DenormalizerInterface::class, []); $fieldDenormalizer = new EmbedManyFieldDenormalizer(\stdClass::class, $accessor); $fieldDenormalizer->denormalizeField('children', $parent, ['test'], $context, $denormalizer); } + #[DoesNotPerformAssertions] public function testDenormalizeFieldWithNull(): void { $parent = new \stdClass(); - /** @var AccessorInterface|MockObject $accessor */ - $accessor = $this->getMockByCalls(AccessorInterface::class, [ - Call::create('getValue')->with($parent)->willReturn([]), - Call::create('setValue')->with($parent, []), + $builder = new MockObjectBuilder(); + + $accessor = $builder->create(AccessorInterface::class, [ + new WithReturn('getValue', [$parent], []), + new WithoutReturn('setValue', [$parent, []]), ]); - /** @var DenormalizerContextInterface|MockObject $context */ - $context = $this->getMockByCalls(DenormalizerContextInterface::class); + /** @var DenormalizerContextInterface $context */ + $context = $builder->create(DenormalizerContextInterface::class, []); - /** @var DenormalizerInterface|MockObject $denormalizer */ - $denormalizer = $this->getMockByCalls(DenormalizerInterface::class); + /** @var DenormalizerInterface $denormalizer */ + $denormalizer = $builder->create(DenormalizerInterface::class, []); $fieldDenormalizer = new EmbedManyFieldDenormalizer(\stdClass::class, $accessor); $fieldDenormalizer->denormalizeField('children', $parent, null, $context, $denormalizer); } + #[DoesNotPerformAssertions] public function testDenormalizeFieldWithSubValueNull(): void { $parent = new \stdClass(); - $child = new \stdClass(); - /** @var AccessorInterface|MockObject $accessor */ - $accessor = $this->getMockByCalls(AccessorInterface::class, [ - Call::create('getValue')->with($parent)->willReturn([]), - Call::create('setValue')->with($parent, [$child]), + $builder = new MockObjectBuilder(); + + /** @var AccessorInterface $accessor */ + $accessor = $builder->create(AccessorInterface::class, [ + new WithReturn('getValue', [$parent], []), + new WithoutReturn('setValue', [$parent, [$child]]), ]); - /** @var DenormalizerContextInterface|MockObject $context */ - $context = $this->getMockByCalls(DenormalizerContextInterface::class); + /** @var DenormalizerContextInterface $context */ + $context = $builder->create(DenormalizerContextInterface::class, []); - /** @var DenormalizerInterface|MockObject $denormalizer */ - $denormalizer = $this->getMockByCalls(DenormalizerInterface::class, [ - Call::create('denormalize') - ->with(\stdClass::class, [], $context, 'children[0]') - ->willReturn($child), + /** @var DenormalizerInterface $denormalizer */ + $denormalizer = $builder->create(DenormalizerInterface::class, [ + new WithReturn( + 'denormalize', + [\stdClass::class, [], $context, 'children[0]'], + $child + ), ]); $fieldDenormalizer = new EmbedManyFieldDenormalizer(\stdClass::class, $accessor); $fieldDenormalizer->denormalizeField('children', $parent, [null], $context, $denormalizer); } + #[DoesNotPerformAssertions] public function testDenormalizeFieldWithNewChild(): void { $parent = new \stdClass(); $child = new \stdClass(); - /** @var AccessorInterface|MockObject $accessor */ - $accessor = $this->getMockByCalls(AccessorInterface::class, [ - Call::create('getValue')->with($parent)->willReturn([]), - Call::create('setValue')->with($parent, [$child]), + $builder = new MockObjectBuilder(); + + /** @var AccessorInterface $accessor */ + $accessor = $builder->create(AccessorInterface::class, [ + new WithReturn('getValue', [$parent], []), + new WithoutReturn('setValue', [$parent, [$child]]), ]); - /** @var DenormalizerContextInterface|MockObject $context */ - $context = $this->getMockByCalls(DenormalizerContextInterface::class); + /** @var DenormalizerContextInterface $context */ + $context = $builder->create(DenormalizerContextInterface::class, []); - /** @var DenormalizerInterface|MockObject $denormalizer */ - $denormalizer = $this->getMockByCalls(DenormalizerInterface::class, [ - Call::create('denormalize') - ->with(\stdClass::class, ['name' => 'name'], $context, 'children[0]') - ->willReturn($child), + /** @var DenormalizerInterface $denormalizer */ + $denormalizer = $builder->create(DenormalizerInterface::class, [ + new WithReturn( + 'denormalize', + [\stdClass::class, ['name' => 'name'], $context, 'children[0]'], + $child + ), ]); $fieldDenormalizer = new EmbedManyFieldDenormalizer(\stdClass::class, $accessor); $fieldDenormalizer->denormalizeField('children', $parent, [['name' => 'name']], $context, $denormalizer); } + #[DoesNotPerformAssertions] public function testDenormalizeFieldWithNewChildAndCollection(): void { $parent = new \stdClass(); $child = new \stdClass(); - /** @var \Iterator|MockObject $iterator */ - $iterator = $this->getMockByCalls(\Iterator::class, [ - Call::create('rewind')->with(), - Call::create('valid')->with()->willReturn(false), + $builder = new MockObjectBuilder(); + + /** @var \Iterator $iterator */ + $iterator = $builder->create(\Iterator::class, [ + new WithoutReturn('rewind', []), + new WithReturn('valid', [], false), ]); - /** @var Collection|MockObject $collection */ - $collection = $this->getMockByCalls(Collection::class, [ - Call::create('getIterator')->with()->willReturn($iterator), - Call::create('offsetSet')->with(0, $child), + /** @var Collection $collection */ + $collection = $builder->create(Collection::class, [ + new WithReturn('getIterator', [], $iterator), + new WithoutReturn('offsetSet', [0, $child]), ]); - /** @var AccessorInterface|MockObject $accessor */ - $accessor = $this->getMockByCalls(AccessorInterface::class, [ - Call::create('getValue')->with($parent)->willReturn($collection), - Call::create('setValue')->with($parent, $collection), + /** @var AccessorInterface $accessor */ + $accessor = $builder->create(AccessorInterface::class, [ + new WithReturn('getValue', [$parent], $collection), + new WithoutReturn('setValue', [$parent, $collection]), ]); - /** @var DenormalizerContextInterface|MockObject $context */ - $context = $this->getMockByCalls(DenormalizerContextInterface::class); + /** @var DenormalizerContextInterface $context */ + $context = $builder->create(DenormalizerContextInterface::class, []); - /** @var DenormalizerInterface|MockObject $denormalizer */ - $denormalizer = $this->getMockByCalls(DenormalizerInterface::class, [ - Call::create('denormalize') - ->with(\stdClass::class, ['name' => 'name'], $context, 'children[0]') - ->willReturn($child), + /** @var DenormalizerInterface $denormalizer */ + $denormalizer = $builder->create(DenormalizerInterface::class, [ + new WithReturn( + 'denormalize', + [\stdClass::class, ['name' => 'name'], $context, 'children[0]'], + $child + ), ]); $fieldDenormalizer = new EmbedManyFieldDenormalizer(\stdClass::class, $accessor); $fieldDenormalizer->denormalizeField('children', $parent, [['name' => 'name']], $context, $denormalizer); } + #[DoesNotPerformAssertions] public function testDenormalizeFieldWithExistingChild(): void { $parent = new \stdClass(); - $child = new \stdClass(); - /** @var AccessorInterface|MockObject $accessor */ - $accessor = $this->getMockByCalls(AccessorInterface::class, [ - Call::create('getValue')->with($parent)->willReturn([$child]), - Call::create('setValue')->with($parent, [$child]), + $builder = new MockObjectBuilder(); + + /** @var AccessorInterface $accessor */ + $accessor = $builder->create(AccessorInterface::class, [ + new WithReturn('getValue', [$parent], [$child]), + new WithoutReturn('setValue', [$parent, [$child]]), ]); - /** @var DenormalizerContextInterface|MockObject $context */ - $context = $this->getMockByCalls(DenormalizerContextInterface::class); + /** @var DenormalizerContextInterface $context */ + $context = $builder->create(DenormalizerContextInterface::class, []); - /** @var DenormalizerInterface|MockObject $denormalizer */ - $denormalizer = $this->getMockByCalls(DenormalizerInterface::class, [ - Call::create('denormalize') - ->with($child, ['name' => 'name'], $context, 'children[0]') - ->willReturn($child), + /** @var DenormalizerInterface $denormalizer */ + $denormalizer = $builder->create(DenormalizerInterface::class, [ + new WithReturn('denormalize', [$child, ['name' => 'name'], $context, 'children[0]'], $child), ]); $fieldDenormalizer = new EmbedManyFieldDenormalizer(\stdClass::class, $accessor); $fieldDenormalizer->denormalizeField('children', $parent, [['name' => 'name']], $context, $denormalizer); } + #[DoesNotPerformAssertions] public function testDenormalizeFieldWithExistingChildAndCollection(): void { $parent = new \stdClass(); - $child = new \stdClass(); - /** @var \Iterator|MockObject $iterator */ - $iterator = $this->getMockByCalls(\Iterator::class, [ - Call::create('rewind')->with(), - Call::create('valid')->with()->willReturn(true), - Call::create('current')->with()->willReturn($child), - Call::create('key')->with()->willReturn(0), - Call::create('next')->with(), - Call::create('valid')->with()->willReturn(false), + $builder = new MockObjectBuilder(); + + /** @var \Iterator $iterator */ + $iterator = $builder->create(\Iterator::class, [ + new WithoutReturn('rewind', []), + new WithReturn('valid', [], true), + new WithReturn('current', [], $child), + new WithReturn('key', [], 0), + new WithoutReturn('next', []), + new WithReturn('valid', [], false), ]); - /** @var Collection|MockObject $collection */ - $collection = $this->getMockByCalls(Collection::class, [ - Call::create('getIterator')->with()->willReturn($iterator), - Call::create('offsetUnset')->with(0), - Call::create('offsetSet')->with(0, $child), + /** @var Collection $collection */ + $collection = $builder->create(Collection::class, [ + new WithReturn('getIterator', [], $iterator), + new WithoutReturn('offsetUnset', [0]), + new WithoutReturn('offsetSet', [0, $child]), ]); - /** @var AccessorInterface|MockObject $accessor */ - $accessor = $this->getMockByCalls(AccessorInterface::class, [ - Call::create('getValue')->with($parent)->willReturn($collection), - Call::create('setValue')->with($parent, $collection), + /** @var AccessorInterface $accessor */ + $accessor = $builder->create(AccessorInterface::class, [ + new WithReturn('getValue', [$parent], $collection), + new WithoutReturn('setValue', [$parent, $collection]), ]); - /** @var DenormalizerContextInterface|MockObject $context */ - $context = $this->getMockByCalls(DenormalizerContextInterface::class); + /** @var DenormalizerContextInterface $context */ + $context = $builder->create(DenormalizerContextInterface::class, []); - /** @var DenormalizerInterface|MockObject $denormalizer */ - $denormalizer = $this->getMockByCalls(DenormalizerInterface::class, [ - Call::create('denormalize') - ->with($child, ['name' => 'name'], $context, 'children[0]') - ->willReturn($child), + /** @var DenormalizerInterface $denormalizer */ + $denormalizer = $builder->create(DenormalizerInterface::class, [ + new WithReturn('denormalize', [$child, ['name' => 'name'], $context, 'children[0]'], $child), ]); $fieldDenormalizer = new EmbedManyFieldDenormalizer(\stdClass::class, $accessor); diff --git a/tests/Unit/Denormalizer/Relation/EmbedOneFieldDenormalizerTest.php b/tests/Unit/Denormalizer/Relation/EmbedOneFieldDenormalizerTest.php index 05de5a6..e1aa19a 100644 --- a/tests/Unit/Denormalizer/Relation/EmbedOneFieldDenormalizerTest.php +++ b/tests/Unit/Denormalizer/Relation/EmbedOneFieldDenormalizerTest.php @@ -10,9 +10,10 @@ use Chubbyphp\Deserialization\Denormalizer\Relation\EmbedOneFieldDenormalizer; use Chubbyphp\Deserialization\DeserializerLogicException; use Chubbyphp\Deserialization\DeserializerRuntimeException; -use Chubbyphp\Mock\Call; -use Chubbyphp\Mock\MockByCallsTrait; -use PHPUnit\Framework\MockObject\MockObject; +use Chubbyphp\Mock\MockMethod\WithoutReturn; +use Chubbyphp\Mock\MockMethod\WithReturn; +use Chubbyphp\Mock\MockObjectBuilder; +use PHPUnit\Framework\Attributes\DoesNotPerformAssertions; use PHPUnit\Framework\TestCase; /** @@ -22,8 +23,6 @@ */ final class EmbedOneFieldDenormalizerTest extends TestCase { - use MockByCallsTrait; - public function testDenormalizeFieldWithMissingDenormalizer(): void { $this->expectException(DeserializerLogicException::class); @@ -31,11 +30,13 @@ public function testDenormalizeFieldWithMissingDenormalizer(): void $object = new \stdClass(); - /** @var AccessorInterface|MockObject $accessor */ - $accessor = $this->getMockByCalls(AccessorInterface::class); + $builder = new MockObjectBuilder(); + + /** @var AccessorInterface $accessor */ + $accessor = $builder->create(AccessorInterface::class, []); - /** @var DenormalizerContextInterface|MockObject $context */ - $context = $this->getMockByCalls(DenormalizerContextInterface::class); + /** @var DenormalizerContextInterface $context */ + $context = $builder->create(DenormalizerContextInterface::class, []); $fieldDenormalizer = new EmbedOneFieldDenormalizer(\stdClass::class, $accessor); $fieldDenormalizer->denormalizeField('reference', $object, ['name' => 'name'], $context); @@ -47,147 +48,166 @@ public function testDenormalizeFieldWithWrongType(): void $this->expectExceptionMessage('There is an invalid data type "string", needed "array" at path: "reference"'); $object = new \stdClass(); + $builder = new MockObjectBuilder(); - /** @var AccessorInterface|MockObject $accessor */ - $accessor = $this->getMockByCalls(AccessorInterface::class); + /** @var AccessorInterface $accessor */ + $accessor = $builder->create(AccessorInterface::class, []); - /** @var DenormalizerContextInterface|MockObject $context */ - $context = $this->getMockByCalls(DenormalizerContextInterface::class); + /** @var DenormalizerContextInterface $context */ + $context = $builder->create(DenormalizerContextInterface::class, []); - /** @var DenormalizerInterface|MockObject $denormalizer */ - $denormalizer = $this->getMockByCalls(DenormalizerInterface::class); + /** @var DenormalizerInterface $denormalizer */ + $denormalizer = $builder->create(DenormalizerInterface::class, []); $fieldDenormalizer = new EmbedOneFieldDenormalizer(\stdClass::class, $accessor); $fieldDenormalizer->denormalizeField('reference', $object, 'test', $context, $denormalizer); } + #[DoesNotPerformAssertions] public function testDenormalizeFieldWithNull(): void { $object = new \stdClass(); - /** @var AccessorInterface|MockObject $accessor */ - $accessor = $this->getMockByCalls(AccessorInterface::class, [ - Call::create('setValue')->with($object, null), + $builder = new MockObjectBuilder(); + + /** @var AccessorInterface $accessor */ + $accessor = $builder->create(AccessorInterface::class, [ + new WithoutReturn('setValue', [$object, null]), ]); - /** @var DenormalizerContextInterface|MockObject $context */ - $context = $this->getMockByCalls(DenormalizerContextInterface::class); + /** @var DenormalizerContextInterface $context */ + $context = $builder->create(DenormalizerContextInterface::class, []); - /** @var DenormalizerInterface|MockObject $denormalizer */ - $denormalizer = $this->getMockByCalls(DenormalizerInterface::class); + /** @var DenormalizerInterface $denormalizer */ + $denormalizer = $builder->create(DenormalizerInterface::class, []); $fieldDenormalizer = new EmbedOneFieldDenormalizer(\stdClass::class, $accessor); $fieldDenormalizer->denormalizeField('reference', $object, null, $context, $denormalizer); } + #[DoesNotPerformAssertions] public function testDenormalizeField(): void { $object = new \stdClass(); - $reference = new \stdClass(); - /** @var AccessorInterface|MockObject $accessor */ - $accessor = $this->getMockByCalls(AccessorInterface::class, [ - Call::create('getValue')->with($object)->willReturn(null), - Call::create('setValue')->with($object, $reference), + $builder = new MockObjectBuilder(); + + /** @var AccessorInterface $accessor */ + $accessor = $builder->create(AccessorInterface::class, [ + new WithReturn('getValue', [$object], null), + new WithoutReturn('setValue', [$object, $reference]), ]); - /** @var DenormalizerContextInterface|MockObject $context */ - $context = $this->getMockByCalls(DenormalizerContextInterface::class); + /** @var DenormalizerContextInterface $context */ + $context = $builder->create(DenormalizerContextInterface::class, []); - /** @var DenormalizerInterface|MockObject $denormalizer */ - $denormalizer = $this->getMockByCalls(DenormalizerInterface::class, [ - Call::create('denormalize') - ->with(\stdClass::class, ['name' => 'name'], $context, 'reference') - ->willReturn($reference), + /** @var DenormalizerInterface $denormalizer */ + $denormalizer = $builder->create(DenormalizerInterface::class, [ + new WithReturn( + 'denormalize', + [\stdClass::class, ['name' => 'name'], $context, 'reference'], + $reference + ), ]); $fieldDenormalizer = new EmbedOneFieldDenormalizer(\stdClass::class, $accessor); $fieldDenormalizer->denormalizeField('reference', $object, ['name' => 'name'], $context, $denormalizer); } + #[DoesNotPerformAssertions] public function testDenormalizeFieldWithExistingValue(): void { $object = new \stdClass(); $reference = new \stdClass(); - /** @var AccessorInterface|MockObject $accessor */ - $accessor = $this->getMockByCalls(AccessorInterface::class, [ - Call::create('getValue')->with($object)->willReturn($reference), - Call::create('setValue')->with($object, $reference), + $builder = new MockObjectBuilder(); + + /** @var AccessorInterface $accessor */ + $accessor = $builder->create(AccessorInterface::class, [ + new WithReturn('getValue', [$object], $reference), + new WithoutReturn('setValue', [$object, $reference]), ]); - /** @var DenormalizerContextInterface|MockObject $context */ - $context = $this->getMockByCalls(DenormalizerContextInterface::class); + /** @var DenormalizerContextInterface $context */ + $context = $builder->create(DenormalizerContextInterface::class, []); - /** @var DenormalizerInterface|MockObject $denormalizer */ - $denormalizer = $this->getMockByCalls(DenormalizerInterface::class, [ - Call::create('denormalize') - ->with($reference, ['name' => 'name'], $context, 'reference') - ->willReturn($reference), + /** @var DenormalizerInterface $denormalizer */ + $denormalizer = $builder->create(DenormalizerInterface::class, [ + new WithReturn( + 'denormalize', + [$reference, ['name' => 'name'], $context, 'reference'], + $reference + ), ]); $fieldDenormalizer = new EmbedOneFieldDenormalizer(\stdClass::class, $accessor); $fieldDenormalizer->denormalizeField('reference', $object, ['name' => 'name'], $context, $denormalizer); } + #[DoesNotPerformAssertions] public function testDenormalizeFieldWithReverseOwning(): void { $object = new \stdClass(); $reference = new \stdClass(); - /** @var AccessorInterface|MockObject $accessor */ - $accessor = $this->getMockByCalls(AccessorInterface::class, [ - Call::create('getValue')->with($object)->willReturn(null), - Call::create('setValue')->with($object, $reference), + $builder = new MockObjectBuilder(); + + /** @var AccessorInterface $accessor */ + $accessor = $builder->create(AccessorInterface::class, [ + new WithReturn('getValue', [$object], null), + new WithoutReturn('setValue', [$object, $reference]), ]); - /** @var DenormalizerContextInterface|MockObject $context */ - $context = $this->getMockByCalls(DenormalizerContextInterface::class); + /** @var DenormalizerContextInterface $context */ + $context = $builder->create(DenormalizerContextInterface::class, []); - /** @var DenormalizerInterface|MockObject $denormalizer */ - $denormalizer = $this->getMockByCalls(DenormalizerInterface::class, [ - Call::create('denormalize') - ->with(\stdClass::class, ['name' => 'name'], $context, 'reference') - ->willReturn($reference), + /** @var DenormalizerInterface $denormalizer */ + $denormalizer = $builder->create(DenormalizerInterface::class, [ + new WithReturn( + 'denormalize', + [\stdClass::class, ['name' => 'name'], $context, 'reference'], + $reference + ), ]); - /** @var AccessorInterface|MockObject $parentAccessor */ - $parentAccessor = $this->getMockByCalls(AccessorInterface::class, [ - Call::create('setValue')->with($reference, $object), + /** @var AccessorInterface $parentAccessor */ + $parentAccessor = $builder->create(AccessorInterface::class, [ + new WithoutReturn('setValue', [$reference, $object]), ]); $fieldDenormalizer = new EmbedOneFieldDenormalizer(\stdClass::class, $accessor, $parentAccessor); $fieldDenormalizer->denormalizeField('reference', $object, ['name' => 'name'], $context, $denormalizer); } + #[DoesNotPerformAssertions] public function testDenormalizeFieldWithExistingValueAndWithReverseOwning(): void { $object = new \stdClass(); $reference = new \stdClass(); - /** @var AccessorInterface|MockObject $accessor */ - $accessor = $this->getMockByCalls(AccessorInterface::class, [ - Call::create('getValue')->with($object)->willReturn($reference), - Call::create('setValue')->with($object, $reference), + $builder = new MockObjectBuilder(); + + /** @var AccessorInterface $accessor */ + $accessor = $builder->create(AccessorInterface::class, [ + new WithReturn('getValue', [$object], $reference), + new WithoutReturn('setValue', [$object, $reference]), ]); - /** @var DenormalizerContextInterface|MockObject $context */ - $context = $this->getMockByCalls(DenormalizerContextInterface::class); + /** @var DenormalizerContextInterface $context */ + $context = $builder->create(DenormalizerContextInterface::class, []); - /** @var DenormalizerInterface|MockObject $denormalizer */ - $denormalizer = $this->getMockByCalls(DenormalizerInterface::class, [ - Call::create('denormalize') - ->with($reference, ['name' => 'name'], $context, 'reference') - ->willReturn($reference), + /** @var DenormalizerInterface $denormalizer */ + $denormalizer = $builder->create(DenormalizerInterface::class, [ + new WithReturn('denormalize', [$reference, ['name' => 'name'], $context, 'reference'], $reference), ]); - /** @var AccessorInterface|MockObject $parentAccessor */ - $parentAccessor = $this->getMockByCalls(AccessorInterface::class, [ - Call::create('setValue')->with($reference, $object), + /** @var AccessorInterface $parentAccessor */ + $parentAccessor = $builder->create(AccessorInterface::class, [ + new WithoutReturn('setValue', [$reference, $object]), ]); $fieldDenormalizer = new EmbedOneFieldDenormalizer(\stdClass::class, $accessor, $parentAccessor); diff --git a/tests/Unit/Denormalizer/Relation/ReferenceManyFieldDenormalizerTest.php b/tests/Unit/Denormalizer/Relation/ReferenceManyFieldDenormalizerTest.php index 6e0eebd..b6600f9 100644 --- a/tests/Unit/Denormalizer/Relation/ReferenceManyFieldDenormalizerTest.php +++ b/tests/Unit/Denormalizer/Relation/ReferenceManyFieldDenormalizerTest.php @@ -8,10 +8,11 @@ use Chubbyphp\Deserialization\Denormalizer\DenormalizerContextInterface; use Chubbyphp\Deserialization\Denormalizer\Relation\ReferenceManyFieldDenormalizer; use Chubbyphp\Deserialization\DeserializerRuntimeException; -use Chubbyphp\Mock\Call; -use Chubbyphp\Mock\MockByCallsTrait; +use Chubbyphp\Mock\MockMethod\WithoutReturn; +use Chubbyphp\Mock\MockMethod\WithReturn; +use Chubbyphp\Mock\MockObjectBuilder; use Doctrine\Common\Collections\Collection; -use PHPUnit\Framework\MockObject\MockObject; +use PHPUnit\Framework\Attributes\DoesNotPerformAssertions; use PHPUnit\Framework\TestCase; /** @@ -21,20 +22,19 @@ */ final class ReferenceManyFieldDenormalizerTest extends TestCase { - use MockByCallsTrait; - public function testDenormalizeFieldWithoutArrayDenormalizer(): void { $this->expectException(DeserializerRuntimeException::class); $this->expectExceptionMessage('There is an invalid data type "double", needed "array" at path: "children"'); $parent = new \stdClass(); + $builder = new MockObjectBuilder(); - /** @var AccessorInterface|MockObject $accessor */ - $accessor = $this->getMockByCalls(AccessorInterface::class); + /** @var AccessorInterface $accessor */ + $accessor = $builder->create(AccessorInterface::class, []); - /** @var DenormalizerContextInterface|MockObject $context */ - $context = $this->getMockByCalls(DenormalizerContextInterface::class); + /** @var DenormalizerContextInterface $context */ + $context = $builder->create(DenormalizerContextInterface::class, []); $fieldDenormalizer = new ReferenceManyFieldDenormalizer(static function (string $id): void {}, $accessor); $fieldDenormalizer->denormalizeField('children', $parent, 18.9, $context); @@ -46,35 +46,38 @@ public function testDenormalizeFieldWithArrayButNullChildDenormalizer(): void $this->expectExceptionMessage('There is an invalid data type "double", needed "string" at path: "children[0]"'); $parent = new \stdClass(); + $builder = new MockObjectBuilder(); - /** @var AccessorInterface|MockObject $accessor */ - $accessor = $this->getMockByCalls(AccessorInterface::class, [ - Call::create('getValue')->with($parent)->willReturn([]), + /** @var AccessorInterface $accessor */ + $accessor = $builder->create(AccessorInterface::class, [ + new WithReturn('getValue', [$parent], []), ]); - /** @var DenormalizerContextInterface|MockObject $context */ - $context = $this->getMockByCalls(DenormalizerContextInterface::class); + /** @var DenormalizerContextInterface $context */ + $context = $builder->create(DenormalizerContextInterface::class, []); $fieldDenormalizer = new ReferenceManyFieldDenormalizer(static function (string $id): void {}, $accessor); $fieldDenormalizer->denormalizeField('children', $parent, [18.9], $context); } + #[DoesNotPerformAssertions] public function testDenormalizeFieldWithNull(): void { $parent = new \stdClass(); + $builder = new MockObjectBuilder(); - /** @var AccessorInterface|MockObject $accessor */ - $accessor = $this->getMockByCalls(AccessorInterface::class, [ - Call::create('getValue')->with($parent)->willReturn([]), - Call::create('setValue')->with($parent, []), + /** @var AccessorInterface $accessor */ + $accessor = $builder->create(AccessorInterface::class, [ + new WithReturn('getValue', [$parent], []), + new WithoutReturn('setValue', [$parent, []]), ]); - /** @var DenormalizerContextInterface|MockObject $context */ - $context = $this->getMockByCalls(DenormalizerContextInterface::class); + /** @var DenormalizerContextInterface $context */ + $context = $builder->create(DenormalizerContextInterface::class, []); $fieldDenormalizer = new ReferenceManyFieldDenormalizer( static function (): void { - self::fail('There should be no id to resolve'); + throw new \Exception('There should be no id to resolve'); }, $accessor ); @@ -87,15 +90,16 @@ public function testDenormalizeFieldWithNewChild(): void $parent = new \stdClass(); $child = new \stdClass(); + $builder = new MockObjectBuilder(); - /** @var AccessorInterface|MockObject $accessor */ - $accessor = $this->getMockByCalls(AccessorInterface::class, [ - Call::create('getValue')->with($parent)->willReturn([]), - Call::create('setValue')->with($parent, [$child]), + /** @var AccessorInterface $accessor */ + $accessor = $builder->create(AccessorInterface::class, [ + new WithReturn('getValue', [$parent], []), + new WithoutReturn('setValue', [$parent, [$child]]), ]); - /** @var DenormalizerContextInterface|MockObject $context */ - $context = $this->getMockByCalls(DenormalizerContextInterface::class); + /** @var DenormalizerContextInterface $context */ + $context = $builder->create(DenormalizerContextInterface::class, []); $fieldDenormalizer = new ReferenceManyFieldDenormalizer( static function (string $id) use ($child) { @@ -112,15 +116,16 @@ static function (string $id) use ($child) { public function testDenormalizeFieldWithNewChildAndNotFoundValue(): void { $parent = new \stdClass(); + $builder = new MockObjectBuilder(); - /** @var AccessorInterface|MockObject $accessor */ - $accessor = $this->getMockByCalls(AccessorInterface::class, [ - Call::create('getValue')->with($parent)->willReturn([]), - Call::create('setValue')->with($parent, ['60a9ee14-64d6-4992-8042-8d1528ac02d6']), + /** @var AccessorInterface $accessor */ + $accessor = $builder->create(AccessorInterface::class, [ + new WithReturn('getValue', [$parent], []), + new WithoutReturn('setValue', [$parent, ['60a9ee14-64d6-4992-8042-8d1528ac02d6']]), ]); - /** @var DenormalizerContextInterface|MockObject $context */ - $context = $this->getMockByCalls(DenormalizerContextInterface::class); + /** @var DenormalizerContextInterface $context */ + $context = $builder->create(DenormalizerContextInterface::class, []); $fieldDenormalizer = new ReferenceManyFieldDenormalizer( static function (string $id): void { @@ -137,15 +142,16 @@ public function testDenormalizeFieldWithExistingChild(): void $parent = new \stdClass(); $child = new \stdClass(); + $builder = new MockObjectBuilder(); - /** @var AccessorInterface|MockObject $accessor */ - $accessor = $this->getMockByCalls(AccessorInterface::class, [ - Call::create('getValue')->with($parent)->willReturn([$child]), - Call::create('setValue')->with($parent, [$child]), + /** @var AccessorInterface $accessor */ + $accessor = $builder->create(AccessorInterface::class, [ + new WithReturn('getValue', [$parent], [$child]), + new WithoutReturn('setValue', [$parent, [$child]]), ]); - /** @var DenormalizerContextInterface|MockObject $context */ - $context = $this->getMockByCalls(DenormalizerContextInterface::class); + /** @var DenormalizerContextInterface $context */ + $context = $builder->create(DenormalizerContextInterface::class, []); $fieldDenormalizer = new ReferenceManyFieldDenormalizer( static function (string $id) use ($child) { @@ -164,27 +170,28 @@ public function testDenormalizeFieldWithNewChildAndCollection(): void $parent = new \stdClass(); $child = new \stdClass(); + $builder = new MockObjectBuilder(); - /** @var \Iterator|MockObject $iterator */ - $iterator = $this->getMockByCalls(\Iterator::class, [ - Call::create('rewind')->with(), - Call::create('valid')->with()->willReturn(false), + /** @var \Iterator $iterator */ + $iterator = $builder->create(\Iterator::class, [ + new WithoutReturn('rewind', []), + new WithReturn('valid', [], false), ]); - /** @var Collection|MockObject $collection */ - $collection = $this->getMockByCalls(Collection::class, [ - Call::create('getIterator')->with()->willReturn($iterator), - Call::create('offsetSet')->with(0, $child), + /** @var Collection $collection */ + $collection = $builder->create(Collection::class, [ + new WithReturn('getIterator', [], $iterator), + new WithoutReturn('offsetSet', [0, $child]), ]); - /** @var AccessorInterface|MockObject $accessor */ - $accessor = $this->getMockByCalls(AccessorInterface::class, [ - Call::create('getValue')->with($parent)->willReturn($collection), - Call::create('setValue')->with($parent, $collection), + /** @var AccessorInterface $accessor */ + $accessor = $builder->create(AccessorInterface::class, [ + new WithReturn('getValue', [$parent], $collection), + new WithoutReturn('setValue', [$parent, $collection]), ]); - /** @var DenormalizerContextInterface|MockObject $context */ - $context = $this->getMockByCalls(DenormalizerContextInterface::class); + /** @var DenormalizerContextInterface $context */ + $context = $builder->create(DenormalizerContextInterface::class, []); $fieldDenormalizer = new ReferenceManyFieldDenormalizer( static function (string $id) use ($child) { @@ -203,32 +210,33 @@ public function testDenormalizeFieldWithExistingChildAndCollection(): void $parent = new \stdClass(); $child = new \stdClass(); - - /** @var \Iterator|MockObject $iterator */ - $iterator = $this->getMockByCalls(\Iterator::class, [ - Call::create('rewind')->with(), - Call::create('valid')->with()->willReturn(true), - Call::create('current')->with()->willReturn($child), - Call::create('key')->with()->willReturn(0), - Call::create('next')->with(), - Call::create('valid')->with()->willReturn(false), + $builder = new MockObjectBuilder(); + + /** @var \Iterator $iterator */ + $iterator = $builder->create(\Iterator::class, [ + new WithoutReturn('rewind', []), + new WithReturn('valid', [], true), + new WithReturn('current', [], $child), + new WithReturn('key', [], 0), + new WithoutReturn('next', []), + new WithReturn('valid', [], false), ]); - /** @var Collection|MockObject $collection */ - $collection = $this->getMockByCalls(Collection::class, [ - Call::create('getIterator')->with()->willReturn($iterator), - Call::create('offsetUnset')->with(0), - Call::create('offsetSet')->with(0, $child), + /** @var Collection $collection */ + $collection = $builder->create(Collection::class, [ + new WithReturn('getIterator', [], $iterator), + new WithoutReturn('offsetUnset', [0]), + new WithoutReturn('offsetSet', [0, $child]), ]); - /** @var AccessorInterface|MockObject $accessor */ - $accessor = $this->getMockByCalls(AccessorInterface::class, [ - Call::create('getValue')->with($parent)->willReturn($collection), - Call::create('setValue')->with($parent, $collection), + /** @var AccessorInterface $accessor */ + $accessor = $builder->create(AccessorInterface::class, [ + new WithReturn('getValue', [$parent], $collection), + new WithoutReturn('setValue', [$parent, $collection]), ]); - /** @var DenormalizerContextInterface|MockObject $context */ - $context = $this->getMockByCalls(DenormalizerContextInterface::class); + /** @var DenormalizerContextInterface $context */ + $context = $builder->create(DenormalizerContextInterface::class, []); $fieldDenormalizer = new ReferenceManyFieldDenormalizer( static function (string $id) use ($child) { diff --git a/tests/Unit/Denormalizer/Relation/ReferenceOneFieldDenormalizerTest.php b/tests/Unit/Denormalizer/Relation/ReferenceOneFieldDenormalizerTest.php index b94de97..fbe0f5c 100644 --- a/tests/Unit/Denormalizer/Relation/ReferenceOneFieldDenormalizerTest.php +++ b/tests/Unit/Denormalizer/Relation/ReferenceOneFieldDenormalizerTest.php @@ -8,9 +8,9 @@ use Chubbyphp\Deserialization\Denormalizer\DenormalizerContextInterface; use Chubbyphp\Deserialization\Denormalizer\Relation\ReferenceOneFieldDenormalizer; use Chubbyphp\Deserialization\DeserializerRuntimeException; -use Chubbyphp\Mock\Call; -use Chubbyphp\Mock\MockByCallsTrait; -use PHPUnit\Framework\MockObject\MockObject; +use Chubbyphp\Mock\MockMethod\WithoutReturn; +use Chubbyphp\Mock\MockObjectBuilder; +use PHPUnit\Framework\Attributes\DoesNotPerformAssertions; use PHPUnit\Framework\TestCase; /** @@ -20,36 +20,37 @@ */ final class ReferenceOneFieldDenormalizerTest extends TestCase { - use MockByCallsTrait; - public function testDenormalizeFieldWithWrongType(): void { $this->expectException(DeserializerRuntimeException::class); $this->expectExceptionMessage('There is an invalid data type "integer", needed "string" at path: "reference"'); $object = new \stdClass(); + $builder = new MockObjectBuilder(); - /** @var AccessorInterface|MockObject $accessor */ - $accessor = $this->getMockByCalls(AccessorInterface::class); + /** @var AccessorInterface $accessor */ + $accessor = $builder->create(AccessorInterface::class, []); - /** @var DenormalizerContextInterface|MockObject $context */ - $context = $this->getMockByCalls(DenormalizerContextInterface::class); + /** @var DenormalizerContextInterface $context */ + $context = $builder->create(DenormalizerContextInterface::class, []); $fieldDenormalizer = new ReferenceOneFieldDenormalizer(static function (string $id): void {}, $accessor); $fieldDenormalizer->denormalizeField('reference', $object, 5, $context); } + #[DoesNotPerformAssertions] public function testDenormalizeFieldWithNull(): void { $object = new \stdClass(); + $builder = new MockObjectBuilder(); - /** @var AccessorInterface|MockObject $accessor */ - $accessor = $this->getMockByCalls(AccessorInterface::class, [ - Call::create('setValue')->with($object, null), + /** @var AccessorInterface $accessor */ + $accessor = $builder->create(AccessorInterface::class, [ + new WithoutReturn('setValue', [$object, null]), ]); - /** @var DenormalizerContextInterface|MockObject $context */ - $context = $this->getMockByCalls(DenormalizerContextInterface::class); + /** @var DenormalizerContextInterface $context */ + $context = $builder->create(DenormalizerContextInterface::class, []); $fieldDenormalizer = new ReferenceOneFieldDenormalizer(static function (string $id): void {}, $accessor); $fieldDenormalizer->denormalizeField('reference', $object, null, $context); @@ -60,14 +61,15 @@ public function testDenormalizeField(): void $object = new \stdClass(); $reference = new \stdClass(); + $builder = new MockObjectBuilder(); - /** @var AccessorInterface|MockObject $accessor */ - $accessor = $this->getMockByCalls(AccessorInterface::class, [ - Call::create('setValue')->with($object, $reference), + /** @var AccessorInterface $accessor */ + $accessor = $builder->create(AccessorInterface::class, [ + new WithoutReturn('setValue', [$object, $reference]), ]); - /** @var DenormalizerContextInterface|MockObject $context */ - $context = $this->getMockByCalls(DenormalizerContextInterface::class); + /** @var DenormalizerContextInterface $context */ + $context = $builder->create(DenormalizerContextInterface::class, []); $fieldDenormalizer = new ReferenceOneFieldDenormalizer( static function (string $id) use ($reference) { @@ -89,14 +91,15 @@ static function (string $id) use ($reference) { public function testDenormalizeFieldWithNotFoundValue(): void { $object = new \stdClass(); + $builder = new MockObjectBuilder(); - /** @var AccessorInterface|MockObject $accessor */ - $accessor = $this->getMockByCalls(AccessorInterface::class, [ - Call::create('setValue')->with($object, '60a9ee14-64d6-4992-8042-8d1528ac02d6'), + /** @var AccessorInterface $accessor */ + $accessor = $builder->create(AccessorInterface::class, [ + new WithoutReturn('setValue', [$object, '60a9ee14-64d6-4992-8042-8d1528ac02d6']), ]); - /** @var DenormalizerContextInterface|MockObject $context */ - $context = $this->getMockByCalls(DenormalizerContextInterface::class); + /** @var DenormalizerContextInterface $context */ + $context = $builder->create(DenormalizerContextInterface::class, []); $fieldDenormalizer = new ReferenceOneFieldDenormalizer( static function (string $id): void { @@ -116,14 +119,15 @@ static function (string $id): void { public function testDenormalizeFieldWithEmptyToNullDisabled(): void { $object = new \stdClass(); + $builder = new MockObjectBuilder(); - /** @var AccessorInterface|MockObject $accessor */ - $accessor = $this->getMockByCalls(AccessorInterface::class, [ - Call::create('setValue')->with($object, ''), + /** @var AccessorInterface $accessor */ + $accessor = $builder->create(AccessorInterface::class, [ + new WithoutReturn('setValue', [$object, '']), ]); - /** @var DenormalizerContextInterface|MockObject $context */ - $context = $this->getMockByCalls(DenormalizerContextInterface::class); + /** @var DenormalizerContextInterface $context */ + $context = $builder->create(DenormalizerContextInterface::class, []); $fieldDenormalizer = new ReferenceOneFieldDenormalizer( static function (string $id): void { @@ -140,17 +144,19 @@ static function (string $id): void { ); } + #[DoesNotPerformAssertions] public function testDenormalizeFieldWithEmptyToNullEnabled(): void { $object = new \stdClass(); + $builder = new MockObjectBuilder(); - /** @var AccessorInterface|MockObject $accessor */ - $accessor = $this->getMockByCalls(AccessorInterface::class, [ - Call::create('setValue')->with($object, null), + /** @var AccessorInterface $accessor */ + $accessor = $builder->create(AccessorInterface::class, [ + new WithoutReturn('setValue', [$object, null]), ]); - /** @var DenormalizerContextInterface|MockObject $context */ - $context = $this->getMockByCalls(DenormalizerContextInterface::class); + /** @var DenormalizerContextInterface $context */ + $context = $builder->create(DenormalizerContextInterface::class, []); $fieldDenormalizer = new ReferenceOneFieldDenormalizer( static function ($id): void { diff --git a/tests/Unit/DeserializerTest.php b/tests/Unit/DeserializerTest.php index a4978fc..d6803f2 100644 --- a/tests/Unit/DeserializerTest.php +++ b/tests/Unit/DeserializerTest.php @@ -8,9 +8,8 @@ use Chubbyphp\Deserialization\Denormalizer\DenormalizerContextInterface; use Chubbyphp\Deserialization\Denormalizer\DenormalizerInterface; use Chubbyphp\Deserialization\Deserializer; -use Chubbyphp\Mock\Call; -use Chubbyphp\Mock\MockByCallsTrait; -use PHPUnit\Framework\MockObject\MockObject; +use Chubbyphp\Mock\MockMethod\WithReturn; +use Chubbyphp\Mock\MockObjectBuilder; use PHPUnit\Framework\TestCase; /** @@ -20,23 +19,27 @@ */ final class DeserializerTest extends TestCase { - use MockByCallsTrait; - public function testDeserialize(): void { $object = new \stdClass(); - /** @var DenormalizerContextInterface|MockObject $context */ - $context = $this->getMockByCalls(DenormalizerContextInterface::class); + $builder = new MockObjectBuilder(); + + /** @var DenormalizerContextInterface $context */ + $context = $builder->create(DenormalizerContextInterface::class, []); - /** @var DecoderInterface|MockObject $decoder */ - $decoder = $this->getMockByCalls(DecoderInterface::class, [ - Call::create('decode')->with('{"name": "php"}', 'application/json')->willReturn(['name' => 'php']), + /** @var DecoderInterface $decoder */ + $decoder = $builder->create(DecoderInterface::class, [ + new WithReturn('decode', ['{"name": "php"}', 'application/json'], ['name' => 'php']), ]); - /** @var DenormalizerInterface|MockObject $denormalizer */ - $denormalizer = $this->getMockByCalls(DenormalizerInterface::class, [ - Call::create('denormalize')->with($object, ['name' => 'php'], $context, '')->willReturn($object), + /** @var DenormalizerInterface $denormalizer */ + $denormalizer = $builder->create(DenormalizerInterface::class, [ + new WithReturn( + 'denormalize', + [$object, ['name' => 'php'], $context, ''], + $object + ), ]); $deserializer = new Deserializer($decoder, $denormalizer); @@ -46,13 +49,15 @@ public function testDeserialize(): void public function testDecode(): void { - /** @var DecoderInterface|MockObject $decoder */ - $decoder = $this->getMockByCalls(DecoderInterface::class, [ - Call::create('decode')->with('{"name": "php"}', 'application/json')->willReturn(['name' => 'php']), + $builder = new MockObjectBuilder(); + + /** @var DecoderInterface $decoder */ + $decoder = $builder->create(DecoderInterface::class, [ + new WithReturn('decode', ['{"name": "php"}', 'application/json'], ['name' => 'php']), ]); - /** @var DenormalizerInterface|MockObject $denormalizer */ - $denormalizer = $this->getMockByCalls(DenormalizerInterface::class); + /** @var DenormalizerInterface $denormalizer */ + $denormalizer = $builder->create(DenormalizerInterface::class, []); $deserializer = new Deserializer($decoder, $denormalizer); @@ -61,13 +66,15 @@ public function testDecode(): void public function testGetContentTypes(): void { - /** @var DecoderInterface|MockObject $decoder */ - $decoder = $this->getMockByCalls(DecoderInterface::class, [ - Call::create('getContentTypes')->with()->willReturn(['application/json']), + $builder = new MockObjectBuilder(); + + /** @var DecoderInterface $decoder */ + $decoder = $builder->create(DecoderInterface::class, [ + new WithReturn('getContentTypes', [], ['application/json']), ]); - /** @var DenormalizerInterface|MockObject $denormalizer */ - $denormalizer = $this->getMockByCalls(DenormalizerInterface::class); + /** @var DenormalizerInterface $denormalizer */ + $denormalizer = $builder->create(DenormalizerInterface::class, []); $deserializer = new Deserializer($decoder, $denormalizer); @@ -78,15 +85,17 @@ public function testDenormalize(): void { $object = new \stdClass(); - /** @var DenormalizerContextInterface|MockObject $context */ - $context = $this->getMockByCalls(DenormalizerContextInterface::class); + $builder = new MockObjectBuilder(); + + /** @var DenormalizerContextInterface $context */ + $context = $builder->create(DenormalizerContextInterface::class, []); - /** @var DecoderInterface|MockObject $decoder */ - $decoder = $this->getMockByCalls(DecoderInterface::class); + /** @var DecoderInterface $decoder */ + $decoder = $builder->create(DecoderInterface::class, []); - /** @var DenormalizerInterface|MockObject $denormalizer */ - $denormalizer = $this->getMockByCalls(DenormalizerInterface::class, [ - Call::create('denormalize')->with($object, ['name' => 'php'], $context, '')->willReturn($object), + /** @var DenormalizerInterface $denormalizer */ + $denormalizer = $builder->create(DenormalizerInterface::class, [ + new WithReturn('denormalize', [$object, ['name' => 'php'], $context, ''], $object), ]); $deserializer = new Deserializer($decoder, $denormalizer); diff --git a/tests/Unit/Mapping/CallableDenormalizationObjectMappingTest.php b/tests/Unit/Mapping/CallableDenormalizationObjectMappingTest.php index 6a44659..2a58199 100644 --- a/tests/Unit/Mapping/CallableDenormalizationObjectMappingTest.php +++ b/tests/Unit/Mapping/CallableDenormalizationObjectMappingTest.php @@ -7,8 +7,8 @@ use Chubbyphp\Deserialization\Mapping\CallableDenormalizationObjectMapping; use Chubbyphp\Deserialization\Mapping\DenormalizationFieldMappingInterface; use Chubbyphp\Deserialization\Mapping\DenormalizationObjectMappingInterface; -use Chubbyphp\Mock\Call; -use Chubbyphp\Mock\MockByCallsTrait; +use Chubbyphp\Mock\MockMethod\WithReturn; +use Chubbyphp\Mock\MockObjectBuilder; use PHPUnit\Framework\TestCase; /** @@ -18,8 +18,6 @@ */ final class CallableDenormalizationObjectMappingTest extends TestCase { - use MockByCallsTrait; - public function testGetClass(): void { $mapping = new CallableDenormalizationObjectMapping(\stdClass::class, static function (): void {}); @@ -30,10 +28,14 @@ public function testGetClass(): void public function testGetDenormalizationFactory(): void { $object = new \stdClass(); + $builder = new MockObjectBuilder(); - $mapping = new CallableDenormalizationObjectMapping(\stdClass::class, fn () => $this->getMockByCalls(DenormalizationObjectMappingInterface::class, [ - Call::create('getDenormalizationFactory')->with('path', null)->willReturn(static fn () => $object), - ])); + $mapping = new CallableDenormalizationObjectMapping( + \stdClass::class, + static fn () => $builder->create(DenormalizationObjectMappingInterface::class, [ + new WithReturn('getDenormalizationFactory', ['path', null], static fn () => $object), + ]) + ); $factory = $mapping->getDenormalizationFactory('path'); @@ -44,11 +46,17 @@ public function testGetDenormalizationFactory(): void public function testGetDenormalizationFieldMappings(): void { - $fieldMapping = $this->getMockByCalls(DenormalizationFieldMappingInterface::class); + $builder = new MockObjectBuilder(); + + /** @var DenormalizationFieldMappingInterface $fieldMapping */ + $fieldMapping = $builder->create(DenormalizationFieldMappingInterface::class, []); - $mapping = new CallableDenormalizationObjectMapping(\stdClass::class, fn () => $this->getMockByCalls(DenormalizationObjectMappingInterface::class, [ - Call::create('getDenormalizationFieldMappings')->with('path', null)->willReturn([$fieldMapping]), - ])); + $mapping = new CallableDenormalizationObjectMapping( + \stdClass::class, + static fn () => $builder->create(DenormalizationObjectMappingInterface::class, [ + new WithReturn('getDenormalizationFieldMappings', ['path', null], [$fieldMapping]), + ]) + ); self::assertSame($fieldMapping, $mapping->getDenormalizationFieldMappings('path')[0]); } diff --git a/tests/Unit/Mapping/DenormalizationFieldMappingFactoryTest.php b/tests/Unit/Mapping/DenormalizationFieldMappingFactoryTest.php index c84365d..c7d7401 100644 --- a/tests/Unit/Mapping/DenormalizationFieldMappingFactoryTest.php +++ b/tests/Unit/Mapping/DenormalizationFieldMappingFactoryTest.php @@ -16,8 +16,7 @@ use Chubbyphp\Deserialization\Mapping\DenormalizationFieldMappingFactory; use Chubbyphp\Deserialization\Policy\NullPolicy; use Chubbyphp\Deserialization\Policy\PolicyInterface; -use Chubbyphp\Mock\MockByCallsTrait; -use PHPUnit\Framework\MockObject\MockObject; +use Chubbyphp\Mock\MockObjectBuilder; use PHPUnit\Framework\TestCase; /** @@ -27,8 +26,6 @@ */ final class DenormalizationFieldMappingFactoryTest extends TestCase { - use MockByCallsTrait; - private DenormalizationFieldMappingFactory $factory; protected function setUp(): void @@ -38,8 +35,10 @@ protected function setUp(): void public function testGetMappingWithDenormalizer(): void { - /** @var FieldDenormalizerInterface|MockObject $fieldDenormalizer */ - $fieldDenormalizer = $this->getMockByCalls(FieldDenormalizerInterface::class); + $builder = new MockObjectBuilder(); + + /** @var FieldDenormalizerInterface $fieldDenormalizer */ + $fieldDenormalizer = $builder->create(FieldDenormalizerInterface::class, []); $fieldMapping = $this->factory->create('name', false, $fieldDenormalizer); @@ -232,11 +231,13 @@ static function (): void {}, public function testGetMapping(): void { - /** @var FieldDenormalizerInterface|MockObject $fieldDenormalizer */ - $fieldDenormalizer = $this->getMockByCalls(FieldDenormalizerInterface::class); + $builder = new MockObjectBuilder(); + + /** @var FieldDenormalizerInterface $fieldDenormalizer */ + $fieldDenormalizer = $builder->create(FieldDenormalizerInterface::class, []); - /** @var MockObject|PolicyInterface $policy */ - $policy = $this->getMockByCalls(PolicyInterface::class); + /** @var PolicyInterface $policy */ + $policy = $builder->create(PolicyInterface::class, []); $fieldMapping = $this->factory->create('name', false, $fieldDenormalizer, $policy); diff --git a/tests/Unit/Mapping/DenormalizationFieldMappingTest.php b/tests/Unit/Mapping/DenormalizationFieldMappingTest.php index 64ede1e..32b8ed5 100644 --- a/tests/Unit/Mapping/DenormalizationFieldMappingTest.php +++ b/tests/Unit/Mapping/DenormalizationFieldMappingTest.php @@ -7,8 +7,7 @@ use Chubbyphp\Deserialization\Denormalizer\FieldDenormalizerInterface; use Chubbyphp\Deserialization\Mapping\DenormalizationFieldMapping; use Chubbyphp\Deserialization\Policy\PolicyInterface; -use Chubbyphp\Mock\MockByCallsTrait; -use PHPUnit\Framework\MockObject\MockObject; +use Chubbyphp\Mock\MockObjectBuilder; use PHPUnit\Framework\TestCase; /** @@ -18,12 +17,12 @@ */ final class DenormalizationFieldMappingTest extends TestCase { - use MockByCallsTrait; - public function testGetName(): void { - /** @var FieldDenormalizerInterface|MockObject $fieldDenormalizer */ - $fieldDenormalizer = $this->getMockByCalls(FieldDenormalizerInterface::class); + $builder = new MockObjectBuilder(); + + /** @var FieldDenormalizerInterface $fieldDenormalizer */ + $fieldDenormalizer = $builder->create(FieldDenormalizerInterface::class, []); $fieldMapping = new DenormalizationFieldMapping('name', $fieldDenormalizer); @@ -32,8 +31,10 @@ public function testGetName(): void public function testGetFieldDenormalizer(): void { - /** @var FieldDenormalizerInterface|MockObject $fieldDenormalizer */ - $fieldDenormalizer = $this->getMockByCalls(FieldDenormalizerInterface::class); + $builder = new MockObjectBuilder(); + + /** @var FieldDenormalizerInterface $fieldDenormalizer */ + $fieldDenormalizer = $builder->create(FieldDenormalizerInterface::class, []); $fieldMapping = new DenormalizationFieldMapping('name', $fieldDenormalizer); @@ -42,11 +43,13 @@ public function testGetFieldDenormalizer(): void public function testGetPolicy(): void { - /** @var FieldDenormalizerInterface|MockObject $fieldDenormalizer */ - $fieldDenormalizer = $this->getMockByCalls(FieldDenormalizerInterface::class); + $builder = new MockObjectBuilder(); + + /** @var FieldDenormalizerInterface $fieldDenormalizer */ + $fieldDenormalizer = $builder->create(FieldDenormalizerInterface::class, []); - /** @var MockObject|PolicyInterface $policy */ - $policy = $this->getMockByCalls(PolicyInterface::class); + /** @var PolicyInterface $policy */ + $policy = $builder->create(PolicyInterface::class, []); $fieldMapping = new DenormalizationFieldMapping('name', $fieldDenormalizer, $policy); diff --git a/tests/Unit/Mapping/LazyDenormalizationObjectMappingTest.php b/tests/Unit/Mapping/LazyDenormalizationObjectMappingTest.php index 40ad5c5..ac83ef3 100644 --- a/tests/Unit/Mapping/LazyDenormalizationObjectMappingTest.php +++ b/tests/Unit/Mapping/LazyDenormalizationObjectMappingTest.php @@ -7,9 +7,8 @@ use Chubbyphp\Deserialization\Mapping\DenormalizationFieldMappingInterface; use Chubbyphp\Deserialization\Mapping\DenormalizationObjectMappingInterface; use Chubbyphp\Deserialization\Mapping\LazyDenormalizationObjectMapping; -use Chubbyphp\Mock\Call; -use Chubbyphp\Mock\MockByCallsTrait; -use PHPUnit\Framework\MockObject\MockObject; +use Chubbyphp\Mock\MockMethod\WithReturn; +use Chubbyphp\Mock\MockObjectBuilder; use PHPUnit\Framework\TestCase; use Psr\Container\ContainerInterface; @@ -20,26 +19,25 @@ */ final class LazyDenormalizationObjectMappingTest extends TestCase { - use MockByCallsTrait; - public function testInvoke(): void { - $denormalizationFieldMappings = [$this->getMockByCalls(DenormalizationFieldMappingInterface::class)]; + $builder = new MockObjectBuilder(); + + /** @var DenormalizationFieldMappingInterface[] $denormalizationFieldMappings */ + $denormalizationFieldMappings = [$builder->create(DenormalizationFieldMappingInterface::class, [])]; $factory = static function (): void {}; - /** @var DenormalizationObjectMappingInterface|MockObject $denormalizationObjectMapping */ - $denormalizationObjectMapping = $this->getMockByCalls(DenormalizationObjectMappingInterface::class, [ - Call::create('getDenormalizationFactory')->with('path', 'type')->willReturn($factory), - Call::create('getDenormalizationFieldMappings') - ->with('path', 'type') - ->willReturn($denormalizationFieldMappings), + /** @var DenormalizationObjectMappingInterface $denormalizationObjectMapping */ + $denormalizationObjectMapping = $builder->create(DenormalizationObjectMappingInterface::class, [ + new WithReturn('getDenormalizationFactory', ['path', 'type'], $factory), + new WithReturn('getDenormalizationFieldMappings', ['path', 'type'], $denormalizationFieldMappings), ]); - /** @var ContainerInterface|MockObject $container */ - $container = $this->getMockByCalls(ContainerInterface::class, [ - Call::create('get')->with('service')->willReturn($denormalizationObjectMapping), - Call::create('get')->with('service')->willReturn($denormalizationObjectMapping), + /** @var ContainerInterface $container */ + $container = $builder->create(ContainerInterface::class, [ + new WithReturn('get', ['service'], $denormalizationObjectMapping), + new WithReturn('get', ['service'], $denormalizationObjectMapping), ]); $objectMapping = new LazyDenormalizationObjectMapping($container, 'service', \stdClass::class); diff --git a/tests/Unit/Policy/AndPolicyTest.php b/tests/Unit/Policy/AndPolicyTest.php index b67b970..ae2e81b 100644 --- a/tests/Unit/Policy/AndPolicyTest.php +++ b/tests/Unit/Policy/AndPolicyTest.php @@ -7,9 +7,8 @@ use Chubbyphp\Deserialization\Denormalizer\DenormalizerContextInterface; use Chubbyphp\Deserialization\Policy\AndPolicy; use Chubbyphp\Deserialization\Policy\PolicyInterface; -use Chubbyphp\Mock\Call; -use Chubbyphp\Mock\MockByCallsTrait; -use PHPUnit\Framework\MockObject\MockObject; +use Chubbyphp\Mock\MockMethod\WithReturn; +use Chubbyphp\Mock\MockObjectBuilder; use PHPUnit\Framework\TestCase; /** @@ -19,25 +18,25 @@ */ final class AndPolicyTest extends TestCase { - use MockByCallsTrait; - public function testIsCompliantIncludingPathReturnsTrueWithMultipleCompliantPolicies(): void { $object = new \stdClass(); $path = ''; - /** @var DenormalizerContextInterface|MockObject $context */ - $context = $this->getMockByCalls(DenormalizerContextInterface::class); + $builder = new MockObjectBuilder(); + + /** @var DenormalizerContextInterface $context */ + $context = $builder->create(DenormalizerContextInterface::class, []); - /** @var MockObject|PolicyInterface $compliantPolicy1 */ - $compliantPolicy1 = $this->getMockByCalls(PolicyInterface::class, [ - Call::create('isCompliant')->with($path, $object, $context)->willReturn(true), + /** @var PolicyInterface $compliantPolicy1 */ + $compliantPolicy1 = $builder->create(PolicyInterface::class, [ + new WithReturn('isCompliant', [$path, $object, $context], true), ]); - /** @var MockObject|PolicyInterface $compliantPolicy2 */ - $compliantPolicy2 = $this->getMockByCalls(PolicyInterface::class, [ - Call::create('isCompliant')->with($path, $object, $context)->willReturn(true), + /** @var PolicyInterface $compliantPolicy2 */ + $compliantPolicy2 = $builder->create(PolicyInterface::class, [ + new WithReturn('isCompliant', [$path, $object, $context], true), ]); $policy = new AndPolicy([$compliantPolicy1, $compliantPolicy2]); @@ -51,21 +50,22 @@ public function testIsCompliantIncludingPathReturnsFalseWithNonCompliantIncludin $path = ''; - /** @var DenormalizerContextInterface|MockObject $context */ - $context = $this->getMockByCalls(DenormalizerContextInterface::class); + $builder = new MockObjectBuilder(); + + /** @var DenormalizerContextInterface $context */ + $context = $builder->create(DenormalizerContextInterface::class, []); - /** @var MockObject|PolicyInterface $compliantPolicy */ - $compliantPolicy = $this->getMockByCalls(PolicyInterface::class, [ - Call::create('isCompliant')->with($path, $object, $context)->willReturn(true), + /** @var PolicyInterface $compliantPolicy */ + $compliantPolicy = $builder->create(PolicyInterface::class, [ + new WithReturn('isCompliant', [$path, $object, $context], true), ]); - /** @var MockObject|PolicyInterface $nonCompliantPolicy */ - $nonCompliantPolicy = $this->getMockByCalls(PolicyInterface::class, [ - Call::create('isCompliant')->with($path, $object, $context)->willReturn(false), + /** @var PolicyInterface $nonCompliantPolicy */ + $nonCompliantPolicy = $builder->create(PolicyInterface::class, [ + new WithReturn('isCompliant', [$path, $object, $context], false), ]); - /** @var MockObject|PolicyInterface $notExpectedToBeCalledPolicy */ - $notExpectedToBeCalledPolicy = $this->getMockByCalls(PolicyInterface::class); + $notExpectedToBeCalledPolicy = $builder->create(PolicyInterface::class, []); $policy = new AndPolicy([$compliantPolicy, $nonCompliantPolicy, $notExpectedToBeCalledPolicy]); diff --git a/tests/Unit/Policy/CallbackPolicyTest.php b/tests/Unit/Policy/CallbackPolicyTest.php index b500cfc..46f4578 100644 --- a/tests/Unit/Policy/CallbackPolicyTest.php +++ b/tests/Unit/Policy/CallbackPolicyTest.php @@ -6,8 +6,7 @@ use Chubbyphp\Deserialization\Denormalizer\DenormalizerContextInterface; use Chubbyphp\Deserialization\Policy\CallbackPolicy; -use Chubbyphp\Mock\MockByCallsTrait; -use PHPUnit\Framework\MockObject\MockObject; +use Chubbyphp\Mock\MockObjectBuilder; use PHPUnit\Framework\TestCase; /** @@ -17,16 +16,16 @@ */ final class CallbackPolicyTest extends TestCase { - use MockByCallsTrait; - public function testIsCompliantIncludingPathReturnsTrueIfCallbackReturnsTrue(): void { $object = new \stdClass(); $path = ''; - /** @var DenormalizerContextInterface|MockObject $context */ - $context = $this->getMockByCalls(DenormalizerContextInterface::class, []); + $builder = new MockObjectBuilder(); + + /** @var DenormalizerContextInterface $context */ + $context = $builder->create(DenormalizerContextInterface::class, []); $policy = new CallbackPolicy( static function ($pathParameter, $objectParameter, $contextParameter) use ($path, $object, $context) { @@ -47,8 +46,10 @@ public function testIsCompliantIncludingPathReturnsFalseIfCallbackReturnsFalse() $path = ''; - /** @var DenormalizerContextInterface|MockObject $context */ - $context = $this->getMockByCalls(DenormalizerContextInterface::class, []); + $builder = new MockObjectBuilder(); + + /** @var DenormalizerContextInterface $context */ + $context = $builder->create(DenormalizerContextInterface::class, []); $policy = new CallbackPolicy( static function ($pathParameter, $objectParameter, $contextParameter) use ($path, $object, $context) { diff --git a/tests/Unit/Policy/GroupPolicyTest.php b/tests/Unit/Policy/GroupPolicyTest.php index 4784329..e62e677 100644 --- a/tests/Unit/Policy/GroupPolicyTest.php +++ b/tests/Unit/Policy/GroupPolicyTest.php @@ -6,9 +6,8 @@ use Chubbyphp\Deserialization\Denormalizer\DenormalizerContextInterface; use Chubbyphp\Deserialization\Policy\GroupPolicy; -use Chubbyphp\Mock\Call; -use Chubbyphp\Mock\MockByCallsTrait; -use PHPUnit\Framework\MockObject\MockObject; +use Chubbyphp\Mock\MockMethod\WithReturn; +use Chubbyphp\Mock\MockObjectBuilder; use PHPUnit\Framework\TestCase; /** @@ -18,16 +17,16 @@ */ final class GroupPolicyTest extends TestCase { - use MockByCallsTrait; - public function testIsCompliantIncludingPathReturnsTrueIfNoGroupsAreSet(): void { $object = new \stdClass(); $path = ''; - /** @var DenormalizerContextInterface|MockObject $context */ - $context = $this->getMockByCalls(DenormalizerContextInterface::class); + $builder = new MockObjectBuilder(); + + /** @var DenormalizerContextInterface $context */ + $context = $builder->create(DenormalizerContextInterface::class, []); $policy = new GroupPolicy([]); @@ -40,11 +39,15 @@ public function testIsCompliantIncludingPathReturnsTrueWithDefaultValues(): void $path = ''; - /** @var DenormalizerContextInterface|MockObject $context */ - $context = $this->getMockByCalls(DenormalizerContextInterface::class, [ - Call::create('getAttribute') - ->with(GroupPolicy::ATTRIBUTE_GROUPS, [GroupPolicy::GROUP_DEFAULT]) - ->willReturn([GroupPolicy::GROUP_DEFAULT]), + $builder = new MockObjectBuilder(); + + /** @var DenormalizerContextInterface $context */ + $context = $builder->create(DenormalizerContextInterface::class, [ + new WithReturn( + 'getAttribute', + [GroupPolicy::ATTRIBUTE_GROUPS, [GroupPolicy::GROUP_DEFAULT]], + [GroupPolicy::GROUP_DEFAULT] + ), ]); $policy = new GroupPolicy(); @@ -58,11 +61,11 @@ public function testIsCompliantIncludingPathReturnsTrueIfOneGroupMatches(): void $path = ''; - /** @var DenormalizerContextInterface|MockObject $context */ - $context = $this->getMockByCalls(DenormalizerContextInterface::class, [ - Call::create('getAttribute') - ->with(GroupPolicy::ATTRIBUTE_GROUPS, [GroupPolicy::GROUP_DEFAULT]) - ->willReturn(['group2']), + $builder = new MockObjectBuilder(); + + /** @var DenormalizerContextInterface $context */ + $context = $builder->create(DenormalizerContextInterface::class, [ + new WithReturn('getAttribute', [GroupPolicy::ATTRIBUTE_GROUPS, [GroupPolicy::GROUP_DEFAULT]], ['group2']), ]); $policy = new GroupPolicy(['group1', 'group2']); @@ -76,11 +79,11 @@ public function testIsCompliantIncludingPathReturnsFalseIfNoGroupsAreSetInContex $path = ''; - /** @var DenormalizerContextInterface|MockObject $context */ - $context = $this->getMockByCalls(DenormalizerContextInterface::class, [ - Call::create('getAttribute') - ->with(GroupPolicy::ATTRIBUTE_GROUPS, [GroupPolicy::GROUP_DEFAULT]) - ->willReturn([]), + $builder = new MockObjectBuilder(); + + /** @var DenormalizerContextInterface $context */ + $context = $builder->create(DenormalizerContextInterface::class, [ + new WithReturn('getAttribute', [GroupPolicy::ATTRIBUTE_GROUPS, [GroupPolicy::GROUP_DEFAULT]], []), ]); $policy = new GroupPolicy(['group1', 'group2']); @@ -94,11 +97,15 @@ public function testIsCompliantIncludingPathReturnsFalseIfNoGroupsMatch(): void $path = ''; - /** @var DenormalizerContextInterface|MockObject $context */ - $context = $this->getMockByCalls(DenormalizerContextInterface::class, [ - Call::create('getAttribute') - ->with(GroupPolicy::ATTRIBUTE_GROUPS, [GroupPolicy::GROUP_DEFAULT]) - ->willReturn(['unknownGroup']), + $builder = new MockObjectBuilder(); + + /** @var DenormalizerContextInterface $context */ + $context = $builder->create(DenormalizerContextInterface::class, [ + new WithReturn( + 'getAttribute', + [GroupPolicy::ATTRIBUTE_GROUPS, [GroupPolicy::GROUP_DEFAULT]], + ['unknownGroup'] + ), ]); $policy = new GroupPolicy(['group1', 'group2']); diff --git a/tests/Unit/Policy/NotPolicyTest.php b/tests/Unit/Policy/NotPolicyTest.php index 4a0ec48..5eef0cf 100644 --- a/tests/Unit/Policy/NotPolicyTest.php +++ b/tests/Unit/Policy/NotPolicyTest.php @@ -7,9 +7,8 @@ use Chubbyphp\Deserialization\Denormalizer\DenormalizerContextInterface; use Chubbyphp\Deserialization\Policy\NotPolicy; use Chubbyphp\Deserialization\Policy\PolicyInterface; -use Chubbyphp\Mock\Call; -use Chubbyphp\Mock\MockByCallsTrait; -use PHPUnit\Framework\MockObject\MockObject; +use Chubbyphp\Mock\MockMethod\WithReturn; +use Chubbyphp\Mock\MockObjectBuilder; use PHPUnit\Framework\TestCase; /** @@ -19,20 +18,20 @@ */ final class NotPolicyTest extends TestCase { - use MockByCallsTrait; - public function testIsCompliantIncludingPathReturnsTrueIfGivenPolicyIncludingPathReturnsFalse(): void { $object = new \stdClass(); $path = ''; - /** @var DenormalizerContextInterface|MockObject $context */ - $context = $this->getMockByCalls(DenormalizerContextInterface::class, []); + $builder = new MockObjectBuilder(); + + /** @var DenormalizerContextInterface $context */ + $context = $builder->create(DenormalizerContextInterface::class, []); - /** @var MockObject|PolicyInterface $nonCompliantPolicy */ - $nonCompliantPolicy = $this->getMockByCalls(PolicyInterface::class, [ - Call::create('isCompliant')->with($path, $object, $context)->willReturn(false), + /** @var PolicyInterface $nonCompliantPolicy */ + $nonCompliantPolicy = $builder->create(PolicyInterface::class, [ + new WithReturn('isCompliant', [$path, $object, $context], false), ]); $policy = new NotPolicy($nonCompliantPolicy); @@ -46,12 +45,14 @@ public function testIsCompliantIncludingPathReturnsFalseIfGivenPolicyIncludingPa $path = ''; - /** @var DenormalizerContextInterface|MockObject $context */ - $context = $this->getMockByCalls(DenormalizerContextInterface::class, []); + $builder = new MockObjectBuilder(); + + /** @var DenormalizerContextInterface $context */ + $context = $builder->create(DenormalizerContextInterface::class, []); - /** @var MockObject|PolicyInterface $nonCompliantPolicy */ - $nonCompliantPolicy = $this->getMockByCalls(PolicyInterface::class, [ - Call::create('isCompliant')->with($path, $object, $context)->willReturn(true), + /** @var PolicyInterface $compliantPolicy */ + $nonCompliantPolicy = $builder->create(PolicyInterface::class, [ + new WithReturn('isCompliant', [$path, $object, $context], true), ]); $policy = new NotPolicy($nonCompliantPolicy); diff --git a/tests/Unit/Policy/NullPolicyTest.php b/tests/Unit/Policy/NullPolicyTest.php index ae2b216..1f19b43 100644 --- a/tests/Unit/Policy/NullPolicyTest.php +++ b/tests/Unit/Policy/NullPolicyTest.php @@ -6,8 +6,7 @@ use Chubbyphp\Deserialization\Denormalizer\DenormalizerContextInterface; use Chubbyphp\Deserialization\Policy\NullPolicy; -use Chubbyphp\Mock\MockByCallsTrait; -use PHPUnit\Framework\MockObject\MockObject; +use Chubbyphp\Mock\MockObjectBuilder; use PHPUnit\Framework\TestCase; /** @@ -17,16 +16,16 @@ */ final class NullPolicyTest extends TestCase { - use MockByCallsTrait; - public function testIsCompliantIncludingReturnsTrue(): void { $object = new \stdClass(); $path = ''; - /** @var DenormalizerContextInterface|MockObject $context */ - $context = $this->getMockByCalls(DenormalizerContextInterface::class); + $builder = new MockObjectBuilder(); + + /** @var DenormalizerContextInterface $context */ + $context = $builder->create(DenormalizerContextInterface::class, []); $policy = new NullPolicy(); diff --git a/tests/Unit/Policy/OrPolicyTest.php b/tests/Unit/Policy/OrPolicyTest.php index 244a2b2..b1b26c4 100644 --- a/tests/Unit/Policy/OrPolicyTest.php +++ b/tests/Unit/Policy/OrPolicyTest.php @@ -7,9 +7,8 @@ use Chubbyphp\Deserialization\Denormalizer\DenormalizerContextInterface; use Chubbyphp\Deserialization\Policy\OrPolicy; use Chubbyphp\Deserialization\Policy\PolicyInterface; -use Chubbyphp\Mock\Call; -use Chubbyphp\Mock\MockByCallsTrait; -use PHPUnit\Framework\MockObject\MockObject; +use Chubbyphp\Mock\MockMethod\WithReturn; +use Chubbyphp\Mock\MockObjectBuilder; use PHPUnit\Framework\TestCase; /** @@ -19,29 +18,29 @@ */ final class OrPolicyTest extends TestCase { - use MockByCallsTrait; - public function testIsCompliantIncludingPathReturnsTrueIfOnePolicyIncludingPathReturnsTrue(): void { $object = new \stdClass(); $path = ''; - /** @var DenormalizerContextInterface|MockObject $context */ - $context = $this->getMockByCalls(DenormalizerContextInterface::class, []); + $builder = new MockObjectBuilder(); + + /** @var DenormalizerContextInterface $context */ + $context = $builder->create(DenormalizerContextInterface::class, []); - /** @var MockObject|PolicyInterface $nonCompliantPolicy */ - $nonCompliantPolicy = $this->getMockByCalls(PolicyInterface::class, [ - Call::create('isCompliant')->with($path, $object, $context)->willReturn(false), + /** @var PolicyInterface $nonCompliantPolicy */ + $nonCompliantPolicy = $builder->create(PolicyInterface::class, [ + new WithReturn('isCompliant', [$path, $object, $context], false), ]); - /** @var MockObject|PolicyInterface $compliantPolicy */ - $compliantPolicy = $this->getMockByCalls(PolicyInterface::class, [ - Call::create('isCompliant')->with($path, $object, $context)->willReturn(true), + /** @var PolicyInterface $compliantPolicy */ + $compliantPolicy = $builder->create(PolicyInterface::class, [ + new WithReturn('isCompliant', [$path, $object, $context], true), ]); - /** @var MockObject|PolicyInterface $notToBeCalledPolicy */ - $notToBeCalledPolicy = $this->getMockByCalls(PolicyInterface::class, []); + /** @var PolicyInterface $notToBeCalledPolicy */ + $notToBeCalledPolicy = $builder->create(PolicyInterface::class, []); $policy = new OrPolicy([$nonCompliantPolicy, $compliantPolicy, $notToBeCalledPolicy]); @@ -54,17 +53,19 @@ public function testIsCompliantIncludingReturnsFalseIfAllPoliciesReturnFalse(): $path = ''; - /** @var DenormalizerContextInterface|MockObject $context */ - $context = $this->getMockByCalls(DenormalizerContextInterface::class, []); + $builder = new MockObjectBuilder(); + + /** @var DenormalizerContextInterface $context */ + $context = $builder->create(DenormalizerContextInterface::class, []); - /** @var MockObject|PolicyInterface $nonCompliantPolicy1 */ - $nonCompliantPolicy1 = $this->getMockByCalls(PolicyInterface::class, [ - Call::create('isCompliant')->with($path, $object, $context)->willReturn(false), + /** @var PolicyInterface $nonCompliantPolicy1 */ + $nonCompliantPolicy1 = $builder->create(PolicyInterface::class, [ + new WithReturn('isCompliant', [$path, $object, $context], false), ]); - /** @var MockObject|PolicyInterface $nonCompliantPolicy2 */ - $nonCompliantPolicy2 = $this->getMockByCalls(PolicyInterface::class, [ - Call::create('isCompliant')->with($path, $object, $context)->willReturn(false), + /** @var PolicyInterface $nonCompliantPolicy2 */ + $nonCompliantPolicy2 = $builder->create(PolicyInterface::class, [ + new WithReturn('isCompliant', [$path, $object, $context], false), ]); $policy = new OrPolicy([$nonCompliantPolicy1, $nonCompliantPolicy2]); diff --git a/tests/Unit/ServiceFactory/DenormalizationFieldMappingFactoryFactoryTest.php b/tests/Unit/ServiceFactory/DenormalizationFieldMappingFactoryFactoryTest.php index 52d7b14..29e4b5b 100644 --- a/tests/Unit/ServiceFactory/DenormalizationFieldMappingFactoryFactoryTest.php +++ b/tests/Unit/ServiceFactory/DenormalizationFieldMappingFactoryFactoryTest.php @@ -6,7 +6,7 @@ use Chubbyphp\Deserialization\Mapping\DenormalizationFieldMappingFactoryInterface; use Chubbyphp\Deserialization\ServiceFactory\DenormalizationFieldMappingFactoryFactory; -use Chubbyphp\Mock\MockByCallsTrait; +use Chubbyphp\Mock\MockObjectBuilder; use PHPUnit\Framework\TestCase; use Psr\Container\ContainerInterface; @@ -17,12 +17,12 @@ */ final class DenormalizationFieldMappingFactoryFactoryTest extends TestCase { - use MockByCallsTrait; - public function testInvoke(): void { + $builder = new MockObjectBuilder(); + /** @var ContainerInterface $container */ - $container = $this->getMockByCalls(ContainerInterface::class, []); + $container = $builder->create(ContainerInterface::class, []); $factory = new DenormalizationFieldMappingFactoryFactory(); @@ -33,8 +33,10 @@ public function testInvoke(): void public function testCallStatic(): void { + $builder = new MockObjectBuilder(); + /** @var ContainerInterface $container */ - $container = $this->getMockByCalls(ContainerInterface::class, []); + $container = $builder->create(ContainerInterface::class, []); $factory = [DenormalizationFieldMappingFactoryFactory::class, 'default']; diff --git a/tests/Unit/ServiceFactory/DenormalizerFactoryTest.php b/tests/Unit/ServiceFactory/DenormalizerFactoryTest.php index 61e78ce..82267c2 100644 --- a/tests/Unit/ServiceFactory/DenormalizerFactoryTest.php +++ b/tests/Unit/ServiceFactory/DenormalizerFactoryTest.php @@ -7,8 +7,8 @@ use Chubbyphp\Deserialization\Denormalizer\DenormalizerInterface; use Chubbyphp\Deserialization\Denormalizer\DenormalizerObjectMappingRegistryInterface; use Chubbyphp\Deserialization\ServiceFactory\DenormalizerFactory; -use Chubbyphp\Mock\Call; -use Chubbyphp\Mock\MockByCallsTrait; +use Chubbyphp\Mock\MockMethod\WithReturn; +use Chubbyphp\Mock\MockObjectBuilder; use PHPUnit\Framework\TestCase; use Psr\Container\ContainerInterface; use Psr\Log\LoggerInterface; @@ -20,20 +20,18 @@ */ final class DenormalizerFactoryTest extends TestCase { - use MockByCallsTrait; - public function testInvoke(): void { + $builder = new MockObjectBuilder(); + /** @var DenormalizerObjectMappingRegistryInterface $normalizerObjectMappingRegistry */ - $normalizerObjectMappingRegistry = $this->getMockByCalls(DenormalizerObjectMappingRegistryInterface::class); + $normalizerObjectMappingRegistry = $builder->create(DenormalizerObjectMappingRegistryInterface::class, []); /** @var ContainerInterface $container */ - $container = $this->getMockByCalls(ContainerInterface::class, [ - Call::create('has')->with(DenormalizerObjectMappingRegistryInterface::class)->willReturn(true), - Call::create('get') - ->with(DenormalizerObjectMappingRegistryInterface::class) - ->willReturn($normalizerObjectMappingRegistry), - Call::create('has')->with(LoggerInterface::class)->willReturn(false), + $container = $builder->create(ContainerInterface::class, [ + new WithReturn('has', [DenormalizerObjectMappingRegistryInterface::class], true), + new WithReturn('get', [DenormalizerObjectMappingRegistryInterface::class], $normalizerObjectMappingRegistry), + new WithReturn('has', [LoggerInterface::class], false), ]); $factory = new DenormalizerFactory(); @@ -45,16 +43,16 @@ public function testInvoke(): void public function testCallStatic(): void { + $builder = new MockObjectBuilder(); + /** @var DenormalizerObjectMappingRegistryInterface $normalizerObjectMappingRegistry */ - $normalizerObjectMappingRegistry = $this->getMockByCalls(DenormalizerObjectMappingRegistryInterface::class); + $normalizerObjectMappingRegistry = $builder->create(DenormalizerObjectMappingRegistryInterface::class, []); /** @var ContainerInterface $container */ - $container = $this->getMockByCalls(ContainerInterface::class, [ - Call::create('has')->with(DenormalizerObjectMappingRegistryInterface::class.'default')->willReturn(true), - Call::create('get') - ->with(DenormalizerObjectMappingRegistryInterface::class.'default') - ->willReturn($normalizerObjectMappingRegistry), - Call::create('has')->with(LoggerInterface::class)->willReturn(false), + $container = $builder->create(ContainerInterface::class, [ + new WithReturn('has', [DenormalizerObjectMappingRegistryInterface::class.'default'], true), + new WithReturn('get', [DenormalizerObjectMappingRegistryInterface::class.'default'], $normalizerObjectMappingRegistry), + new WithReturn('has', [LoggerInterface::class], false), ]); $factory = [DenormalizerFactory::class, 'default']; diff --git a/tests/Unit/ServiceFactory/DenormalizerObjectMappingRegistryFactoryTest.php b/tests/Unit/ServiceFactory/DenormalizerObjectMappingRegistryFactoryTest.php index 948ef3e..4dd8bfe 100644 --- a/tests/Unit/ServiceFactory/DenormalizerObjectMappingRegistryFactoryTest.php +++ b/tests/Unit/ServiceFactory/DenormalizerObjectMappingRegistryFactoryTest.php @@ -7,8 +7,8 @@ use Chubbyphp\Deserialization\Denormalizer\DenormalizerObjectMappingRegistryInterface; use Chubbyphp\Deserialization\Mapping\DenormalizationObjectMappingInterface; use Chubbyphp\Deserialization\ServiceFactory\DenormalizerObjectMappingRegistryFactory; -use Chubbyphp\Mock\Call; -use Chubbyphp\Mock\MockByCallsTrait; +use Chubbyphp\Mock\MockMethod\WithReturn; +use Chubbyphp\Mock\MockObjectBuilder; use PHPUnit\Framework\TestCase; use Psr\Container\ContainerInterface; @@ -19,13 +19,13 @@ */ final class DenormalizerObjectMappingRegistryFactoryTest extends TestCase { - use MockByCallsTrait; - public function testInvoke(): void { + $builder = new MockObjectBuilder(); + /** @var ContainerInterface $container */ - $container = $this->getMockByCalls(ContainerInterface::class, [ - Call::create('get')->with(DenormalizationObjectMappingInterface::class.'[]')->willReturn([]), + $container = $builder->create(ContainerInterface::class, [ + new WithReturn('get', [DenormalizationObjectMappingInterface::class.'[]'], []), ]); $factory = new DenormalizerObjectMappingRegistryFactory(); @@ -37,9 +37,11 @@ public function testInvoke(): void public function testCallStatic(): void { + $builder = new MockObjectBuilder(); + /** @var ContainerInterface $container */ - $container = $this->getMockByCalls(ContainerInterface::class, [ - Call::create('get')->with(DenormalizationObjectMappingInterface::class.'[]default')->willReturn([]), + $container = $builder->create(ContainerInterface::class, [ + new WithReturn('get', [DenormalizationObjectMappingInterface::class.'[]default'], []), ]); $factory = [DenormalizerObjectMappingRegistryFactory::class, 'default']; diff --git a/tests/Unit/ServiceFactory/DeserializationServiceFactoryTest.php b/tests/Unit/ServiceFactory/DeserializationServiceFactoryTest.php index 406f7b8..afaec97 100644 --- a/tests/Unit/ServiceFactory/DeserializationServiceFactoryTest.php +++ b/tests/Unit/ServiceFactory/DeserializationServiceFactoryTest.php @@ -11,8 +11,7 @@ use Chubbyphp\Deserialization\Deserializer; use Chubbyphp\Deserialization\Mapping\DenormalizationFieldMappingFactory; use Chubbyphp\Deserialization\ServiceFactory\DeserializationServiceFactory; -use Chubbyphp\Mock\MockByCallsTrait; -use PHPUnit\Framework\MockObject\MockObject; +use Chubbyphp\Mock\MockObjectBuilder; use PHPUnit\Framework\TestCase; use Psr\Log\LoggerInterface; use Psr\Log\NullLogger; @@ -24,12 +23,11 @@ */ final class DeserializationServiceFactoryTest extends TestCase { - use MockByCallsTrait; - public function testRegister(): void { $container = new Container(); - $container->factories((new DeserializationServiceFactory())()); + $factory = new DeserializationServiceFactory(); + $container->factories($factory()); self::assertTrue($container->has('deserializer')); @@ -71,14 +69,18 @@ public function testRegister(): void public function testRegisterWithDefinedLogger(): void { - /** @var LoggerInterface|MockObject $logger */ - $logger = $this->getMockByCalls(LoggerInterface::class); + $builder = new MockObjectBuilder(); + + /** @var LoggerInterface $logger */ + $logger = $builder->create(LoggerInterface::class, []); $container = new Container([ 'logger' => static fn () => $logger, ]); - $container->factories((new DeserializationServiceFactory())()); + $factory = new DeserializationServiceFactory(); + + $container->factories($factory()); /** @var Denormalizer $denormalizer */ $denormalizer = $container->get('deserializer.denormalizer'); diff --git a/tests/Unit/ServiceFactory/DeserializerFactoryTest.php b/tests/Unit/ServiceFactory/DeserializerFactoryTest.php index d754882..3e56d34 100644 --- a/tests/Unit/ServiceFactory/DeserializerFactoryTest.php +++ b/tests/Unit/ServiceFactory/DeserializerFactoryTest.php @@ -8,8 +8,8 @@ use Chubbyphp\Deserialization\Denormalizer\DenormalizerInterface; use Chubbyphp\Deserialization\DeserializerInterface; use Chubbyphp\Deserialization\ServiceFactory\DeserializerFactory; -use Chubbyphp\Mock\Call; -use Chubbyphp\Mock\MockByCallsTrait; +use Chubbyphp\Mock\MockMethod\WithReturn; +use Chubbyphp\Mock\MockObjectBuilder; use PHPUnit\Framework\TestCase; use Psr\Container\ContainerInterface; @@ -20,22 +20,22 @@ */ final class DeserializerFactoryTest extends TestCase { - use MockByCallsTrait; - public function testInvoke(): void { + $builder = new MockObjectBuilder(); + /** @var DecoderInterface $decoder */ - $decoder = $this->getMockByCalls(DecoderInterface::class); + $decoder = $builder->create(DecoderInterface::class, []); /** @var DenormalizerInterface $denormalizer */ - $denormalizer = $this->getMockByCalls(DenormalizerInterface::class); + $denormalizer = $builder->create(DenormalizerInterface::class, []); /** @var ContainerInterface $container */ - $container = $this->getMockByCalls(ContainerInterface::class, [ - Call::create('has')->with(DecoderInterface::class)->willReturn(true), - Call::create('get')->with(DecoderInterface::class)->willReturn($decoder), - Call::create('has')->with(DenormalizerInterface::class)->willReturn(true), - Call::create('get')->with(DenormalizerInterface::class)->willReturn($denormalizer), + $container = $builder->create(ContainerInterface::class, [ + new WithReturn('has', [DecoderInterface::class], true), + new WithReturn('get', [DecoderInterface::class], $decoder), + new WithReturn('has', [DenormalizerInterface::class], true), + new WithReturn('get', [DenormalizerInterface::class], $denormalizer), ]); $factory = new DeserializerFactory(); @@ -47,18 +47,23 @@ public function testInvoke(): void public function testCallStatic(): void { + $builder = new MockObjectBuilder(); + + $decoderKey = DecoderInterface::class.'default'; + $denormalizerKey = DenormalizerInterface::class.'default'; + /** @var DecoderInterface $decoder */ - $decoder = $this->getMockByCalls(DecoderInterface::class); + $decoder = $builder->create(DecoderInterface::class, []); /** @var DenormalizerInterface $denormalizer */ - $denormalizer = $this->getMockByCalls(DenormalizerInterface::class); + $denormalizer = $builder->create(DenormalizerInterface::class, []); /** @var ContainerInterface $container */ - $container = $this->getMockByCalls(ContainerInterface::class, [ - Call::create('has')->with(DecoderInterface::class.'default')->willReturn(true), - Call::create('get')->with(DecoderInterface::class.'default')->willReturn($decoder), - Call::create('has')->with(DenormalizerInterface::class.'default')->willReturn(true), - Call::create('get')->with(DenormalizerInterface::class.'default')->willReturn($denormalizer), + $container = $builder->create(ContainerInterface::class, [ + new WithReturn('has', [$decoderKey], true), + new WithReturn('get', [$decoderKey], $decoder), + new WithReturn('has', [$denormalizerKey], true), + new WithReturn('get', [$denormalizerKey], $denormalizer), ]); $factory = [DeserializerFactory::class, 'default']; diff --git a/tests/Unit/ServiceProvider/DeserializationServiceProviderTest.php b/tests/Unit/ServiceProvider/DeserializationServiceProviderTest.php index dcc5788..1de14ed 100644 --- a/tests/Unit/ServiceProvider/DeserializationServiceProviderTest.php +++ b/tests/Unit/ServiceProvider/DeserializationServiceProviderTest.php @@ -10,8 +10,7 @@ use Chubbyphp\Deserialization\Deserializer; use Chubbyphp\Deserialization\Mapping\DenormalizationFieldMappingFactory; use Chubbyphp\Deserialization\ServiceProvider\DeserializationServiceProvider; -use Chubbyphp\Mock\MockByCallsTrait; -use PHPUnit\Framework\MockObject\MockObject; +use Chubbyphp\Mock\MockObjectBuilder; use PHPUnit\Framework\TestCase; use Pimple\Container; use Psr\Log\LoggerInterface; @@ -24,8 +23,6 @@ */ final class DeserializationServiceProviderTest extends TestCase { - use MockByCallsTrait; - public function testRegister(): void { $container = new Container(); @@ -71,8 +68,10 @@ public function testRegister(): void public function testRegisterWithDefinedLogger(): void { - /** @var LoggerInterface|MockObject $logger */ - $logger = $this->getMockByCalls(LoggerInterface::class); + $builder = new MockObjectBuilder(); + + /** @var LoggerInterface $logger */ + $logger = $builder->create(LoggerInterface::class, []); $container = new Container([ 'logger' => $logger,