Add SimpleCacheV3Test for PSR-16 v3 strict type hints (#121)#122
Open
GautamMKGarg wants to merge 1 commit into
Open
Add SimpleCacheV3Test for PSR-16 v3 strict type hints (#121)#122GautamMKGarg wants to merge 1 commit into
GautamMKGarg wants to merge 1 commit into
Conversation
Contributor
|
I think we should have a single test class, to make it easier for projects supporting multiple versions of |
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.
Closes #121 (with the help of AI agents)
PSR-16 v3 (psr/simple-cache ^3.0) introduced strict PHP type hints:
string $keyiterable $keysnull|int|\DateInterval $ttlThis caused the existing
SimpleCacheTestdata providers to throw\TypeErrorbefore implementation code ever ran, making many tests effectively broken for
v3 consumers.
What this PR does
Adds
SimpleCacheV3Test— a new subclass ofSimpleCacheTestthat:invalidKeys()andinvalidArrayKeys()to only string invalidkeys (non-string types are rejected by PHP before reaching the library)
invalidTtl()to values that don't coerce to valid int/null inPHP weak mode
assertCacheExceptionOrTypeError()helper that accepts both\TypeError(PHP-level rejection) andInvalidArgumentException(library-level validation) as valid failures
testBasicUsageWithLongKey64()— tests the PSR-16 mandatedminimum key length of 64 characters
Updates
composer.json— addspsr/simple-cache: ^1.0 || ^2.0 || ^3.0to
require-devso the test suite can be developed against any versionUpdates
README.md— documentsSimpleCacheV3TestusageBackward compatibility
SimpleCacheTestis completely untouched. Existing v1/v2 consumers continueusing it without any changes. V3 consumers switch to
SimpleCacheV3Test.Tested against
gautammkgarg/psr-for-wordpress(Packagist) —
a real PSR-16 v3 WordPress bridge implementation (transients + object cache
adapters, 466 tests, 2251 assertions, all passing)