Skip to content

Commit

Permalink
Add assertions for phpstan
Browse files Browse the repository at this point in the history
  • Loading branch information
simensen committed Sep 15, 2023
1 parent 3e00f19 commit ee498ef
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 4 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/phpstan.yml
Original file line number Diff line number Diff line change
Expand Up @@ -36,5 +36,5 @@ jobs:
with:
composer-options: "--no-progress --prefer-dist --optimize-autoloader"

- name: Larastan
- name: PHPStan
run: php ./vendor/bin/phpstan analyse --memory-limit=2G --error-format=github
2 changes: 2 additions & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@
}
},
"scripts": {
"lint": "@phpstan",
"phpstan": "@php ./vendor/bin/phpstan analyze",
"style:check": "@php ./vendor/bin/php-cs-fixer fix --dry-run",
"style:fix": "@php ./vendor/bin/php-cs-fixer fix"
}
Expand Down
16 changes: 13 additions & 3 deletions src/Testing/GivenWhenThen/Scenario.php
Original file line number Diff line number Diff line change
Expand Up @@ -272,12 +272,22 @@ public function usingMessageRepository(InMemoryMessageRepository $messageReposit

public function assertObjectSurvivesSerializationRoundTrip(mixed $input): void
{
$payloadSerializer = $this->payloadSerializer ?? DefaultPayloadSerializer::resolve();
if (!isset($this->payloadSerializer)) {
$this->payloadSerializer = DefaultPayloadSerializer::resolve();
}

assert(is_object($input), 'Input must be an object.');

$serializedPayload = $payloadSerializer->serializePayload($input);
$serializedPayload = $this->payloadSerializer->serializePayload($input);
$jsonEncodedSerializedPayload = json_encode($serializedPayload);

assert(is_string($jsonEncodedSerializedPayload), 'JSON encoding failed.');

$jsonDecodedSerializedPayload = json_decode($jsonEncodedSerializedPayload, true);
$unserializedPayload = $payloadSerializer->unserializePayload(get_class($input), $jsonDecodedSerializedPayload);

assert(is_array($jsonDecodedSerializedPayload), 'JSON decoding failed.');

$unserializedPayload = $this->payloadSerializer->unserializePayload(get_class($input), $jsonDecodedSerializedPayload);

Assert::assertEquals($input, $unserializedPayload, 'Payload serialization failed round trip.');
}
Expand Down

0 comments on commit ee498ef

Please sign in to comment.