From 026dc13565b21934d5bc0c010ba5ad2e7c76832c Mon Sep 17 00:00:00 2001 From: Claude Date: Fri, 4 Dec 2026 20:54:44 +0000 Subject: [PATCH] Analyse tests with PHPStan Add the tests/ folder to PHPStan's paths and scan the wp-cli-tests TestCase so PHPStan knows the base class and its polyfilled assertions. Fix the errors this reports: narrow the items yielded by RecursiveIteratorIterator to SplFileInfo with assertInstanceOf() before calling getPathname(). Also switch the setUp()/tearDown() overrides to the Yoast polyfill set_up()/tear_down() fixtures provided by WP_CLI\Tests\TestCase. Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_01UWTd5n3ZupvgHr4fEBJCGp --- phpstan.neon.dist | 2 ++ tests/Distignore_Filter_Iterator_Test.php | 13 +++++++++---- 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/phpstan.neon.dist b/phpstan.neon.dist index 824de93..2c88aef 100644 --- a/phpstan.neon.dist +++ b/phpstan.neon.dist @@ -3,10 +3,12 @@ parameters: paths: - src - dist-archive-command.php + - tests scanDirectories: - vendor/wp-cli/wp-cli/php scanFiles: - vendor/php-stubs/wordpress-stubs/wordpress-stubs.php + - vendor/wp-cli/wp-cli-tests/tests/includes/TestCase.php treatPhpDocTypesAsCertain: false ignoreErrors: - identifier: missingType.parameter diff --git a/tests/Distignore_Filter_Iterator_Test.php b/tests/Distignore_Filter_Iterator_Test.php index cd33f4d..2ef15f4 100644 --- a/tests/Distignore_Filter_Iterator_Test.php +++ b/tests/Distignore_Filter_Iterator_Test.php @@ -17,8 +17,8 @@ class Distignore_Filter_Iterator_Test extends TestCase { /** * Set up test environment. */ - public function setUp(): void { - parent::setUp(); + protected function set_up() { + parent::set_up(); $this->temp_dir = sys_get_temp_dir() . '/distignore-test-' . uniqid(); mkdir( $this->temp_dir ); @@ -27,11 +27,11 @@ public function setUp(): void { /** * Clean up test environment. */ - public function tearDown(): void { + protected function tear_down() { if ( is_dir( $this->temp_dir ) ) { $this->recursiveDelete( $this->temp_dir ); } - parent::tearDown(); + parent::tear_down(); } /** @@ -67,6 +67,7 @@ public function test_filters_ignored_files() { $files = []; foreach ( $recursive_iter as $item ) { + $this->assertInstanceOf( SplFileInfo::class, $item ); $files[] = basename( $item->getPathname() ); } @@ -92,6 +93,7 @@ public function test_tracks_ignored_directories() { $files = []; foreach ( $recursive_iter as $item ) { + $this->assertInstanceOf( SplFileInfo::class, $item ); $relative_path = str_replace( $this->temp_dir, '', $item->getPathname() ); $files[] = $relative_path; } @@ -161,6 +163,7 @@ public function test_has_children_prevents_descent() { $files = []; foreach ( $recursive_iter as $item ) { + $this->assertInstanceOf( SplFileInfo::class, $item ); $relative_path = str_replace( $this->temp_dir, '', $item->getPathname() ); $files[] = $relative_path; } @@ -188,6 +191,7 @@ public function test_negation_patterns() { $files = []; foreach ( $recursive_iter as $item ) { + $this->assertInstanceOf( SplFileInfo::class, $item ); $relative_path = str_replace( $this->temp_dir, '', $item->getPathname() ); $files[] = $relative_path; } @@ -231,6 +235,7 @@ public function test_nested_directory_filtering() { $files = []; foreach ( $recursive_iter as $item ) { + $this->assertInstanceOf( SplFileInfo::class, $item ); $relative_path = str_replace( $this->temp_dir, '', $item->getPathname() ); $files[] = $relative_path; }