Leverage PHPUnit 13 array assertions#76
Merged
Merged
Conversation
PHPUnit 13 introduces dedicated array-comparison assertions whose names encode comparison strictness, key handling and order sensitivity. Replace generic assertEquals/assertSame calls that compare arrays with the precise equivalents: - assertSame(array, array) -> assertArraysAreIdentical (strict, keys, order) - assertEquals(array, array) -> assertArraysAreEqual (loose, keys, order) Assertions whose actual value is nullable (?array getMetadata()) or mixed (json_decode) are left untouched to keep PHPStan level 7 happy. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
The forward/backward iterator tests and the normalizer test compared the same fixed-type data as the direct read paths, but did so loosely (assertArraysAreEqual). Since the values are strictly typed strings/arrays with no loose-coercion intent, tighten them to assertArraysAreIdentical so the same data is asserted with identical strictness across all call sites. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Contributor
There was a problem hiding this comment.
Pull request overview
Updates the test suite to use PHPUnit 13’s dedicated array-comparison assertions instead of generic assertSame/assertEquals for array comparisons, aiming to make intent clearer and leverage PHPUnit’s newer APIs.
Changes:
- Replaced several array comparisons in tests with
assertArraysAreIdentical(...). - Standardized array assertion usage in unit and integration tests around event data normalization/reading.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 3 comments.
| File | Description |
|---|---|
| tests/Unit/WritableEventNormalizerTest.php | Replaces an array assertEquals with a PHPUnit 13 array assertion. |
| tests/Integration/EventStoreTest.php | Replaces multiple array comparisons of event data with PHPUnit 13 array assertions. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| ]; | ||
|
|
||
| $this->assertEquals($expected, $normalized); | ||
| $this->assertArraysAreIdentical($expected, $normalized); |
| $event = $entryWithEvent->getEvent(); | ||
| $this->assertEquals('Foo_Event', $event->getType()); | ||
| $this->assertEquals(['foo_data_key' => 'bar'], $event->getData()); | ||
| $this->assertArraysAreIdentical(['foo_data_key' => 'bar'], $event->getData()); |
| $event = $entryWithEvent->getEvent(); | ||
| $this->assertEquals('Foo_Event', $event->getType()); | ||
| $this->assertEquals(['foo_data_key' => 'bar'], $event->getData()); | ||
| $this->assertArraysAreIdentical(['foo_data_key' => 'bar'], $event->getData()); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
PHPUnit 13 introduces dedicated array-comparison assertions whose method names encode three dimensions: comparison strictness (identical vs equal), key handling (considered vs ignored), and order sensitivity. This PR adopts them where the test suite was comparing arrays via the general-purpose
assertSame/assertEquals.The project already required
phpunit/phpunit: ^13.0, so no dependency change was needed — only the assertion call sites.Changes
Mapping applied (faithful to the previous
===/==semantics, with known fixed key order):assertSame(array, array)→assertArraysAreIdentical(strict, keys considered, order significant)assertEquals(array, array)→assertArraysAreEqual(loose, keys considered, order significant)Converted call sites:
tests/Unit/WritableEventNormalizerTest.php:38assertEqualsassertArraysAreEqualtests/Integration/EventStoreTest.php:226assertSameassertArraysAreIdenticaltests/Integration/EventStoreTest.php:279assertSameassertArraysAreIdenticaltests/Integration/EventStoreTest.php:307assertSameassertArraysAreIdenticaltests/Integration/EventStoreTest.php:400assertEqualsassertArraysAreEqualtests/Integration/EventStoreTest.php:424assertEqualsassertArraysAreEqualDeliberately left untouched
The new assertions require both arguments to be typed
array. Two array comparisons were kept as-is to avoid PHPStan level 7 friction:EventStoreTest.php:308—getMetadata()returns?array(nullable)EventStoreTest.php:168—json_decode(..., true)returnsmixedWritableEventCollectionTest.php:52compares two JSON strings, not arrays, so it is not a candidate.Verification
make before-pushpasses: cs-fixer clean, 104 tests / 260 assertions green, PHPStan level 7 with no errors.🤖 Generated with Claude Code