Title: Feature request: Validate `with` and `willReturn` types on mocks · Issue #321 · phpstan/phpstan-phpunit · GitHub
Open Graph Title: Feature request: Validate `with` and `willReturn` types on mocks · Issue #321 · phpstan/phpstan-phpunit
X Title: Feature request: Validate `with` and `willReturn` types on mocks · Issue #321 · phpstan/phpstan-phpunit
Description: Given the following example, i'd expect PHPStan to report the following issues: The parameter types in with don't match the function signature The return value does not match the function signature. This would be usefull for projects wit...
Open Graph Description: Given the following example, i'd expect PHPStan to report the following issues: The parameter types in with don't match the function signature The return value does not match the function signature...
X Description: Given the following example, i'd expect PHPStan to report the following issues: The parameter types in with don't match the function signature The return value does not match the function s...
Opengraph URL: https://github.com/phpstan/phpstan-phpunit/issues/321
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Feature request: Validate `with` and `willReturn` types on mocks","articleBody":"Given the following example, i'd expect PHPStan to report the following issues:\n\n* The parameter types in `with` don't match the function signature\n* The return value does not match the function signature.\n\nThis would be usefull for projects with a large test suite, where you do a refactor of a method that is used in a lot of places. It would allow to fix these issues before running the entire test suite to get the errors from PHPUnit.\n\n```php\nclass T1 {\n public function myMethod(int $a, string $b): int {\n return 3;\n }\n}\n\nclass T1Test extends TestCase {\n public function testStuff(): void {\n $mock = $this->createMock(T1::class);\n\n $mock->expects($this->once())\n ->method('myMethod')\n ->with(\n new \\stdClass(),\n new \\stdClass(),\n )->willReturn(true);\n }\n}\n```\n\n","author":{"url":"https://github.com/BackEndTea","@type":"Person","name":"BackEndTea"},"datePublished":"2026-07-29T07:00:50Z","url":"https://github.com/phpstan/phpstan-phpunit/issues/321"}
| react-profiling | 0 |
| react-import-map | react,react-dom,react-dom/client,react-dom/profiling,react-is,react/compiler-runtime,react/jsx-dev-runtime,react/jsx-runtime,scheduler@b8488ee2c322 |
| route-pattern | /_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format) |
| route-controller | voltron_issues_fragments |
| route-action | issue_layout |
| fetch-nonce | v2:b4360fed-8604-8cdb-3497-9cb2fd4b0ba1 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | CB96:3E133F:3426EA:48E4F0:6B006D29 |
| html-safe-nonce | f6613ed73ce4fd0b039962cec4fe3acb2d804dd2b4ce2e6a19788e853895d588 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJDQjk2OjNFMTMzRjozNDI2RUE6NDhFNEYwOjZCMDA2RDI5IiwidmlzaXRvcl9pZCI6Ijc0NTAxNzE2NzkyNzczNDYwODkiLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ== |
| visitor-hmac | f91f089e158590751de00ab089dd45a6a89eddc047c23ee65804d88e86dc1739 |
| hovercard-subject-tag | issue:5006414181 |
| github-keyboard-shortcuts | repository,issues,copilot |
| google-site-verification | Apib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I |
| octolytics-url | https://collector.github.com/github/collect |
| analytics-location | / |
| fb:app_id | 1401488693436528 |
| apple-itunes-app | app-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/phpstan/phpstan-phpunit/321/issue_layout |
| twitter:image | https://opengraph.githubassets.com/e338779fb7b0efb1f0943ef9bc4aeee6cb9405c631d0abc07386ed00cd5829ff/phpstan/phpstan-phpunit/issues/321 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/e338779fb7b0efb1f0943ef9bc4aeee6cb9405c631d0abc07386ed00cd5829ff/phpstan/phpstan-phpunit/issues/321 |
| og:image:alt | Given the following example, i'd expect PHPStan to report the following issues: The parameter types in with don't match the function signature The return value does not match the function signature... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | BackEndTea |
| hostname | github.com |
| expected-hostname | github.com |
| None | 6527e91c60c0b29d16606ff32ac5df8ecdc37a2a62205ea057a14d7762c870fa |
| turbo-cache-control | no-preview |
| go-import | github.com/phpstan/phpstan-phpunit git https://github.com/phpstan/phpstan-phpunit.git |
| octolytics-dimension-user_id | 16435710 |
| octolytics-dimension-user_login | phpstan |
| octolytics-dimension-repository_id | 105883921 |
| octolytics-dimension-repository_nwo | phpstan/phpstan-phpunit |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 105883921 |
| octolytics-dimension-repository_network_root_nwo | phpstan/phpstan-phpunit |
| turbo-body-classes | logged-out env-production page-responsive |
| disable-turbo | false |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | 46f1cd2ae3cd8ae1a81019b5d619742e76f13bbd |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
| react-app-name | issues |
Links:
Viewport: width=device-width