From 09b37ffcc2e0512670b11ea2db26fa83e21d3a41 Mon Sep 17 00:00:00 2001 From: Pascal Birchler Date: Wed, 22 May 2024 07:03:17 +0200 Subject: [PATCH 1/3] Fix compatibility with latest PHPUnit --- .gitignore | 2 ++ phpunit.xml.dist | 29 ++++++++++++------- ...composer-json.php => ComposerJsonTest.php} | 8 +++-- ...anipulator.php => JsonManipulatorTest.php} | 12 ++++---- 4 files changed, 32 insertions(+), 19 deletions(-) rename tests/{test-composer-json.php => ComposerJsonTest.php} (96%) rename tests/{test-json-manipulator.php => JsonManipulatorTest.php} (99%) diff --git a/.gitignore b/.gitignore index bcf211b32..f16162361 100644 --- a/.gitignore +++ b/.gitignore @@ -9,3 +9,5 @@ composer.lock phpunit.xml phpcs.xml .phpcs.xml +.phpunit.cache +.phpunit.result.cache diff --git a/phpunit.xml.dist b/phpunit.xml.dist index bcdd6b1c2..dc9847342 100644 --- a/phpunit.xml.dist +++ b/phpunit.xml.dist @@ -1,11 +1,20 @@ - - - - tests/ - tests/ - - + + + tests + + + + + src + + diff --git a/tests/test-composer-json.php b/tests/ComposerJsonTest.php similarity index 96% rename from tests/test-composer-json.php rename to tests/ComposerJsonTest.php index dcb214c0b..93b29a956 100644 --- a/tests/test-composer-json.php +++ b/tests/ComposerJsonTest.php @@ -28,10 +28,11 @@ public function set_up() { WP_CLI::set_logger( $this->logger ); // Enable exit exception. + $class_wp_cli_capture_exit = new \ReflectionProperty( 'WP_CLI', 'capture_exit' ); $class_wp_cli_capture_exit->setAccessible( true ); - $this->prev_capture_exit = $class_wp_cli_capture_exit->getValue(); - $class_wp_cli_capture_exit->setValue( true ); + $class_wp_cli = new \ReflectionClass( 'WP_CLI' ); + $class_wp_cli->setStaticPropertyValue( 'capture_exit', true ); $this->temp_dir = Utils\get_temp_dir() . uniqid( 'wp-cli-test-package-composer-json-', true ) . '/'; mkdir( $this->temp_dir ); @@ -44,7 +45,8 @@ public function tear_down() { // Restore exit exception. $class_wp_cli_capture_exit = new \ReflectionProperty( 'WP_CLI', 'capture_exit' ); $class_wp_cli_capture_exit->setAccessible( true ); - $class_wp_cli_capture_exit->setValue( $this->prev_capture_exit ); + $class_wp_cli = new \ReflectionClass( 'WP_CLI' ); + $class_wp_cli->setStaticPropertyValue( 'capture_exit', $this->prev_capture_exit ); rmdir( $this->temp_dir ); diff --git a/tests/test-json-manipulator.php b/tests/JsonManipulatorTest.php similarity index 99% rename from tests/test-json-manipulator.php rename to tests/JsonManipulatorTest.php index add2727a7..026f7bec8 100644 --- a/tests/test-json-manipulator.php +++ b/tests/JsonManipulatorTest.php @@ -26,7 +26,7 @@ public function testAddLink($json, $type, $package, $constraint, $expected) $this->assertEquals($expected, $manipulator->getContents()); } - public function linkProvider() + public static function linkProvider() { return array( array( @@ -1297,7 +1297,7 @@ public function testAddLinkAndSortPackages($json, $type, $package, $constraint, $this->assertEquals($expected, $manipulator->getContents()); } - public function providerAddLinkAndSortPackages() + public static function providerAddLinkAndSortPackages() { return array( array( @@ -1380,7 +1380,7 @@ public function testRemoveSubNode($json, $name, $expected, $expectedContent = nu } } - public function removeSubNodeProvider() + public static function removeSubNodeProvider() { return array( 'works on simple ones first' => array( @@ -2374,7 +2374,7 @@ public function testAddLinkCaseInsensitive($json, $type, $package, $constraint, $this->assertEquals($expected, $manipulator->getContents()); } - public function providerAddLinkCaseInsensitive() + public static function providerAddLinkCaseInsensitive() { return array( array( @@ -2441,7 +2441,7 @@ public function testAddSubNodeCase($json, $mainNode, $name, $caseInsensitive, $e $this->assertSame($expected, $manipulator->getContents()); } - public function providerAddSubNodeCase() + public static function providerAddSubNodeCase() { return array( array( @@ -2504,7 +2504,7 @@ public function testRemoveSubNodeCaseInsensitive($json, $mainNode, $name, $expec } } - public function providerRemoveSubNodeCaseInsensitive() + public static function providerRemoveSubNodeCaseInsensitive() { return array( array( From a6af9a3d8760f5c9daf84ffe197943d46ba8bebc Mon Sep 17 00:00:00 2001 From: Pascal Birchler Date: Wed, 22 May 2024 07:05:37 +0200 Subject: [PATCH 2/3] Update PHPCS config --- phpcs.xml.dist | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/phpcs.xml.dist b/phpcs.xml.dist index e82b67bcc..6da9ad35e 100644 --- a/phpcs.xml.dist +++ b/phpcs.xml.dist @@ -18,7 +18,7 @@ */src/WP_CLI/JsonManipulator\.php$ */src/WP_CLI/Package/Compat/Min_Composer_1_10/NullIOMethodsTrait\.php$ */src/WP_CLI/Package/Compat/Min_Composer_2_3/NullIOMethodsTrait\.php$ - */tests/test-json-manipulator\.php$ + */tests/JsonManipulatorTest\.php$ From 7652a58ffc5fca2b055cda20f6aab279848ca20f Mon Sep 17 00:00:00 2001 From: Pascal Birchler Date: Wed, 22 May 2024 07:14:53 +0200 Subject: [PATCH 3/3] Simply pass null --- tests/ComposerJsonTest.php | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/tests/ComposerJsonTest.php b/tests/ComposerJsonTest.php index 93b29a956..82ef7d46f 100644 --- a/tests/ComposerJsonTest.php +++ b/tests/ComposerJsonTest.php @@ -31,8 +31,7 @@ public function set_up() { $class_wp_cli_capture_exit = new \ReflectionProperty( 'WP_CLI', 'capture_exit' ); $class_wp_cli_capture_exit->setAccessible( true ); - $class_wp_cli = new \ReflectionClass( 'WP_CLI' ); - $class_wp_cli->setStaticPropertyValue( 'capture_exit', true ); + $class_wp_cli_capture_exit->setValue( null, true ); $this->temp_dir = Utils\get_temp_dir() . uniqid( 'wp-cli-test-package-composer-json-', true ) . '/'; mkdir( $this->temp_dir ); @@ -45,8 +44,7 @@ public function tear_down() { // Restore exit exception. $class_wp_cli_capture_exit = new \ReflectionProperty( 'WP_CLI', 'capture_exit' ); $class_wp_cli_capture_exit->setAccessible( true ); - $class_wp_cli = new \ReflectionClass( 'WP_CLI' ); - $class_wp_cli->setStaticPropertyValue( 'capture_exit', $this->prev_capture_exit ); + $class_wp_cli_capture_exit->setValue( null, $this->prev_capture_exit ); rmdir( $this->temp_dir );