Skip to content

Commit

Permalink
phan: Add stubs for PHPUnit 9.6 (#36881)
Browse files Browse the repository at this point in the history
PHPUnit 9.6 has three major issues when it comes to analysis with Phan:

* It uses `@psalm`-prefixed phpdocs various places, which Phan doesn't
  understand. This most obviously shows up with mock objects where it
  only knows that they're `MockObject` and not also the class being
  mocked.
* It has the parameter type incorrectly declared for `->with()`.
* Phan loses the generic typing for methods that `@return $this` (it
  wants `@return $this<T>` to tell it the generic still applies).

We can work around all of these issues by generating stubs for PHPUnit,
then munging them to rewrite the `@psalm-` docs to `@phan-` and to fix
the incorrect docs. All this is done by the same script from #36803 that
we already have set up to auto-update WooCommerce stubs.

Then we may as well fix the new issues this turns up:

* Don't try to php-lint stub files. They don't need to be valid PHP as
  long as Phan is happy with them.
* For `yoast/phpunit-polyfills`, prefer the empty versions of the traits
  so we get the PHPUnit versions of things like `assertIsArray()` where
  PHPUnit already gives us `@phan-assert array $actual`.
* Remove lots of Phan suppressions added in previous PRs with comments
  about the PHPUnit issues above.
* Suppress lots of `PhanPluginUnreachableCode` now that Phan knows that
  methods like `->markTestSkipped()` never return.
* Suppress some PhanEmptyFQSENInClasslike warnings issued due to a Phan
  bug when intersection types are passed in callables.
* packages/jetpack-mu-wpcom is missing a dep on automattic/jetpack-status
  which was being hacked around in a test (and presumably only working
  in production because Jetpack is bringing in the package).
* And some other miscellaneous things.

Committed via a GitHub action: https://github.com/Automattic/jetpack/actions/runs/8709448100

Upstream-Ref: Automattic/jetpack@3d714eb
  • Loading branch information
anomiex authored and matticbot committed Apr 16, 2024
1 parent 1a9b6f6 commit 045fa84
Show file tree
Hide file tree
Showing 5 changed files with 10 additions and 10 deletions.
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
},
"require-dev": {
"yoast/phpunit-polyfills": "1.1.0",
"automattic/jetpack-changelogger": "^4.2.1"
"automattic/jetpack-changelogger": "^4.2.2-alpha"
},
"autoload": {
"classmap": [
Expand Down
10 changes: 5 additions & 5 deletions composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion vendor/automattic/jetpack-device-detection/composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
},
"require-dev": {
"yoast/phpunit-polyfills": "1.1.0",
"automattic/jetpack-changelogger": "^4.2.1"
"automattic/jetpack-changelogger": "^4.2.2-alpha"
},
"suggest": {
"automattic/jetpack-autoloader": "Allow for better interoperability with other plugins that use this package."
Expand Down
4 changes: 2 additions & 2 deletions vendor/composer/installed.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,13 @@
"dist": {
"type": "path",
"url": "/tmp/jetpack-build/Automattic/jetpack-device-detection",
"reference": "2fea361c1c62203aeb07748bdd6780bfcdee1578"
"reference": "b7ab04ebbb478bd0d60ef69c0485a4f591d4334b"
},
"require": {
"php": ">=7.0"
},
"require-dev": {
"automattic/jetpack-changelogger": "^4.2.1",
"automattic/jetpack-changelogger": "^4.2.2-alpha",
"yoast/phpunit-polyfills": "1.1.0"
},
"suggest": {
Expand Down
2 changes: 1 addition & 1 deletion vendor/composer/installed.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
'automattic/jetpack-device-detection' => array(
'pretty_version' => '2.1.3',
'version' => '2.1.3.0',
'reference' => '2fea361c1c62203aeb07748bdd6780bfcdee1578',
'reference' => 'b7ab04ebbb478bd0d60ef69c0485a4f591d4334b',
'type' => 'jetpack-library',
'install_path' => __DIR__ . '/../automattic/jetpack-device-detection',
'aliases' => array(),
Expand Down

0 comments on commit 045fa84

Please sign in to comment.