Skip to content

Commit e080906

Browse files
authored
Analyse tests with PHPStan (#271)
1 parent 21ac3e6 commit e080906

4 files changed

Lines changed: 17 additions & 3 deletions

File tree

‎phpstan.neon.dist‎

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,16 @@ parameters:
33
paths:
44
- src
55
- package-command.php
6+
- tests
7+
excludePaths:
8+
analyse:
9+
- tests/phpstan/scan-files.php
10+
- tests/phpunit/fixtures
611
scanDirectories:
712
- vendor/wp-cli/wp-cli/php
813
scanFiles:
914
- vendor/php-stubs/wordpress-stubs/wordpress-stubs.php
1015
- tests/phpstan/scan-files.php
16+
- vendor/wp-cli/wp-cli-tests/tests/bootstrap.php
17+
- vendor/wp-cli/wp-cli-tests/tests/includes/TestCase.php
1118
treatPhpDocTypesAsCertain: false
12-
ignoreErrors:
13-
# WP_CLI_VERSION is defined in wp-cli core at runtime
14-
- '#Constant WP_CLI_VERSION not found#'

‎tests/PackageAuthTest.php‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ private function invoke_set_composer_auth() {
4646
$package = new Package_Command();
4747
$method = new \ReflectionMethod( 'Package_Command', 'set_composer_auth_env_var' );
4848
if ( PHP_VERSION_ID < 80100 ) {
49+
// @phpstan-ignore method.deprecated
4950
$method->setAccessible( true );
5051
}
5152
$method->invoke( $package );

‎tests/phpunit/ComposerJsonTest.php‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ public function set_up() {
2222
// Save and set logger.
2323
$class_wp_cli_logger = new \ReflectionProperty( 'WP_CLI', 'logger' );
2424
if ( PHP_VERSION_ID < 80100 ) {
25+
// @phpstan-ignore method.deprecated
2526
$class_wp_cli_logger->setAccessible( true );
2627
}
2728
$this->prev_logger = $class_wp_cli_logger->getValue();
@@ -33,6 +34,7 @@ public function set_up() {
3334

3435
$class_wp_cli_capture_exit = new \ReflectionProperty( 'WP_CLI', 'capture_exit' );
3536
if ( PHP_VERSION_ID < 80100 ) {
37+
// @phpstan-ignore method.deprecated
3638
$class_wp_cli_capture_exit->setAccessible( true );
3739
}
3840
$class_wp_cli_capture_exit->setValue( null, true );
@@ -53,6 +55,7 @@ public function tear_down() {
5355
// Restore exit exception.
5456
$class_wp_cli_capture_exit = new \ReflectionProperty( 'WP_CLI', 'capture_exit' );
5557
if ( PHP_VERSION_ID < 80100 ) {
58+
// @phpstan-ignore method.deprecated
5659
$class_wp_cli_capture_exit->setAccessible( true );
5760
}
5861
$class_wp_cli_capture_exit->setValue( null, $this->prev_capture_exit );
@@ -65,6 +68,7 @@ public function tear_down() {
6568
public function test_create_default_composer_json() {
6669
$create_default_composer_json = new \ReflectionMethod( 'Package_Command', 'create_default_composer_json' );
6770
if ( PHP_VERSION_ID < 80100 ) {
71+
// @phpstan-ignore method.deprecated
6872
$create_default_composer_json->setAccessible( true );
6973
}
7074

@@ -109,6 +113,7 @@ public function test_get_composer_json_path() {
109113

110114
$get_composer_json_path = new \ReflectionMethod( 'Package_Command', 'get_composer_json_path' );
111115
if ( PHP_VERSION_ID < 80100 ) {
116+
// @phpstan-ignore method.deprecated
112117
$get_composer_json_path->setAccessible( true );
113118
}
114119

@@ -161,6 +166,7 @@ public function test_get_composer_json_path_backup_decoded() {
161166

162167
$get_composer_json_path_backup_decoded = new \ReflectionMethod( 'Package_Command', 'get_composer_json_path_backup_decoded' );
163168
if ( PHP_VERSION_ID < 80100 ) {
169+
// @phpstan-ignore method.deprecated
164170
$get_composer_json_path_backup_decoded->setAccessible( true );
165171
}
166172

@@ -218,6 +224,7 @@ public function test_installed_packages_filters_dependencies_and_accepts_legacy_
218224
file_put_contents( $this->temp_dir . 'vendor/composer/installed.json', '{"packages":[{"name":"vendor/command","version":"1.0.0"},{"name":"vendor/dependency","version":"2.0.0"}]}' );
219225
$method = new ReflectionMethod( 'Package_Command', 'get_installed_packages' );
220226
if ( PHP_VERSION_ID < 80100 ) {
227+
// @phpstan-ignore method.deprecated
221228
$method->setAccessible( true );
222229
}
223230
try {
@@ -236,6 +243,7 @@ public function test_installed_packages_filters_dependencies_and_accepts_legacy_
236243
public function test_sync_root_metadata_updates_version_and_excludes_required_from_replace() {
237244
$method = new \ReflectionMethod( 'Package_Command', 'sync_root_metadata' );
238245
if ( PHP_VERSION_ID < 80100 ) {
246+
// @phpstan-ignore method.deprecated
239247
$method->setAccessible( true );
240248
}
241249

‎tests/phpunit/ComposerPharTest.php‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,7 @@ public function test_both_streams_are_logged_without_ansi_or_empty_lines() {
8989
file_put_contents( $this->directory . '/composer.phar', '<?php fwrite(STDOUT, "\\033[32mstdout\\033[0m \\n\\n"); fwrite(STDERR, "stderr \\nlast line");' );
9090
$property = new ReflectionProperty( 'WP_CLI', 'logger' );
9191
if ( PHP_VERSION_ID < 80100 ) {
92+
// @phpstan-ignore method.deprecated
9293
$property->setAccessible( true );
9394
}
9495
$previous = $property->getValue();

0 commit comments

Comments
 (0)