Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix mock method $args parameter type #1397

Merged
merged 1 commit into from Mar 13, 2024

Conversation

sakarikl
Copy link
Contributor

fix for #1395

@sakarikl
Copy link
Contributor Author

sakarikl commented Mar 13, 2024

This still does not fix alias: and such usages, but most normal use cases PHPStan undestands it properly.

and if no parameters given at all also still fails.

But in those cases it might be able to solve with this: https://github.com/phpstan/phpstan-mockery

@ghostwriter ghostwriter added this to the 1.6.10 milestone Mar 13, 2024
@ghostwriter ghostwriter self-assigned this Mar 13, 2024
@ghostwriter ghostwriter added Patch Backwards compatible bug fixes and improvements Fixed for bug fixes or error corrections labels Mar 13, 2024
@ghostwriter ghostwriter linked an issue Mar 13, 2024 that may be closed by this pull request
Copy link
Member

@ghostwriter ghostwriter left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks great, going to merge this pull request.

Thank you.

@ghostwriter ghostwriter merged commit bbc6d97 into mockery:1.6.x Mar 13, 2024
19 of 22 checks passed
@ghostwriter
Copy link
Member

This still does not fix alias: and such usages

Thank you, made a note to take care of that.

@ghostwriter ghostwriter mentioned this pull request Mar 19, 2024
@@ -468,7 +468,7 @@ public static function isSame($expected): IsSame
*
* @template TMock
*
* @param TMock ...$args
* @param array<class-string<TMock>|TMock> $args
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is invalid type, because according in the doc you can

$mock = \Mockery::mock('MyClass', 'MyInterface', [$constructorArg1, $constructorArg2]);

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes it is. There are still a lot of different use cases that this does not cover.

@Harrald
Copy link

Harrald commented Mar 20, 2024

While this update fixes a lot of phpstan errors. It also introduces a new one for an edge case in my code:

Parameter #2 ...$args of static method Mockery::mock() expects class-string<SplFileObject>|SplFileObject, array<int, string> given.

$path = 'php://memory';
$splFileObject = Mockery::mock('SplFileObject', [$path]);

It seems that like it only excepts 1 parameter?
These also fail:
$skuNotFoundException = Mockery::mock('alias:' . SkuDoesNotExistException::class, Exception::class);
$supplierModel = Mockery::mock('alias:' . SupplierModel::class, Model::class);

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Fixed for bug fixes or error corrections Patch Backwards compatible bug fixes and improvements
Projects
None yet
Development

Successfully merging this pull request may close these issues.

PHPStan error with mock method in 1.6.8
4 participants