diff --git a/composer.json b/composer.json index bbb3fdd..d9e0e1d 100644 --- a/composer.json +++ b/composer.json @@ -21,21 +21,20 @@ "require": { "php": "~8.2.0 || ~8.3.0 || ~8.4.0", "ext-openssl": "*", - "symfony/event-dispatcher": "^5.4.29|^6.4.0|^7.0.0", + "psr/cache": "^2.0.0 || ^3.0.0", + "psr/simple-cache": "^2.0.0 || ^3.0.0", + "symfony/event-dispatcher": "^5.4.29 || ^6.4.0 || ^7.0.0", "symfony/type-info": "^7.2.4" }, "require-dev": { "infection/infection": "^0.29.10", "patchlevel/coding-standard": "^1.3.0", - "psr/cache": "^2.0.0|^3.0.0", - "psr/simple-cache": "^2.0.0|^3.0.0", "phpbench/phpbench": "^1.2.15", - "phpspec/prophecy-phpunit": "^2.1.0", "phpstan/phpstan": "^2.1.0", "phpunit/phpunit": "^11.5.17", "psalm/plugin-phpunit": "^0.19.2", "roave/infection-static-analysis-plugin": "^1.36.0", - "symfony/var-dumper": "^5.4.29|^6.4.0|^7.0.0", + "symfony/var-dumper": "^5.4.29 || ^6.4.0 || ^7.0.0", "vimeo/psalm": "^6.0.0" }, "config": { diff --git a/composer.lock b/composer.lock index dca1489..ebf27f9 100644 --- a/composer.lock +++ b/composer.lock @@ -4,8 +4,57 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "07eec00202daf96be15b9a71e33e5b1c", + "content-hash": "88a6e4328de05fee58b52ac893a9927c", "packages": [ + { + "name": "psr/cache", + "version": "3.0.0", + "source": { + "type": "git", + "url": "https://github.com/php-fig/cache.git", + "reference": "aa5030cfa5405eccfdcb1083ce040c2cb8d253bf" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/php-fig/cache/zipball/aa5030cfa5405eccfdcb1083ce040c2cb8d253bf", + "reference": "aa5030cfa5405eccfdcb1083ce040c2cb8d253bf", + "shasum": "" + }, + "require": { + "php": ">=8.0.0" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "1.0.x-dev" + } + }, + "autoload": { + "psr-4": { + "Psr\\Cache\\": "src/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "PHP-FIG", + "homepage": "https://www.php-fig.org/" + } + ], + "description": "Common interface for caching libraries", + "keywords": [ + "cache", + "psr", + "psr-6" + ], + "support": { + "source": "https://github.com/php-fig/cache/tree/3.0.0" + }, + "time": "2021-02-03T23:26:27+00:00" + }, { "name": "psr/container", "version": "2.0.2", @@ -109,6 +158,57 @@ }, "time": "2019-01-08T18:20:26+00:00" }, + { + "name": "psr/simple-cache", + "version": "3.0.0", + "source": { + "type": "git", + "url": "https://github.com/php-fig/simple-cache.git", + "reference": "764e0b3939f5ca87cb904f570ef9be2d78a07865" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/php-fig/simple-cache/zipball/764e0b3939f5ca87cb904f570ef9be2d78a07865", + "reference": "764e0b3939f5ca87cb904f570ef9be2d78a07865", + "shasum": "" + }, + "require": { + "php": ">=8.0.0" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "3.0.x-dev" + } + }, + "autoload": { + "psr-4": { + "Psr\\SimpleCache\\": "src/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "PHP-FIG", + "homepage": "https://www.php-fig.org/" + } + ], + "description": "Common interfaces for simple caching", + "keywords": [ + "cache", + "caching", + "psr", + "psr-16", + "simple-cache" + ], + "support": { + "source": "https://github.com/php-fig/simple-cache/tree/3.0.0" + }, + "time": "2021-10-29T13:26:27+00:00" + }, { "name": "symfony/event-dispatcher", "version": "v7.2.0", @@ -1799,76 +1899,6 @@ }, "time": "2025-04-07T20:06:18+00:00" }, - { - "name": "doctrine/instantiator", - "version": "2.0.0", - "source": { - "type": "git", - "url": "https://github.com/doctrine/instantiator.git", - "reference": "c6222283fa3f4ac679f8b9ced9a4e23f163e80d0" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/doctrine/instantiator/zipball/c6222283fa3f4ac679f8b9ced9a4e23f163e80d0", - "reference": "c6222283fa3f4ac679f8b9ced9a4e23f163e80d0", - "shasum": "" - }, - "require": { - "php": "^8.1" - }, - "require-dev": { - "doctrine/coding-standard": "^11", - "ext-pdo": "*", - "ext-phar": "*", - "phpbench/phpbench": "^1.2", - "phpstan/phpstan": "^1.9.4", - "phpstan/phpstan-phpunit": "^1.3", - "phpunit/phpunit": "^9.5.27", - "vimeo/psalm": "^5.4" - }, - "type": "library", - "autoload": { - "psr-4": { - "Doctrine\\Instantiator\\": "src/Doctrine/Instantiator/" - } - }, - "notification-url": "https://packagist.org/downloads/", - "license": [ - "MIT" - ], - "authors": [ - { - "name": "Marco Pivetta", - "email": "ocramius@gmail.com", - "homepage": "https://ocramius.github.io/" - } - ], - "description": "A small, lightweight utility to instantiate objects in PHP without invoking their constructors", - "homepage": "https://www.doctrine-project.org/projects/instantiator.html", - "keywords": [ - "constructor", - "instantiate" - ], - "support": { - "issues": "https://github.com/doctrine/instantiator/issues", - "source": "https://github.com/doctrine/instantiator/tree/2.0.0" - }, - "funding": [ - { - "url": "https://www.doctrine-project.org/sponsorship.html", - "type": "custom" - }, - { - "url": "https://www.patreon.com/phpdoctrine", - "type": "patreon" - }, - { - "url": "https://tidelift.com/funding/github/packagist/doctrine%2Finstantiator", - "type": "tidelift" - } - ], - "time": "2022-12-30T00:23:10+00:00" - }, { "name": "doctrine/lexer", "version": "3.0.1", @@ -3462,131 +3492,6 @@ }, "time": "2024-11-09T15:12:26+00:00" }, - { - "name": "phpspec/prophecy", - "version": "v1.20.0", - "source": { - "type": "git", - "url": "https://github.com/phpspec/prophecy.git", - "reference": "a0165c648cab6a80311c74ffc708a07bb53ecc93" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/phpspec/prophecy/zipball/a0165c648cab6a80311c74ffc708a07bb53ecc93", - "reference": "a0165c648cab6a80311c74ffc708a07bb53ecc93", - "shasum": "" - }, - "require": { - "doctrine/instantiator": "^1.2 || ^2.0", - "php": "^7.2 || 8.0.* || 8.1.* || 8.2.* || 8.3.* || 8.4.*", - "phpdocumentor/reflection-docblock": "^5.2", - "sebastian/comparator": "^3.0 || ^4.0 || ^5.0 || ^6.0", - "sebastian/recursion-context": "^3.0 || ^4.0 || ^5.0 || ^6.0" - }, - "require-dev": { - "friendsofphp/php-cs-fixer": "^3.40", - "phpspec/phpspec": "^6.0 || ^7.0", - "phpstan/phpstan": "^1.9", - "phpunit/phpunit": "^8.0 || ^9.0 || ^10.0" - }, - "type": "library", - "extra": { - "branch-alias": { - "dev-master": "1.x-dev" - } - }, - "autoload": { - "psr-4": { - "Prophecy\\": "src/Prophecy" - } - }, - "notification-url": "https://packagist.org/downloads/", - "license": [ - "MIT" - ], - "authors": [ - { - "name": "Konstantin Kudryashov", - "email": "ever.zet@gmail.com", - "homepage": "http://everzet.com" - }, - { - "name": "Marcello Duarte", - "email": "marcello.duarte@gmail.com" - } - ], - "description": "Highly opinionated mocking framework for PHP 5.3+", - "homepage": "https://github.com/phpspec/prophecy", - "keywords": [ - "Double", - "Dummy", - "dev", - "fake", - "mock", - "spy", - "stub" - ], - "support": { - "issues": "https://github.com/phpspec/prophecy/issues", - "source": "https://github.com/phpspec/prophecy/tree/v1.20.0" - }, - "time": "2024-11-19T13:12:41+00:00" - }, - { - "name": "phpspec/prophecy-phpunit", - "version": "v2.3.0", - "source": { - "type": "git", - "url": "https://github.com/phpspec/prophecy-phpunit.git", - "reference": "8819516c1b489ecee4c60db5f5432fac1ea8ac6f" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/phpspec/prophecy-phpunit/zipball/8819516c1b489ecee4c60db5f5432fac1ea8ac6f", - "reference": "8819516c1b489ecee4c60db5f5432fac1ea8ac6f", - "shasum": "" - }, - "require": { - "php": "^7.3 || ^8", - "phpspec/prophecy": "^1.18", - "phpunit/phpunit": "^9.1 || ^10.1 || ^11.0" - }, - "require-dev": { - "phpstan/phpstan": "^1.10" - }, - "type": "library", - "extra": { - "branch-alias": { - "dev-master": "2.x-dev" - } - }, - "autoload": { - "psr-4": { - "Prophecy\\PhpUnit\\": "src" - } - }, - "notification-url": "https://packagist.org/downloads/", - "license": [ - "MIT" - ], - "authors": [ - { - "name": "Christophe Coevoet", - "email": "stof@notk.org" - } - ], - "description": "Integrating the Prophecy mocking library in PHPUnit test cases", - "homepage": "http://phpspec.net", - "keywords": [ - "phpunit", - "prophecy" - ], - "support": { - "issues": "https://github.com/phpspec/prophecy-phpunit/issues", - "source": "https://github.com/phpspec/prophecy-phpunit/tree/v2.3.0" - }, - "time": "2024-11-19T13:24:17+00:00" - }, { "name": "phpstan/phpdoc-parser", "version": "2.1.0", @@ -4174,55 +4079,6 @@ }, "time": "2025-03-31T18:49:55+00:00" }, - { - "name": "psr/cache", - "version": "3.0.0", - "source": { - "type": "git", - "url": "https://github.com/php-fig/cache.git", - "reference": "aa5030cfa5405eccfdcb1083ce040c2cb8d253bf" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/php-fig/cache/zipball/aa5030cfa5405eccfdcb1083ce040c2cb8d253bf", - "reference": "aa5030cfa5405eccfdcb1083ce040c2cb8d253bf", - "shasum": "" - }, - "require": { - "php": ">=8.0.0" - }, - "type": "library", - "extra": { - "branch-alias": { - "dev-master": "1.0.x-dev" - } - }, - "autoload": { - "psr-4": { - "Psr\\Cache\\": "src/" - } - }, - "notification-url": "https://packagist.org/downloads/", - "license": [ - "MIT" - ], - "authors": [ - { - "name": "PHP-FIG", - "homepage": "https://www.php-fig.org/" - } - ], - "description": "Common interface for caching libraries", - "keywords": [ - "cache", - "psr", - "psr-6" - ], - "support": { - "source": "https://github.com/php-fig/cache/tree/3.0.0" - }, - "time": "2021-02-03T23:26:27+00:00" - }, { "name": "psr/http-factory", "version": "1.1.0", @@ -4381,57 +4237,6 @@ }, "time": "2024-09-11T13:17:53+00:00" }, - { - "name": "psr/simple-cache", - "version": "3.0.0", - "source": { - "type": "git", - "url": "https://github.com/php-fig/simple-cache.git", - "reference": "764e0b3939f5ca87cb904f570ef9be2d78a07865" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/php-fig/simple-cache/zipball/764e0b3939f5ca87cb904f570ef9be2d78a07865", - "reference": "764e0b3939f5ca87cb904f570ef9be2d78a07865", - "shasum": "" - }, - "require": { - "php": ">=8.0.0" - }, - "type": "library", - "extra": { - "branch-alias": { - "dev-master": "3.0.x-dev" - } - }, - "autoload": { - "psr-4": { - "Psr\\SimpleCache\\": "src/" - } - }, - "notification-url": "https://packagist.org/downloads/", - "license": [ - "MIT" - ], - "authors": [ - { - "name": "PHP-FIG", - "homepage": "https://www.php-fig.org/" - } - ], - "description": "Common interfaces for simple caching", - "keywords": [ - "cache", - "caching", - "psr", - "psr-16", - "simple-cache" - ], - "support": { - "source": "https://github.com/php-fig/simple-cache/tree/3.0.0" - }, - "time": "2021-10-29T13:26:27+00:00" - }, { "name": "revolt/event-loop", "version": "v1.0.7", diff --git a/tests/Unit/Cryptography/CryptographySubscriberTest.php b/tests/Unit/Cryptography/CryptographySubscriberTest.php index ba1af50..a8c6e03 100644 --- a/tests/Unit/Cryptography/CryptographySubscriberTest.php +++ b/tests/Unit/Cryptography/CryptographySubscriberTest.php @@ -11,15 +11,12 @@ use Patchlevel\Hydrator\Metadata\ClassMetadata; use PHPUnit\Framework\Attributes\CoversClass; use PHPUnit\Framework\TestCase; -use Prophecy\PhpUnit\ProphecyTrait; use ReflectionClass; use stdClass; #[CoversClass(CryptographySubscriber::class)] final class CryptographySubscriberTest extends TestCase { - use ProphecyTrait; - public function testSubscriptions(): void { self::assertEquals([ @@ -39,13 +36,10 @@ public function testPreHydrate(): void $metadata, ); - $cryptographer = $this->prophesize(PayloadCryptographer::class); - $cryptographer->decrypt( - $metadata, - ['foo' => 'bar'], - )->willReturn(['foo' => 'baz'])->shouldBeCalledOnce(); + $cryptographer = $this->createMock(PayloadCryptographer::class); + $cryptographer->expects($this->once())->method('decrypt')->with($metadata, ['foo' => 'bar'])->willReturn(['foo' => 'baz']); - $subscriber = new CryptographySubscriber($cryptographer->reveal()); + $subscriber = new CryptographySubscriber($cryptographer); $subscriber->preHydrate($event); self::assertEquals(['foo' => 'baz'], $event->data); @@ -62,13 +56,10 @@ public function testPostExtract(): void $metadata, ); - $cryptographer = $this->prophesize(PayloadCryptographer::class); - $cryptographer->encrypt( - $metadata, - ['foo' => 'bar'], - )->willReturn(['foo' => 'baz'])->shouldBeCalledOnce(); + $cryptographer = $this->createMock(PayloadCryptographer::class); + $cryptographer->expects($this->once())->method('encrypt')->with($metadata, ['foo' => 'bar'])->willReturn(['foo' => 'baz']); - $subscriber = new CryptographySubscriber($cryptographer->reveal()); + $subscriber = new CryptographySubscriber($cryptographer); $subscriber->postExtract($event); self::assertEquals(['foo' => 'baz'], $event->data); diff --git a/tests/Unit/Cryptography/PersonalDataPayloadCryptographerTest.php b/tests/Unit/Cryptography/PersonalDataPayloadCryptographerTest.php index fefbb2b..2468fc8 100644 --- a/tests/Unit/Cryptography/PersonalDataPayloadCryptographerTest.php +++ b/tests/Unit/Cryptography/PersonalDataPayloadCryptographerTest.php @@ -20,26 +20,22 @@ use Patchlevel\Hydrator\Tests\Unit\Fixture\PersonalDataProfileCreated; use Patchlevel\Hydrator\Tests\Unit\Fixture\PersonalDataProfileCreatedFallbackCallback; use PHPUnit\Framework\TestCase; -use Prophecy\Argument; -use Prophecy\PhpUnit\ProphecyTrait; /** @covers \Patchlevel\Hydrator\Cryptography\PersonalDataPayloadCryptographer */ final class PersonalDataPayloadCryptographerTest extends TestCase { - use ProphecyTrait; - public function testSkipEncrypt(): void { - $cipherKeyStore = $this->prophesize(CipherKeyStore::class); - $cipherKeyStore->get(Argument::any())->shouldNotBeCalled(); + $cipherKeyStore = $this->createMock(CipherKeyStore::class); + $cipherKeyStore->expects($this->never())->method('get'); - $cipherKeyFactory = $this->prophesize(CipherKeyFactory::class); - $cipher = $this->prophesize(Cipher::class); + $cipherKeyFactory = $this->createMock(CipherKeyFactory::class); + $cipher = $this->createMock(Cipher::class); $cryptographer = new PersonalDataPayloadCryptographer( - $cipherKeyStore->reveal(), - $cipherKeyFactory->reveal(), - $cipher->reveal(), + $cipherKeyStore, + $cipherKeyFactory, + $cipher, ); $payload = ['id' => 'foo', 'email' => 'info@patchlevel.de']; @@ -57,23 +53,21 @@ public function testEncryptWithMissingKey(): void 'baz', ); - $cipherKeyStore = $this->prophesize(CipherKeyStore::class); - $cipherKeyStore->get('foo')->willThrow(new CipherKeyNotExists('foo')); - $cipherKeyStore->store('foo', $cipherKey)->shouldBeCalled(); + $cipherKeyStore = $this->createMock(CipherKeyStore::class); + $cipherKeyStore->method('get')->with('foo')->willThrowException(new CipherKeyNotExists('foo')); + $cipherKeyStore->expects($this->once())->method('store')->with('foo', $cipherKey); - $cipherKeyFactory = $this->prophesize(CipherKeyFactory::class); - $cipherKeyFactory->__invoke()->willReturn($cipherKey)->shouldBeCalledOnce(); + $cipherKeyFactory = $this->createMock(CipherKeyFactory::class); + $cipherKeyFactory->expects($this->once())->method('__invoke')->willReturn($cipherKey); - $cipher = $this->prophesize(Cipher::class); - $cipher - ->encrypt($cipherKey, 'info@patchlevel.de') - ->willReturn('encrypted') - ->shouldBeCalledOnce(); + $cipher = $this->createMock(Cipher::class); + $cipher->expects($this->once())->method('encrypt')->with($cipherKey, 'info@patchlevel.de') + ->willReturn('encrypted'); $cryptographer = new PersonalDataPayloadCryptographer( - $cipherKeyStore->reveal(), - $cipherKeyFactory->reveal(), - $cipher->reveal(), + $cipherKeyStore, + $cipherKeyFactory, + $cipher, ); $result = $cryptographer->encrypt($this->metadata(PersonalDataProfileCreated::class), ['id' => 'foo', 'email' => 'info@patchlevel.de']); @@ -89,23 +83,24 @@ public function testEncryptWithExistingKey(): void 'baz', ); - $cipherKeyStore = $this->prophesize(CipherKeyStore::class); - $cipherKeyStore->get('foo')->willReturn($cipherKey); - $cipherKeyStore->store('foo', Argument::type(CipherKey::class))->shouldNotBeCalled(); + $cipherKeyStore = $this->createMock(CipherKeyStore::class); + $cipherKeyStore->method('get')->with('foo')->willReturn($cipherKey); + $cipherKeyStore + ->expects($this->never()) + ->method('store') + ->with('foo', $this->isInstanceOf(CipherKey::class)); - $cipherKeyFactory = $this->prophesize(CipherKeyFactory::class); - $cipherKeyFactory->__invoke()->shouldNotBeCalled(); + $cipherKeyFactory = $this->createMock(CipherKeyFactory::class); + $cipherKeyFactory->expects($this->never())->method('__invoke'); - $cipher = $this->prophesize(Cipher::class); - $cipher - ->encrypt($cipherKey, 'info@patchlevel.de') - ->willReturn('encrypted') - ->shouldBeCalledOnce(); + $cipher = $this->createMock(Cipher::class); + $cipher->expects($this->once())->method('encrypt')->with($cipherKey, 'info@patchlevel.de') + ->willReturn('encrypted'); $cryptographer = new PersonalDataPayloadCryptographer( - $cipherKeyStore->reveal(), - $cipherKeyFactory->reveal(), - $cipher->reveal(), + $cipherKeyStore, + $cipherKeyFactory, + $cipher, ); $result = $cryptographer->encrypt($this->metadata(PersonalDataProfileCreated::class), ['id' => 'foo', 'email' => 'info@patchlevel.de']); @@ -121,23 +116,24 @@ public function testEncryptWithExistingKeyEncryptedFieldName(): void 'baz', ); - $cipherKeyStore = $this->prophesize(CipherKeyStore::class); - $cipherKeyStore->get('foo')->willReturn($cipherKey); - $cipherKeyStore->store('foo', Argument::type(CipherKey::class))->shouldNotBeCalled(); + $cipherKeyStore = $this->createMock(CipherKeyStore::class); + $cipherKeyStore->method('get')->with('foo')->willReturn($cipherKey); + $cipherKeyStore + ->expects($this->never()) + ->method('store') + ->with('foo', $this->isInstanceOf(CipherKey::class)); - $cipherKeyFactory = $this->prophesize(CipherKeyFactory::class); - $cipherKeyFactory->__invoke()->shouldNotBeCalled(); + $cipherKeyFactory = $this->createMock(CipherKeyFactory::class); + $cipherKeyFactory->expects($this->never())->method('__invoke'); - $cipher = $this->prophesize(Cipher::class); - $cipher - ->encrypt($cipherKey, 'info@patchlevel.de') - ->willReturn('encrypted') - ->shouldBeCalledOnce(); + $cipher = $this->createMock(Cipher::class); + $cipher->expects($this->once())->method('encrypt')->with($cipherKey, 'info@patchlevel.de') + ->willReturn('encrypted'); $cryptographer = new PersonalDataPayloadCryptographer( - $cipherKeyStore->reveal(), - $cipherKeyFactory->reveal(), - $cipher->reveal(), + $cipherKeyStore, + $cipherKeyFactory, + $cipher, true, ); @@ -148,16 +144,16 @@ public function testEncryptWithExistingKeyEncryptedFieldName(): void public function testSkipDecrypt(): void { - $cipherKeyStore = $this->prophesize(CipherKeyStore::class); - $cipherKeyStore->get(Argument::any())->shouldNotBeCalled(); + $cipherKeyStore = $this->createMock(CipherKeyStore::class); + $cipherKeyStore->expects($this->never())->method('get'); - $cipherKeyFactory = $this->prophesize(CipherKeyFactory::class); - $cipher = $this->prophesize(Cipher::class); + $cipherKeyFactory = $this->createMock(CipherKeyFactory::class); + $cipher = $this->createMock(Cipher::class); $cryptographer = new PersonalDataPayloadCryptographer( - $cipherKeyStore->reveal(), - $cipherKeyFactory->reveal(), - $cipher->reveal(), + $cipherKeyStore, + $cipherKeyFactory, + $cipher, ); $payload = ['id' => 'foo', 'email' => 'info@patchlevel.de']; @@ -169,19 +165,19 @@ public function testSkipDecrypt(): void public function testDecryptWithMissingKey(): void { - $cipherKeyStore = $this->prophesize(CipherKeyStore::class); - $cipherKeyStore->get('foo')->willThrow(new CipherKeyNotExists('foo')); + $cipherKeyStore = $this->createMock(CipherKeyStore::class); + $cipherKeyStore->method('get')->with('foo')->willThrowException(new CipherKeyNotExists('foo')); - $cipherKeyFactory = $this->prophesize(CipherKeyFactory::class); - $cipherKeyFactory->__invoke()->shouldNotBeCalled(); + $cipherKeyFactory = $this->createMock(CipherKeyFactory::class); + $cipherKeyFactory->expects($this->never())->method('__invoke'); - $cipher = $this->prophesize(Cipher::class); - $cipher->decrypt()->shouldNotBeCalled(); + $cipher = $this->createMock(Cipher::class); + $cipher->expects($this->never())->method('decrypt'); $cryptographer = new PersonalDataPayloadCryptographer( - $cipherKeyStore->reveal(), - $cipherKeyFactory->reveal(), - $cipher->reveal(), + $cipherKeyStore, + $cipherKeyFactory, + $cipher, ); $result = $cryptographer->decrypt($this->metadata(PersonalDataProfileCreated::class), ['id' => 'foo', 'email' => 'encrypted']); @@ -197,23 +193,24 @@ public function testDecryptWithInvalidKey(): void 'baz', ); - $cipherKeyStore = $this->prophesize(CipherKeyStore::class); - $cipherKeyStore->get('foo')->willReturn($cipherKey); - $cipherKeyStore->store('foo', Argument::type(CipherKey::class))->shouldNotBeCalled(); + $cipherKeyStore = $this->createMock(CipherKeyStore::class); + $cipherKeyStore->method('get')->with('foo')->willReturn($cipherKey); + $cipherKeyStore + ->expects($this->never()) + ->method('store') + ->with('foo', $this->isInstanceOf(CipherKey::class)); - $cipherKeyFactory = $this->prophesize(CipherKeyFactory::class); - $cipherKeyFactory->__invoke()->shouldNotBeCalled(); + $cipherKeyFactory = $this->createMock(CipherKeyFactory::class); + $cipherKeyFactory->expects($this->never())->method('__invoke'); - $cipher = $this->prophesize(Cipher::class); - $cipher - ->decrypt($cipherKey, 'encrypted') - ->willThrow(new DecryptionFailed()) - ->shouldBeCalledOnce(); + $cipher = $this->createMock(Cipher::class); + $cipher->expects($this->once())->method('decrypt')->with($cipherKey, 'encrypted') + ->willThrowException(new DecryptionFailed()); $cryptographer = new PersonalDataPayloadCryptographer( - $cipherKeyStore->reveal(), - $cipherKeyFactory->reveal(), - $cipher->reveal(), + $cipherKeyStore, + $cipherKeyFactory, + $cipher, ); $result = $cryptographer->decrypt($this->metadata(PersonalDataProfileCreated::class), ['id' => 'foo', 'email' => 'encrypted']); @@ -229,23 +226,21 @@ public function testDecryptWithInvalidKeyWithFallbackCallback(): void 'baz', ); - $cipherKeyStore = $this->prophesize(CipherKeyStore::class); - $cipherKeyStore->get('foo')->willReturn($cipherKey); - $cipherKeyStore->store('foo', Argument::type(CipherKey::class))->shouldNotBeCalled(); + $cipherKeyStore = $this->createMock(CipherKeyStore::class); + $cipherKeyStore->method('get')->with('foo')->willReturn($cipherKey); + $cipherKeyStore->expects($this->never())->method('store')->with('foo', $this->isInstanceOf(CipherKey::class)); - $cipherKeyFactory = $this->prophesize(CipherKeyFactory::class); - $cipherKeyFactory->__invoke()->shouldNotBeCalled(); + $cipherKeyFactory = $this->createMock(CipherKeyFactory::class); + $cipherKeyFactory->expects($this->never())->method('__invoke'); - $cipher = $this->prophesize(Cipher::class); - $cipher - ->decrypt($cipherKey, 'encrypted') - ->willThrow(new DecryptionFailed()) - ->shouldBeCalledOnce(); + $cipher = $this->createMock(Cipher::class); + $cipher->expects($this->once())->method('decrypt')->with($cipherKey, 'encrypted') + ->willThrowException(new DecryptionFailed()); $cryptographer = new PersonalDataPayloadCryptographer( - $cipherKeyStore->reveal(), - $cipherKeyFactory->reveal(), - $cipher->reveal(), + $cipherKeyStore, + $cipherKeyFactory, + $cipher, ); $result = $cryptographer->decrypt($this->metadata(PersonalDataProfileCreatedFallbackCallback::class), ['id' => 'foo', 'email' => 'encrypted']); @@ -261,23 +256,21 @@ public function testDecryptWithValidKey(): void 'baz', ); - $cipherKeyStore = $this->prophesize(CipherKeyStore::class); - $cipherKeyStore->get('foo')->willReturn($cipherKey); - $cipherKeyStore->store('foo', Argument::type(CipherKey::class))->shouldNotBeCalled(); + $cipherKeyStore = $this->createMock(CipherKeyStore::class); + $cipherKeyStore->method('get')->with('foo')->willReturn($cipherKey); + $cipherKeyStore->expects($this->never())->method('store')->with('foo', $this->isInstanceOf(CipherKey::class)); - $cipherKeyFactory = $this->prophesize(CipherKeyFactory::class); - $cipherKeyFactory->__invoke()->shouldNotBeCalled(); + $cipherKeyFactory = $this->createMock(CipherKeyFactory::class); + $cipherKeyFactory->expects($this->never())->method('__invoke'); - $cipher = $this->prophesize(Cipher::class); - $cipher - ->decrypt($cipherKey, 'encrypted') - ->willReturn('info@patchlevel.de') - ->shouldBeCalledOnce(); + $cipher = $this->createMock(Cipher::class); + $cipher->expects($this->once())->method('decrypt')->with($cipherKey, 'encrypted') + ->willReturn('info@patchlevel.de'); $cryptographer = new PersonalDataPayloadCryptographer( - $cipherKeyStore->reveal(), - $cipherKeyFactory->reveal(), - $cipher->reveal(), + $cipherKeyStore, + $cipherKeyFactory, + $cipher, false, ); @@ -294,23 +287,21 @@ public function testDecryptWithValidKeyAndEncryptedFieldName(): void 'baz', ); - $cipherKeyStore = $this->prophesize(CipherKeyStore::class); - $cipherKeyStore->get('foo')->willReturn($cipherKey); - $cipherKeyStore->store('foo', Argument::type(CipherKey::class))->shouldNotBeCalled(); + $cipherKeyStore = $this->createMock(CipherKeyStore::class); + $cipherKeyStore->method('get')->with('foo')->willReturn($cipherKey); + $cipherKeyStore->expects($this->never())->method('store')->with('foo', $this->isInstanceOf(CipherKey::class)); - $cipherKeyFactory = $this->prophesize(CipherKeyFactory::class); - $cipherKeyFactory->__invoke()->shouldNotBeCalled(); + $cipherKeyFactory = $this->createMock(CipherKeyFactory::class); + $cipherKeyFactory->expects($this->never())->method('__invoke'); - $cipher = $this->prophesize(Cipher::class); - $cipher - ->decrypt($cipherKey, 'encrypted') - ->willReturn('info@patchlevel.de') - ->shouldBeCalledOnce(); + $cipher = $this->createMock(Cipher::class); + $cipher->expects($this->once())->method('decrypt')->with($cipherKey, 'encrypted') + ->willReturn('info@patchlevel.de'); $cryptographer = new PersonalDataPayloadCryptographer( - $cipherKeyStore->reveal(), - $cipherKeyFactory->reveal(), - $cipher->reveal(), + $cipherKeyStore, + $cipherKeyFactory, + $cipher, true, ); @@ -327,19 +318,19 @@ public function testDecryptWithValidKeyAndEncryptedFieldNameWithoutEncryptedData 'baz', ); - $cipherKeyStore = $this->prophesize(CipherKeyStore::class); - $cipherKeyStore->get('foo')->willReturn($cipherKey); - $cipherKeyStore->store('foo', Argument::type(CipherKey::class))->shouldNotBeCalled(); + $cipherKeyStore = $this->createMock(CipherKeyStore::class); + $cipherKeyStore->method('get')->with('foo')->willReturn($cipherKey); + $cipherKeyStore->expects($this->never())->method('store')->with('foo', $this->isInstanceOf(CipherKey::class)); - $cipherKeyFactory = $this->prophesize(CipherKeyFactory::class); - $cipherKeyFactory->__invoke()->shouldNotBeCalled(); + $cipherKeyFactory = $this->createMock(CipherKeyFactory::class); + $cipherKeyFactory->expects($this->never())->method('__invoke'); - $cipher = $this->prophesize(Cipher::class); + $cipher = $this->createMock(Cipher::class); $cryptographer = new PersonalDataPayloadCryptographer( - $cipherKeyStore->reveal(), - $cipherKeyFactory->reveal(), - $cipher->reveal(), + $cipherKeyStore, + $cipherKeyFactory, + $cipher, true, ); @@ -356,23 +347,21 @@ public function testDecryptWithValidKeyAndEncryptedFieldNameAndFallbackFieldName 'baz', ); - $cipherKeyStore = $this->prophesize(CipherKeyStore::class); - $cipherKeyStore->get('foo')->willReturn($cipherKey); - $cipherKeyStore->store('foo', Argument::type(CipherKey::class))->shouldNotBeCalled(); + $cipherKeyStore = $this->createMock(CipherKeyStore::class); + $cipherKeyStore->method('get')->with('foo')->willReturn($cipherKey); + $cipherKeyStore->expects($this->never())->method('store')->with('foo', $this->isInstanceOf(CipherKey::class)); - $cipherKeyFactory = $this->prophesize(CipherKeyFactory::class); - $cipherKeyFactory->__invoke()->shouldNotBeCalled(); + $cipherKeyFactory = $this->createMock(CipherKeyFactory::class); + $cipherKeyFactory->expects($this->never())->method('__invoke'); - $cipher = $this->prophesize(Cipher::class); - $cipher - ->decrypt($cipherKey, 'encrypted') - ->willReturn('info@patchlevel.de') - ->shouldBeCalledOnce(); + $cipher = $this->createMock(Cipher::class); + $cipher->expects($this->once())->method('decrypt')->with($cipherKey, 'encrypted') + ->willReturn('info@patchlevel.de'); $cryptographer = new PersonalDataPayloadCryptographer( - $cipherKeyStore->reveal(), - $cipherKeyFactory->reveal(), - $cipher->reveal(), + $cipherKeyStore, + $cipherKeyFactory, + $cipher, true, true, ); @@ -386,14 +375,14 @@ public function testUnsupportedSubjectId(): void { $this->expectException(UnsupportedSubjectId::class); - $cipherKeyStore = $this->prophesize(CipherKeyStore::class); - $cipherKeyFactory = $this->prophesize(CipherKeyFactory::class); - $cipher = $this->prophesize(Cipher::class); + $cipherKeyStore = $this->createMock(CipherKeyStore::class); + $cipherKeyFactory = $this->createMock(CipherKeyFactory::class); + $cipher = $this->createMock(Cipher::class); $cryptographer = new PersonalDataPayloadCryptographer( - $cipherKeyStore->reveal(), - $cipherKeyFactory->reveal(), - $cipher->reveal(), + $cipherKeyStore, + $cipherKeyFactory, + $cipher, ); $cryptographer->decrypt($this->metadata(PersonalDataProfileCreated::class), ['id' => null, 'email' => 'encrypted']); @@ -403,14 +392,14 @@ public function testMissingSubjectId(): void { $this->expectException(MissingSubjectId::class); - $cipherKeyStore = $this->prophesize(CipherKeyStore::class); - $cipherKeyFactory = $this->prophesize(CipherKeyFactory::class); - $cipher = $this->prophesize(Cipher::class); + $cipherKeyStore = $this->createMock(CipherKeyStore::class); + $cipherKeyFactory = $this->createMock(CipherKeyFactory::class); + $cipher = $this->createMock(Cipher::class); $cryptographer = new PersonalDataPayloadCryptographer( - $cipherKeyStore->reveal(), - $cipherKeyFactory->reveal(), - $cipher->reveal(), + $cipherKeyStore, + $cipherKeyFactory, + $cipher, ); $cryptographer->decrypt($this->metadata(PersonalDataProfileCreated::class), ['email' => 'encrypted']); @@ -418,10 +407,10 @@ public function testMissingSubjectId(): void public function testCreateWithOpenssl(): void { - $cipherKeyStore = $this->prophesize(CipherKeyStore::class); + $cipherKeyStore = $this->createMock(CipherKeyStore::class); $cryptographer = PersonalDataPayloadCryptographer::createWithOpenssl( - $cipherKeyStore->reveal(), + $cipherKeyStore, ); self::assertInstanceOf(PersonalDataPayloadCryptographer::class, $cryptographer); diff --git a/tests/Unit/MetadataHydratorTest.php b/tests/Unit/MetadataHydratorTest.php index 3400ad4..121468a 100644 --- a/tests/Unit/MetadataHydratorTest.php +++ b/tests/Unit/MetadataHydratorTest.php @@ -39,13 +39,10 @@ use Patchlevel\Hydrator\Tests\Unit\Fixture\WrongNormalizer; use Patchlevel\Hydrator\TypeMismatch; use PHPUnit\Framework\TestCase; -use Prophecy\PhpUnit\ProphecyTrait; use Symfony\Component\EventDispatcher\EventDispatcherInterface; final class MetadataHydratorTest extends TestCase { - use ProphecyTrait; - private MetadataHydrator $hydrator; public function setUp(): void @@ -264,13 +261,14 @@ public function testDecrypt(): void $metadataFactory = new AttributeMetadataFactory(); - $cryptographer = $this->prophesize(PayloadCryptographer::class); + $cryptographer = $this->createMock(PayloadCryptographer::class); $cryptographer - ->decrypt($metadataFactory->metadata(ProfileCreated::class), $encryptedPayload) - ->willReturn($payload) - ->shouldBeCalledOnce(); + ->expects($this->once()) + ->method('decrypt') + ->with($metadataFactory->metadata(ProfileCreated::class), $encryptedPayload) + ->willReturn($payload); - $hydrator = new MetadataHydrator($metadataFactory, $cryptographer->reveal()); + $hydrator = new MetadataHydrator($metadataFactory, $cryptographer); $return = $hydrator->hydrate(ProfileCreated::class, $encryptedPayload); @@ -289,13 +287,14 @@ public function testEncrypt(): void $metadataFactory = new AttributeMetadataFactory(); - $cryptographer = $this->prophesize(PayloadCryptographer::class); + $cryptographer = $this->createMock(PayloadCryptographer::class); $cryptographer - ->encrypt($metadataFactory->metadata(ProfileCreated::class), $payload) - ->willReturn($encryptedPayload) - ->shouldBeCalledOnce(); + ->expects($this->once()) + ->method('encrypt') + ->with($metadataFactory->metadata(ProfileCreated::class), $payload) + ->willReturn($encryptedPayload); - $hydrator = new MetadataHydrator($metadataFactory, $cryptographer->reveal()); + $hydrator = new MetadataHydrator($metadataFactory, $cryptographer); $return = $hydrator->extract($object); @@ -324,13 +323,14 @@ public function testPreHydrate(): void $metadataFactory->metadata(ProfileCreated::class), ); - $eventDispatcher = $this->prophesize(EventDispatcherInterface::class); + $eventDispatcher = $this->createMock(EventDispatcherInterface::class); $eventDispatcher - ->dispatch($event) - ->willReturn($eventReturn) - ->shouldBeCalledOnce(); + ->expects($this->once()) + ->method('dispatch') + ->with($event) + ->willReturn($eventReturn); - $hydrator = new MetadataHydrator($metadataFactory, eventDispatcher: $eventDispatcher->reveal()); + $hydrator = new MetadataHydrator($metadataFactory, eventDispatcher: $eventDispatcher); $return = $hydrator->hydrate(ProfileCreated::class, $encryptedPayload); @@ -359,13 +359,11 @@ public function testPostExtract(): void $metadataFactory->metadata(ProfileCreated::class), ); - $eventDispatcher = $this->prophesize(EventDispatcherInterface::class); - $eventDispatcher - ->dispatch($event) - ->willReturn($eventReturn) - ->shouldBeCalledOnce(); + $eventDispatcher = $this->createMock(EventDispatcherInterface::class); + $eventDispatcher->expects($this->once())->method('dispatch')->with($event) + ->willReturn($eventReturn); - $hydrator = new MetadataHydrator($metadataFactory, eventDispatcher: $eventDispatcher->reveal()); + $hydrator = new MetadataHydrator($metadataFactory, eventDispatcher: $eventDispatcher); $return = $hydrator->extract($object); diff --git a/tests/Unit/Normalizer/ArrayNormalizerTest.php b/tests/Unit/Normalizer/ArrayNormalizerTest.php index e52f9b8..b320b83 100644 --- a/tests/Unit/Normalizer/ArrayNormalizerTest.php +++ b/tests/Unit/Normalizer/ArrayNormalizerTest.php @@ -11,26 +11,23 @@ use Patchlevel\Hydrator\Normalizer\InvalidArgument; use Patchlevel\Hydrator\Normalizer\Normalizer; use PHPUnit\Framework\TestCase; -use Prophecy\PhpUnit\ProphecyTrait; #[Attribute(Attribute::TARGET_PROPERTY)] final class ArrayNormalizerTest extends TestCase { - use ProphecyTrait; - public function testNormalizeWithNull(): void { - $innerNormalizer = $this->prophesize(Normalizer::class); + $innerNormalizer = $this->createMock(Normalizer::class); - $normalizer = new ArrayNormalizer($innerNormalizer->reveal()); + $normalizer = new ArrayNormalizer($innerNormalizer); $this->assertEquals(null, $normalizer->normalize(null)); } public function testDenormalizeWithNull(): void { - $innerNormalizer = $this->prophesize(Normalizer::class); + $innerNormalizer = $this->createMock(Normalizer::class); - $normalizer = new ArrayNormalizer($innerNormalizer->reveal()); + $normalizer = new ArrayNormalizer($innerNormalizer); $this->assertEquals(null, $normalizer->denormalize(null)); } @@ -38,9 +35,9 @@ public function testNormalizeWithInvalidArgument(): void { $this->expectException(InvalidArgument::class); - $innerNormalizer = $this->prophesize(Normalizer::class); + $innerNormalizer = $this->createMock(Normalizer::class); - $normalizer = new ArrayNormalizer($innerNormalizer->reveal()); + $normalizer = new ArrayNormalizer($innerNormalizer); $normalizer->normalize('foo'); } @@ -48,9 +45,9 @@ public function testDenormalizeWithInvalidArgument(): void { $this->expectException(InvalidArgument::class); - $innerNormalizer = $this->prophesize(Normalizer::class); + $innerNormalizer = $this->createMock(Normalizer::class); - $normalizer = new ArrayNormalizer($innerNormalizer->reveal()); + $normalizer = new ArrayNormalizer($innerNormalizer); $normalizer->denormalize('foo'); } @@ -92,12 +89,11 @@ public function denormalize(mixed $value): int public function testPassHydrator(): void { - $hydrator = $this->prophesize(Hydrator::class)->reveal(); - $normalizer = $this->prophesize(Normalizer::class); - $normalizer->willImplement(HydratorAwareNormalizer::class); - $normalizer->setHydrator($hydrator)->shouldBeCalled(); + $hydrator = $this->createMock(Hydrator::class); + $normalizer = $this->createMockForIntersectionOfInterfaces([Normalizer::class, HydratorAwareNormalizer::class]); + $normalizer->expects($this->once())->method('setHydrator')->with($hydrator); - $normalizer = new ArrayNormalizer($normalizer->reveal()); + $normalizer = new ArrayNormalizer($normalizer); $normalizer->setHydrator($hydrator); } } diff --git a/tests/Unit/Normalizer/DateTimeImmutableNormalizerTest.php b/tests/Unit/Normalizer/DateTimeImmutableNormalizerTest.php index 58bd504..fb90e0f 100644 --- a/tests/Unit/Normalizer/DateTimeImmutableNormalizerTest.php +++ b/tests/Unit/Normalizer/DateTimeImmutableNormalizerTest.php @@ -10,13 +10,10 @@ use Patchlevel\Hydrator\Normalizer\DateTimeImmutableNormalizer; use Patchlevel\Hydrator\Normalizer\InvalidArgument; use PHPUnit\Framework\TestCase; -use Prophecy\PhpUnit\ProphecyTrait; #[Attribute(Attribute::TARGET_PROPERTY)] final class DateTimeImmutableNormalizerTest extends TestCase { - use ProphecyTrait; - public function testNormalizeWithNull(): void { $normalizer = new DateTimeImmutableNormalizer(); diff --git a/tests/Unit/Normalizer/DateTimeNormalizerTest.php b/tests/Unit/Normalizer/DateTimeNormalizerTest.php index b4c2505..0588ef0 100644 --- a/tests/Unit/Normalizer/DateTimeNormalizerTest.php +++ b/tests/Unit/Normalizer/DateTimeNormalizerTest.php @@ -9,13 +9,10 @@ use Patchlevel\Hydrator\Normalizer\DateTimeNormalizer; use Patchlevel\Hydrator\Normalizer\InvalidArgument; use PHPUnit\Framework\TestCase; -use Prophecy\PhpUnit\ProphecyTrait; #[Attribute(Attribute::TARGET_PROPERTY)] final class DateTimeNormalizerTest extends TestCase { - use ProphecyTrait; - public function testNormalizeWithNull(): void { $normalizer = new DateTimeNormalizer(); diff --git a/tests/Unit/Normalizer/DateTimeZoneNormalizerTest.php b/tests/Unit/Normalizer/DateTimeZoneNormalizerTest.php index f830057..0af3a8b 100644 --- a/tests/Unit/Normalizer/DateTimeZoneNormalizerTest.php +++ b/tests/Unit/Normalizer/DateTimeZoneNormalizerTest.php @@ -9,13 +9,10 @@ use Patchlevel\Hydrator\Normalizer\DateTimeZoneNormalizer; use Patchlevel\Hydrator\Normalizer\InvalidArgument; use PHPUnit\Framework\TestCase; -use Prophecy\PhpUnit\ProphecyTrait; #[Attribute(Attribute::TARGET_PROPERTY)] final class DateTimeZoneNormalizerTest extends TestCase { - use ProphecyTrait; - public function testNormalizeWithNull(): void { $normalizer = new DateTimeZoneNormalizer(); diff --git a/tests/Unit/Normalizer/EnumNormalizerTest.php b/tests/Unit/Normalizer/EnumNormalizerTest.php index 5239d33..4ac8dd7 100644 --- a/tests/Unit/Normalizer/EnumNormalizerTest.php +++ b/tests/Unit/Normalizer/EnumNormalizerTest.php @@ -12,7 +12,6 @@ use Patchlevel\Hydrator\Tests\Unit\Fixture\AutoTypeDto; use Patchlevel\Hydrator\Tests\Unit\Fixture\Status; use PHPUnit\Framework\TestCase; -use Prophecy\PhpUnit\ProphecyTrait; use ReflectionClass; use ReflectionType; use RuntimeException; @@ -20,8 +19,6 @@ #[Attribute(Attribute::TARGET_PROPERTY)] final class EnumNormalizerTest extends TestCase { - use ProphecyTrait; - public function testNormalizeWithNull(): void { $normalizer = new EnumNormalizer(Status::class); diff --git a/tests/Unit/Normalizer/ObjectNormalizerTest.php b/tests/Unit/Normalizer/ObjectNormalizerTest.php index b3dc816..9a9a644 100644 --- a/tests/Unit/Normalizer/ObjectNormalizerTest.php +++ b/tests/Unit/Normalizer/ObjectNormalizerTest.php @@ -15,7 +15,6 @@ use Patchlevel\Hydrator\Tests\Unit\Fixture\ProfileCreated; use Patchlevel\Hydrator\Tests\Unit\Fixture\ProfileId; use PHPUnit\Framework\TestCase; -use Prophecy\PhpUnit\ProphecyTrait; use ReflectionClass; use ReflectionType; use RuntimeException; @@ -26,8 +25,6 @@ #[Attribute(Attribute::TARGET_PROPERTY)] final class ObjectNormalizerTest extends TestCase { - use ProphecyTrait; - public function testNormalizeMissingHydrator(): void { $this->expectException(MissingHydrator::class); @@ -46,20 +43,20 @@ public function testDenormalizeMissingHydrator(): void public function testNormalizeWithNull(): void { - $hydrator = $this->prophesize(Hydrator::class); + $hydrator = $this->createMock(Hydrator::class); $normalizer = new ObjectNormalizer(ProfileCreated::class); - $normalizer->setHydrator($hydrator->reveal()); + $normalizer->setHydrator($hydrator); $this->assertEquals(null, $normalizer->normalize(null)); } public function testDenormalizeWithNull(): void { - $hydrator = $this->prophesize(Hydrator::class); + $hydrator = $this->createMock(Hydrator::class); $normalizer = new ObjectNormalizer(ProfileCreated::class); - $normalizer->setHydrator($hydrator->reveal()); + $normalizer->setHydrator($hydrator); $this->assertEquals(null, $normalizer->denormalize(null)); } @@ -69,10 +66,10 @@ public function testNormalizeWithInvalidArgument(): void $this->expectException(InvalidArgument::class); $this->expectExceptionMessage('type "Patchlevel\Hydrator\Tests\Unit\Fixture\ProfileCreated|null" was expected but "string" was passed.'); - $hydrator = $this->prophesize(Hydrator::class); + $hydrator = $this->createMock(Hydrator::class); $normalizer = new ObjectNormalizer(ProfileCreated::class); - $normalizer->setHydrator($hydrator->reveal()); + $normalizer->setHydrator($hydrator); $normalizer->normalize('foo'); } @@ -81,28 +78,27 @@ public function testDenormalizeWithInvalidArgument(): void $this->expectException(InvalidArgument::class); $this->expectExceptionMessage('array|null" was expected but "string" was passed.'); - $hydrator = $this->prophesize(Hydrator::class); + $hydrator = $this->createMock(Hydrator::class); $normalizer = new ObjectNormalizer(ProfileCreated::class); - $normalizer->setHydrator($hydrator->reveal()); + $normalizer->setHydrator($hydrator); $normalizer->denormalize('foo'); } public function testNormalizeWithValue(): void { - $hydrator = $this->prophesize(Hydrator::class); + $hydrator = $this->createMock(Hydrator::class); $event = new ProfileCreated( ProfileId::fromString('1'), Email::fromString('info@patchlevel.de'), ); - $hydrator->extract($event) - ->willReturn(['profileId' => '1', 'email' => 'info@patchlevel.de']) - ->shouldBeCalledOnce(); + $hydrator->expects($this->once())->method('extract')->with($event) + ->willReturn(['profileId' => '1', 'email' => 'info@patchlevel.de']); $normalizer = new ObjectNormalizer(ProfileCreated::class); - $normalizer->setHydrator($hydrator->reveal()); + $normalizer->setHydrator($hydrator); self::assertEquals( $normalizer->normalize($event), @@ -112,19 +108,18 @@ public function testNormalizeWithValue(): void public function testDenormalizeWithValue(): void { - $hydrator = $this->prophesize(Hydrator::class); + $hydrator = $this->createMock(Hydrator::class); $expected = new ProfileCreated( ProfileId::fromString('1'), Email::fromString('info@patchlevel.de'), ); - $hydrator->hydrate(ProfileCreated::class, ['profileId' => '1', 'email' => 'info@patchlevel.de']) - ->willReturn($expected) - ->shouldBeCalledOnce(); + $hydrator->expects($this->once())->method('hydrate')->with(ProfileCreated::class, ['profileId' => '1', 'email' => 'info@patchlevel.de']) + ->willReturn($expected); $normalizer = new ObjectNormalizer(ProfileCreated::class); - $normalizer->setHydrator($hydrator->reveal()); + $normalizer->setHydrator($hydrator); $this->assertEquals( $expected, @@ -134,10 +129,10 @@ public function testDenormalizeWithValue(): void public function testAutoDetect(): void { - $hydrator = $this->prophesize(Hydrator::class); + $hydrator = $this->createMock(Hydrator::class); $normalizer = new ObjectNormalizer(); - $normalizer->setHydrator($hydrator->reveal()); + $normalizer->setHydrator($hydrator); $normalizer->handleReflectionType($this->reflectionType(AutoTypeDto::class, 'profileCreated')); self::assertEquals(ProfileCreated::class, $normalizer->getClassName()); @@ -145,10 +140,10 @@ public function testAutoDetect(): void public function testAutoDetectOverrideNotPossible(): void { - $hydrator = $this->prophesize(Hydrator::class); + $hydrator = $this->createMock(Hydrator::class); $normalizer = new ObjectNormalizer(AutoTypeDto::class); - $normalizer->setHydrator($hydrator->reveal()); + $normalizer->setHydrator($hydrator); $normalizer->handleReflectionType($this->reflectionType(AutoTypeDto::class, 'profileCreated')); self::assertEquals(AutoTypeDto::class, $normalizer->getClassName()); @@ -158,10 +153,10 @@ public function testAutoDetectMissingType(): void { $this->expectException(InvalidType::class); - $hydrator = $this->prophesize(Hydrator::class); + $hydrator = $this->createMock(Hydrator::class); $normalizer = new ObjectNormalizer(); - $normalizer->setHydrator($hydrator->reveal()); + $normalizer->setHydrator($hydrator); $normalizer->getClassName(); } @@ -170,10 +165,10 @@ public function testAutoDetectMissingTypeBecauseNull(): void { $this->expectException(InvalidType::class); - $hydrator = $this->prophesize(Hydrator::class); + $hydrator = $this->createMock(Hydrator::class); $normalizer = new ObjectNormalizer(); - $normalizer->setHydrator($hydrator->reveal()); + $normalizer->setHydrator($hydrator); $normalizer->handleReflectionType(null); $normalizer->getClassName(); @@ -181,10 +176,10 @@ public function testAutoDetectMissingTypeBecauseNull(): void public function testSerialize(): void { - $hydrator = $this->prophesize(Hydrator::class); + $hydrator = $this->createMock(Hydrator::class); $normalizer = new ObjectNormalizer(ProfileCreated::class); - $normalizer->setHydrator($hydrator->reveal()); + $normalizer->setHydrator($hydrator); $serialized = serialize($normalizer);