Add SimpleCacheV3Test for PSR-16 v3 strict type hints (#121)#122
Add SimpleCacheV3Test for PSR-16 v3 strict type hints (#121)#122GautamMKGarg wants to merge 6 commits into
Conversation
|
I think we should have a single test class, to make it easier for projects supporting multiple versions of |
|
@stof Thank you for the detailed feedback and sorry for the delay in response — this architecture is much cleaner than the subclass approach. I have updated the tests with some help from the AI tools, Here's what's been refactored:
Backward compatibility with v1 is preserved:
Would appreciate your review when you have time. |
stof
left a comment
There was a problem hiding this comment.
@GautamMKGarg checking the version of the interface package to decide between TypeError or InvalidArgumentException is the wrong approach. When writing an implementation supporting 2 versions of the interface, the types can differ between the interface and the implementation (respecting variance rules), and PHP will enforce strict types based on the implementation, not based on the interface.
I think you should always use assertCacheExceptionOrTypeError, without the switch based on self::isPsr16V1() to account for that.
And this PR should probably also cover the PSR-6 tests, as we have the same kind of stricter types for PSR-6 than for PSR-16.
|
@stof Thanks for more information. I have more remaining changes with the help of AI tools. This PR is ready for another review. Changes made: SimpleCacheTest: Removed CachePoolTest: Added Questions: |
|
I suggest submitting |
Removed test for PSR-16 minimum key length of 64 characters. Moving it in a seperate PR as suggested by @stof
|
Thanks @stof for your suggestion. I have removed |
stof
left a comment
There was a problem hiding this comment.
Looks good to me, but it will require someone with write access to the repo to allow workflow runs and to perform a review and merge. I don't have access to this repo.
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)