Repository navigation
[12.x] Support string abstract in mock/partialMock/spy PHPDoc - #59477
Conversation
|
Thanks, sorry for the oversigt. Can I ask why someone would use a string alias and type checking at the same time, it seems counter intuitive to me, and I'm working on two projects that aims to improve use and inference of types (a LSP for IDEs with build in Laravel support, and a Laravel plugin for mago, a fast Rust based alternative to PHPStan). I would have thought anyone using the alias would not care about the type since it doesn't allow for anything meaningful on the other end? |
|
Good question — adding It's just about not breaking their code: without it, passing |
|
|
…l#59477) * Support string abstract in mock/partialMock/spy PHPDoc with conditional return types * Fix StyleCI formatting
- mock(), partialMock() and spy() return MockInterface&TInstance for a class-string and MockInterface for other container keys (laravel/framework#59353, laravel/framework#59384, laravel/framework#59477), with the upstream type fixture. - The events dispatcher reads attributes through the support package's ReadsClassAttributes instead of the queue trait (laravel/framework#59275). The events package still requires hypervel/queue because CallQueuedListener uses it. - env:encrypt and env:decrypt build paths from environmentPath() (laravel/framework#58984). - Drop redundant array_flip() calls on class_uses_recursive(), which is already class-keyed (laravel/framework#59452), including Hypervel's command trait setup and Testbench's trait cache. - JSON:API imports its base collection under an alias and documents a non-negative relationship depth (laravel/framework#59079). The flushState test uses the upstream name and values (laravel/framework#59116). - Docblocks: Request::getSession() throws SessionNotFoundException (laravel/framework#58965), RateLimiter::for() (laravel/framework#59144) and WithoutOverlapping::shared() (laravel/framework#59375). - Tests: the chained-batch queue test for a batch with only a connection (laravel/framework#59233), and the final response-limit assertion in the Redis throttle test (laravel/framework#58990). Validation: each changed test file passes, as do the events, console, environment command, JSON:API resource and type fixture checks. Claude-Session: https://claude.ai/code/session_01WveaB7yyFo2T6yo7cnEpW9
This is a follow-up to #59353.
While #59353 improved the return type for
mock(),partialMock(), andspy()when usingclass-string, it restricted the$abstractparameter to only acceptclass-string<TInstance>, which causes PHPStan errors when passing plain string aliases — a common pattern in Laravel:This PR updates the
@paramtostring|class-string<TInstance>and uses conditional return types (consistent withContainer::make(),Container::makeWith(), etc.) so that:class-stringinput → returnsTInstance & MockInterface(preserving the DX win from Preserve class type of mocked classes #59353)stringinput → returnsMockInterface(backward compatible)Also adds PHPStan type assertion tests to verify both cases.