diff --git a/.scrutinizer.yml b/.scrutinizer.yml index 9a9bb96..328415c 100644 --- a/.scrutinizer.yml +++ b/.scrutinizer.yml @@ -1,13 +1,24 @@ # language: php +build: + dependencies: + before: + - 'composer self-update' + - 'composer update --prefer-stable --prefer-source --no-interaction --no-progress --no-suggest' + cache: + directories: + - vendor/ + nodes: + analysis: + project_setup: + override: true + tests: + override: [php-scrutinizer-run] + filter: paths: [src/*] excluded_paths: [tests/*, vendor/*] -before_commands: - - 'composer self-update' - - 'composer update --prefer-stable --prefer-source --no-interaction --no-scripts --no-progress --no-suggest' - coding_style: php: upper_lower_casing: @@ -17,8 +28,8 @@ coding_style: true_false_null: lower spaces: around_operators: - concatenation: true - negation: false + concatenation: true + negation: false other: after_type_cast: true @@ -34,7 +45,6 @@ tools: enabled: true config: ruleset: 'unusedcode,naming,design,controversial,codesize' - php_cpd: true php_loc: true php_pdepend: true diff --git a/.travis.yml b/.travis.yml index edd3ab5..b834abe 100644 --- a/.travis.yml +++ b/.travis.yml @@ -13,7 +13,9 @@ env: - COMPOSER_FLAGS="--prefer-stable --prefer-dist" php: + - 7.2 - 7.3 + - 7.4snapshot - nightly matrix: @@ -22,7 +24,7 @@ matrix: - php: 7.1 env: - COMPOSER_FLAGS="--prefer-lowest --prefer-stable --prefer-dist" - - php: 7.2 + - php: 7.1 env: - TEST_VERSION=true - COMPOSER_FLAGS="--prefer-stable --prefer-dist" @@ -30,17 +32,17 @@ matrix: - php: nightly before_install: - - if [[ -z $TEST_VERSION && -f "/home/travis/.phpenv/versions/$(phpenv version-name)/etc/conf.d/xdebug.ini" ]]; then phpenv config-rm xdebug.ini; fi - - composer global require hirak/prestissimo - - composer self-update --stable --no-progress + - if [[ -z $TEST_VERSION && -f "/home/travis/.phpenv/versions/$(phpenv version-name)/etc/conf.d/xdebug.ini" ]]; then phpenv config-rm xdebug.ini; fi + - composer global require hirak/prestissimo + - composer self-update --stable --no-progress install: - - travis_retry composer update $COMPOSER_FLAGS --no-interaction --no-scripts --no-progress - - if [[ $TEST_VERSION ]]; then travis_retry composer require php-coveralls/php-coveralls $COMPOSER_FLAGS --no-interaction --no-scripts --no-progress ; fi + - travis_retry composer update $COMPOSER_FLAGS --no-interaction --no-progress + - if [[ $TEST_VERSION ]]; then travis_retry composer require php-coveralls/php-coveralls $COMPOSER_FLAGS --no-interaction --no-scripts --no-progress ; fi script: - - if [[ $TEST_VERSION ]]; then composer qa && composer report-phpunit-clover ; fi - - if [[ -z $TEST_VERSION ]]; then composer test-phpunit ; fi + - if [[ $TEST_VERSION ]]; then composer qa && composer report-phpunit-clover ; fi + - if [[ -z $TEST_VERSION ]]; then composer test-phpunit ; fi after_script: - - if [[ $TEST_VERSION ]]; then travis_retry php vendor/bin/php-coveralls --verbose ; fi + - if [[ $TEST_VERSION ]]; then travis_retry php vendor/bin/php-coveralls --verbose ; fi diff --git a/composer.json b/composer.json index 7bdcd77..a70b8c7 100644 --- a/composer.json +++ b/composer.json @@ -26,22 +26,23 @@ "require": { "php": "^7.1", "ext-json": "*", - "phpgears/event": "~0.1.3" + "phpgears/event": "~0.3" }, "require-dev": { "brainmaestro/composer-git-hooks": "^2.1", "friendsofphp/php-cs-fixer": "^2.0", "infection/infection": "^0.9", "phpmd/phpmd": "^2.0", - "phpstan/phpstan": "^0.10", - "phpstan/phpstan-deprecation-rules": "^0.10", - "phpstan/phpstan-strict-rules": "^0.10", - "phpunit/phpunit": "^6.0|^7.0", + "phpstan/extension-installer": "^1.0", + "phpstan/phpstan": "~0.11.12", + "phpstan/phpstan-deprecation-rules": "~0.11.2", + "phpstan/phpstan-strict-rules": "~0.11.1", + "phpunit/phpunit": "^7.0|^8.0", "povils/phpmnd": "^2.0", "roave/security-advisories": "dev-master", - "sebastian/phpcpd": "^3.0|^4.0", - "squizlabs/php_codesniffer": "^2.0", - "thecodingmachine/phpstan-strict-rules": "^0.10.1" + "sebastian/phpcpd": "^4.0", + "squizlabs/php_codesniffer": "^3.0", + "thecodingmachine/phpstan-strict-rules": "~0.11.2" }, "suggest": { }, diff --git a/phpstan.neon b/phpstan.neon index 02c72a4..a1c637a 100644 --- a/phpstan.neon +++ b/phpstan.neon @@ -1,8 +1,3 @@ -includes: - - vendor/phpstan/phpstan-strict-rules/rules.neon - - vendor/phpstan/phpstan-deprecation-rules/rules.neon - - vendor/thecodingmachine/phpstan-strict-rules/phpstan-strict-rules.neon - parameters: level: max paths: diff --git a/src/ReceivedEvent.php b/src/ReceivedEvent.php index 26d60fd..0ad9827 100644 --- a/src/ReceivedEvent.php +++ b/src/ReceivedEvent.php @@ -96,7 +96,7 @@ public function getMetadata(): array * * @return array */ - public function withMetadata(array $metadata) + public function withAddedMetadata(array $metadata) { throw new ReceivedEventException(\sprintf('Method %s should not be called ', __METHOD__)); } @@ -116,7 +116,7 @@ public function getCreatedAt(): \DateTimeImmutable * * @throws ReceivedEventException */ - public static function reconstitute(array $payload, array $attributes = []): void + public static function reconstitute(array $payload, \DateTimeImmutable $createdAt, array $attributes = []): void { throw new ReceivedEventException(\sprintf('Method %s should not be called ', __METHOD__)); } diff --git a/src/Serializer/JsonEventSerializer.php b/src/Serializer/JsonEventSerializer.php index 69b1d6d..febee9c 100644 --- a/src/Serializer/JsonEventSerializer.php +++ b/src/Serializer/JsonEventSerializer.php @@ -52,6 +52,7 @@ final public function serialize(Event $event): string [ 'class' => \get_class($event), 'payload' => $event->getPayload(), + 'createdAt' => $event->getCreatedAt()->format(self::DATE_RFC3339_EXTENDED), 'attributes' => $this->getSerializationAttributes($event), ], static::JSON_ENCODE_OPTIONS @@ -81,7 +82,6 @@ protected function getSerializationAttributes(Event $event): array { return [ 'metadata' => $event->getMetadata(), - 'createdAt' => $event->getCreatedAt()->format(self::DATE_RFC3339_EXTENDED), ]; } @@ -90,7 +90,7 @@ protected function getSerializationAttributes(Event $event): array */ final public function fromSerialized(string $serialized): Event { - ['class' => $eventClass, 'payload' => $payload, 'attributes' => $attributes] = + ['class' => $eventClass, 'payload' => $payload, 'createdAt' => $createdAt, 'attributes' => $attributes] = $this->getEventDefinition($serialized); if (!\class_exists($eventClass)) { @@ -105,10 +105,12 @@ final public function fromSerialized(string $serialized): Event )); } + $createdAt = \DateTimeImmutable::createFromFormat(self::DATE_RFC3339_EXTENDED, $createdAt); + // @codeCoverageIgnoreStart try { /* @var Event $eventClass */ - return $eventClass::reconstitute($payload, $this->getDeserializationAttributes($attributes)); + return $eventClass::reconstitute($payload, $createdAt, $this->getDeserializationAttributes($attributes)); } catch (\Exception $exception) { throw new EventSerializationException('Error reconstituting event', 0, $exception); } @@ -128,10 +130,11 @@ private function getEventDefinition(string $serialized): array { $definition = $this->getDeserializationDefinition($serialized); - if (!isset($definition['class'], $definition['payload'], $definition['attributes']) - || \count(\array_diff(\array_keys($definition), ['class', 'payload', 'attributes'])) !== 0 + if (!isset($definition['class'], $definition['payload'], $definition['createdAt'], $definition['attributes']) + || \count(\array_diff(\array_keys($definition), ['class', 'payload', 'createdAt', 'attributes'])) !== 0 || !\is_string($definition['class']) || !\is_array($definition['payload']) + || !\is_string($definition['createdAt']) || !\is_array($definition['attributes']) ) { throw new EventSerializationException('Malformed JSON serialized event'); @@ -179,7 +182,6 @@ protected function getDeserializationAttributes(array $attributes): array { return [ 'metadata' => $attributes['metadata'], - 'createdAt' => \DateTimeImmutable::createFromFormat(self::DATE_RFC3339_EXTENDED, $attributes['createdAt']), ]; } } diff --git a/tests/Async/AbstractEventQueueTest.php b/tests/Async/AbstractEventQueueTest.php index bac6f77..d56e0e6 100644 --- a/tests/Async/AbstractEventQueueTest.php +++ b/tests/Async/AbstractEventQueueTest.php @@ -24,7 +24,7 @@ public function testSerialization(): void { $serializer = $this->getMockBuilder(EventSerializer::class) ->getMock(); - $serializer->expects($this->once()) + $serializer->expects(static::once()) ->method('serialize'); /* @var EventSerializer $serializer */ diff --git a/tests/Async/AsyncEventBusTest.php b/tests/Async/AsyncEventBusTest.php index 4bd3bd1..40d97d0 100644 --- a/tests/Async/AsyncEventBusTest.php +++ b/tests/Async/AsyncEventBusTest.php @@ -28,12 +28,12 @@ public function testShouldEnqueue(): void { $busMock = $this->getMockBuilder(EventBus::class) ->getMock(); - $busMock->expects($this->once()) + $busMock->expects(static::once()) ->method('dispatch'); /** @var EventBus $busMock */ $queueMock = $this->getMockBuilder(EventQueue::class) ->getMock(); - $queueMock->expects($this->once()) + $queueMock->expects(static::once()) ->method('send'); /** @var EventQueue $queueMock */ $discriminatorMock = new class() implements EventDiscriminator { @@ -50,12 +50,12 @@ public function testShouldNotEnqueue(): void { $busMock = $this->getMockBuilder(EventBus::class) ->getMock(); - $busMock->expects($this->once()) + $busMock->expects(static::once()) ->method('dispatch'); /** @var EventBus $busMock */ $queueMock = $this->getMockBuilder(EventQueue::class) ->getMock(); - $queueMock->expects($this->never()) + $queueMock->expects(static::never()) ->method('send'); /** @var EventQueue $queueMock */ $discriminatorMock = new class() implements EventDiscriminator { @@ -72,12 +72,12 @@ public function testReceivedEvent(): void { $busMock = $this->getMockBuilder(EventBus::class) ->getMock(); - $busMock->expects($this->once()) + $busMock->expects(static::once()) ->method('dispatch'); /** @var EventBus $busMock */ $queueMock = $this->getMockBuilder(EventQueue::class) ->getMock(); - $queueMock->expects($this->never()) + $queueMock->expects(static::never()) ->method('send'); /** @var EventQueue $queueMock */ $discriminatorMock = new class() implements EventDiscriminator { diff --git a/tests/Async/Discriminator/ArrayEventDiscriminatorTest.php b/tests/Async/Discriminator/ArrayEventDiscriminatorTest.php index db024f4..08be2ea 100644 --- a/tests/Async/Discriminator/ArrayEventDiscriminatorTest.php +++ b/tests/Async/Discriminator/ArrayEventDiscriminatorTest.php @@ -11,7 +11,7 @@ declare(strict_types=1); -namespace Gears\Event\Async\Tests; +namespace Gears\Event\Async\Tests\Discriminator; use Gears\Event\Async\Discriminator\ArrayEventDiscriminator; use Gears\Event\Async\Tests\Stub\EventStub; @@ -30,7 +30,7 @@ public function testDiscriminate(): void /** @var \Gears\Event\Event $eventMock */ $discriminator = new ArrayEventDiscriminator([\get_class($eventMock)]); - $this->assertTrue($discriminator->shouldEnqueue($eventMock)); - $this->assertFalse($discriminator->shouldEnqueue(EventStub::instance())); + static::assertTrue($discriminator->shouldEnqueue($eventMock)); + static::assertFalse($discriminator->shouldEnqueue(EventStub::instance())); } } diff --git a/tests/Async/Discriminator/ClassEventDiscriminatorTest.php b/tests/Async/Discriminator/ClassEventDiscriminatorTest.php index 6970e22..c1283f8 100644 --- a/tests/Async/Discriminator/ClassEventDiscriminatorTest.php +++ b/tests/Async/Discriminator/ClassEventDiscriminatorTest.php @@ -11,7 +11,7 @@ declare(strict_types=1); -namespace Gears\Event\Async\Tests; +namespace Gears\Event\Async\Tests\Discriminator; use Gears\Event\Async\Discriminator\ClassEventDiscriminator; use Gears\Event\Async\Tests\Stub\EventStub; @@ -30,7 +30,7 @@ public function testDiscriminate(): void /** @var \Gears\Event\Event $eventMock */ $discriminator = new ClassEventDiscriminator(\get_class($eventMock)); - $this->assertTrue($discriminator->shouldEnqueue($eventMock)); - $this->assertFalse($discriminator->shouldEnqueue(EventStub::instance())); + static::assertTrue($discriminator->shouldEnqueue($eventMock)); + static::assertFalse($discriminator->shouldEnqueue(EventStub::instance())); } } diff --git a/tests/Async/Discriminator/ParameterEventDiscriminatorTest.php b/tests/Async/Discriminator/ParameterEventDiscriminatorTest.php index 27933fc..6cb941c 100644 --- a/tests/Async/Discriminator/ParameterEventDiscriminatorTest.php +++ b/tests/Async/Discriminator/ParameterEventDiscriminatorTest.php @@ -11,7 +11,7 @@ declare(strict_types=1); -namespace Gears\Event\Async\Tests; +namespace Gears\Event\Async\Tests\Discriminator; use Gears\Event\Async\Discriminator\ParameterEventDiscriminator; use Gears\Event\Async\Tests\Stub\EventStub; @@ -26,15 +26,15 @@ public function testDiscriminateParameter(): void { $discriminator = new ParameterEventDiscriminator('identifier'); - $this->assertTrue($discriminator->shouldEnqueue(EventStub::instance(['identifier' => null]))); - $this->assertFalse($discriminator->shouldEnqueue(EventStub::instance([]))); + static::assertTrue($discriminator->shouldEnqueue(EventStub::instance(['identifier' => null]))); + static::assertFalse($discriminator->shouldEnqueue(EventStub::instance([]))); } public function testDiscriminateParameterValue(): void { $discriminator = new ParameterEventDiscriminator('identifier', '1234'); - $this->assertTrue($discriminator->shouldEnqueue(EventStub::instance(['identifier' => '1234']))); - $this->assertFalse($discriminator->shouldEnqueue(EventStub::instance(['identifier' => true]))); + static::assertTrue($discriminator->shouldEnqueue(EventStub::instance(['identifier' => '1234']))); + static::assertFalse($discriminator->shouldEnqueue(EventStub::instance(['identifier' => true]))); } } diff --git a/tests/Async/ReceivedEventTest.php b/tests/Async/ReceivedEventTest.php index e08ce08..2eb0ec0 100644 --- a/tests/Async/ReceivedEventTest.php +++ b/tests/Async/ReceivedEventTest.php @@ -13,6 +13,7 @@ namespace Gears\Event\Async\Tests; +use Gears\Event\Async\Exception\ReceivedEventException; use Gears\Event\Async\ReceivedEvent; use Gears\Event\Async\Tests\Stub\EventStub; use PHPUnit\Framework\TestCase; @@ -21,73 +22,66 @@ class ReceivedEventTest extends TestCase { public function testOriginalEvent(): void { - $originalEvent = EventStub::instance([]); + $originalEvent = EventStub::instance(); $event = new ReceivedEvent($originalEvent); - $this->assertSame($originalEvent, $event->getOriginalEvent()); + static::assertSame($originalEvent, $event->getOriginalEvent()); } - /** - * @expectedException \Gears\Event\Async\Exception\ReceivedEventException - * @expectedExceptionMessage Method Gears\Event\Async\ReceivedEvent::has should not be called - */ public function testHasException(): void { - (new ReceivedEvent(EventStub::instance([])))->has(''); + $this->expectException(ReceivedEventException::class); + $this->expectExceptionMessage('Method Gears\Event\Async\ReceivedEvent::has should not be called'); + + (new ReceivedEvent(EventStub::instance()))->has(''); } - /** - * @expectedException \Gears\Event\Async\Exception\ReceivedEventException - * @expectedExceptionMessage Method Gears\Event\Async\ReceivedEvent::get should not be called - */ public function testGetException(): void { - (new ReceivedEvent(EventStub::instance([])))->get(''); + $this->expectException(ReceivedEventException::class); + $this->expectExceptionMessage('Method Gears\Event\Async\ReceivedEvent::get should not be called'); + + (new ReceivedEvent(EventStub::instance()))->get(''); } - /** - * @expectedException \Gears\Event\Async\Exception\ReceivedEventException - * @expectedExceptionMessage Method Gears\Event\Async\ReceivedEvent::getPayload should not be called - */ public function testGetPayloadException(): void { - (new ReceivedEvent(EventStub::instance([])))->getPayload(); + $this->expectException(ReceivedEventException::class); + $this->expectExceptionMessage('Method Gears\Event\Async\ReceivedEvent::getPayload should not be called'); + + (new ReceivedEvent(EventStub::instance()))->getPayload(); } - /** - * @expectedException \Gears\Event\Async\Exception\ReceivedEventException - * @expectedExceptionMessage Method Gears\Event\Async\ReceivedEvent::getMetadata should not be called - */ public function testGetMetadataException(): void { - (new ReceivedEvent(EventStub::instance([])))->getMetadata(); + $this->expectException(ReceivedEventException::class); + $this->expectExceptionMessage('Method Gears\Event\Async\ReceivedEvent::getMetadata should not be called'); + + (new ReceivedEvent(EventStub::instance()))->getMetadata(); } - /** - * @expectedException \Gears\Event\Async\Exception\ReceivedEventException - * @expectedExceptionMessage Method Gears\Event\Async\ReceivedEvent::withMetadata should not be called - */ public function testGetMetadataMutateException(): void { - (new ReceivedEvent(EventStub::instance([])))->withMetadata([]); + $this->expectException(ReceivedEventException::class); + $this->expectExceptionMessage('Method Gears\Event\Async\ReceivedEvent::withAddedMetadata should not be called'); + + (new ReceivedEvent(EventStub::instance()))->withAddedMetadata([]); } - /** - * @expectedException \Gears\Event\Async\Exception\ReceivedEventException - * @expectedExceptionMessage Method Gears\Event\Async\ReceivedEvent::getCreatedAt should not be called - */ public function testGetCreatedAtException(): void { - (new ReceivedEvent(EventStub::instance([])))->getCreatedAt(); + $this->expectException(ReceivedEventException::class); + $this->expectExceptionMessage('Method Gears\Event\Async\ReceivedEvent::getCreatedAt should not be called'); + + (new ReceivedEvent(EventStub::instance()))->getCreatedAt(); } - /** - * @expectedException \Gears\Event\Async\Exception\ReceivedEventException - * @expectedExceptionMessage Method Gears\Event\Async\ReceivedEvent::reconstitute should not be called - */ public function testReconstituteException(): void { - ReceivedEvent::reconstitute([]); + $this->expectException(ReceivedEventException::class); + $this->expectExceptionMessage('Method Gears\Event\Async\ReceivedEvent::reconstitute should not be called'); + + ReceivedEvent::reconstitute([], new \DateTimeImmutable('now')); } } diff --git a/tests/Async/Serializer/JsonEventSerializerTest.php b/tests/Async/Serializer/JsonEventSerializerTest.php index 656e64e..57fe796 100644 --- a/tests/Async/Serializer/JsonEventSerializerTest.php +++ b/tests/Async/Serializer/JsonEventSerializerTest.php @@ -11,8 +11,9 @@ declare(strict_types=1); -namespace Gears\Event\Async\Tests; +namespace Gears\Event\Async\Tests\Serializer; +use Gears\Event\Async\Serializer\Exception\EventSerializationException; use Gears\Event\Async\Serializer\JsonEventSerializer; use Gears\Event\Async\Tests\Stub\EventStub; use PHPUnit\Framework\TestCase; @@ -28,73 +29,69 @@ public function testSerialize(): void $serialized = (new JsonEventSerializer())->serialize($event); - $this->assertContains('"payload":{"identifier":"1234"}', $serialized); + static::assertContains('"payload":{"identifier":"1234"}', $serialized); } public function testDeserialize(): void { $event = EventStub::instance(['identifier' => '1234']); - $event = $event->withMetadata(['meta' => 'data']); + $event = $event->withAddedMetadata(['meta' => 'data']); $eventDate = $event->getCreatedAt()->format('Y-m-d\TH:i:s.uP'); $serialized = '{"class":"Gears\\\\Event\\\\Async\\\\Tests\\\\Stub\\\\EventStub",' . '"payload":{"identifier":"1234"},' - . '"attributes":{"metadata":{"meta":"data"},"createdAt":"' . $eventDate . '"}}'; + . '"createdAt":"' . $eventDate . '",' + . '"attributes":{"metadata":{"meta":"data"}}}'; $deserialized = (new JsonEventSerializer())->fromSerialized($serialized); - $this->assertEquals($event, $deserialized); + static::assertEquals($event, $deserialized); } - /** - * @expectedException \Gears\Event\Async\Serializer\Exception\EventSerializationException - * @expectedExceptionMessage Malformed JSON serialized event: empty string - */ public function testEmptyDeserialization(): void { + $this->expectException(EventSerializationException::class); + $this->expectExceptionMessage('Malformed JSON serialized event: empty string'); + (new JsonEventSerializer())->fromSerialized(' '); } - /** - * @expectedException \Gears\Event\Async\Serializer\Exception\EventSerializationException - * @expectedExceptionMessage Malformed JSON serialized event - */ public function testMissingPartsDeserialization(): void { + $this->expectException(EventSerializationException::class); + $this->expectExceptionMessage('Malformed JSON serialized event'); + (new JsonEventSerializer()) ->fromSerialized('{"class":"Gears\\\\Event\\\\Async\\\\Tests\\\\Stub\\\\EventStub"}'); } - /** - * @expectedException \Gears\Event\Async\Serializer\Exception\EventSerializationException - * @expectedExceptionMessage Malformed JSON serialized event - */ public function testWrongTypeDeserialization(): void { + $this->expectException(EventSerializationException::class); + $this->expectExceptionMessage('Malformed JSON serialized event'); + (new JsonEventSerializer()) ->fromSerialized('{"class":"Gears\\\\Event\\\\Async\\\\Tests\\\\Stub\\\\EventStub",' - . '"payload":"1234","attributes":{"createdAt":"2018-01-01T00:00:00.000000+00:00"}}'); + . '"payload":"1234","createdAt":"2018-01-01T00:00:00.000000+00:00","attributes":{}}'); } - /** - * @expectedException \Gears\Event\Async\Serializer\Exception\EventSerializationException - * @expectedExceptionMessage Event class Gears\Unknown cannot be found - */ public function testMissingClassDeserialization(): void { + $this->expectException(EventSerializationException::class); + $this->expectExceptionMessage('Event class Gears\Unknown cannot be found'); + (new JsonEventSerializer()) ->fromSerialized('{"class":"Gears\\\\Unknown",' - . '"payload":{"identifier":"1234"},"attributes":{"createdAt":"2018-01-01T00:00:00.000000+00:00"}}'); + . '"payload":{"identifier":"1234"},"createdAt":"2018-01-01T00:00:00.000000+00:00","attributes":{}}'); } - /** - * @expectedException \Gears\Event\Async\Serializer\Exception\EventSerializationException - * @expectedExceptionMessageRegExp /^Event class must implement .+\\Event, .+\\JsonEventSerializer given$/ - */ public function testWrongClassTypeDeserialization(): void { + $this->expectException(EventSerializationException::class); + $this->expectExceptionMessageRegExp('/^Event class must implement .+\\Event, .+\\JsonEventSerializer given$/'); + (new JsonEventSerializer()) ->fromSerialized('{"class":"Gears\\\\Event\\\\Async\\\\Serializer\\\\JsonEventSerializer",' - . '"payload":{"identifier":"1234"},"attributes":{"createdAt":"2018-01-01T00:00:00.000000+00:00"}}'); + . '"payload":{"identifier":"1234"},"createdAt":"2018-01-01T00:00:00.000000+00:00","attributes":{}}'); } } diff --git a/tests/Async/Serializer/NativeEventSerializerTest.php b/tests/Async/Serializer/NativeEventSerializerTest.php index 8694eaa..c0c7b5c 100644 --- a/tests/Async/Serializer/NativeEventSerializerTest.php +++ b/tests/Async/Serializer/NativeEventSerializerTest.php @@ -11,8 +11,9 @@ declare(strict_types=1); -namespace Gears\Event\Async\Tests; +namespace Gears\Event\Async\Tests\Serializer; +use Gears\Event\Async\Serializer\Exception\EventSerializationException; use Gears\Event\Async\Serializer\NativeEventSerializer; use Gears\Event\Async\Tests\Stub\EventStub; use PHPUnit\Framework\TestCase; @@ -28,25 +29,24 @@ public function testSerialize(): void $serialized = (new NativeEventSerializer())->serialize($event); - $this->assertContains('a:1:{s:10:"identifier";s:4:"1234";}', $serialized); + static::assertContains('a:1:{s:10:"identifier";s:4:"1234";}', $serialized); } public function testDeserialize(): void { $event = EventStub::instance(['identifier' => '1234']); - $event = $event->withMetadata(['meta' => 'data']); + $event = $event->withAddedMetadata(['meta' => 'data']); $deserialized = (new NativeEventSerializer())->fromSerialized(\serialize($event)); - $this->assertEquals($event, $deserialized); + static::assertEquals($event, $deserialized); } - /** - * @expectedException \Gears\Event\Async\Serializer\Exception\EventSerializationException - * @expectedExceptionMessage Invalid unserialized event - */ public function testInvalidDeserialization(): void { + $this->expectException(EventSerializationException::class); + $this->expectExceptionMessage('Invalid unserialized event'); + (new NativeEventSerializer())->fromSerialized(\serialize(new \stdClass())); } }