Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix failing PHPUnit tests #188

Merged
merged 3 commits into from
May 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,5 @@ composer.lock
phpunit.xml
phpcs.xml
.phpcs.xml
.phpunit.cache
.phpunit.result.cache
Comment on lines +12 to +13
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
.phpunit.cache
.phpunit.result.cache
*.[Cc]ache

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I personally prefer the more verbose format

2 changes: 1 addition & 1 deletion phpcs.xml.dist
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
<exclude-pattern>*/src/WP_CLI/JsonManipulator\.php$</exclude-pattern>
<exclude-pattern>*/src/WP_CLI/Package/Compat/Min_Composer_1_10/NullIOMethodsTrait\.php$</exclude-pattern>
<exclude-pattern>*/src/WP_CLI/Package/Compat/Min_Composer_2_3/NullIOMethodsTrait\.php$</exclude-pattern>
<exclude-pattern>*/tests/test-json-manipulator\.php$</exclude-pattern>
<exclude-pattern>*/tests/JsonManipulatorTest\.php$</exclude-pattern>

<!-- Show progress. -->
<arg value="p"/>
Expand Down
29 changes: 19 additions & 10 deletions phpunit.xml.dist
Original file line number Diff line number Diff line change
@@ -1,11 +1,20 @@
<phpunit
bootstrap="vendor/autoload.php"
colors="true"
>
<testsuites>
<testsuite>
<directory prefix="spec-" suffix=".php">tests/</directory>
<directory prefix="test-" suffix=".php">tests/</directory>
</testsuite>
</testsuites>
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/4.8/phpunit.xsd"
bootstrap="vendor/autoload.php"
backupGlobals="false"
beStrictAboutCoversAnnotation="true"
beStrictAboutOutputDuringTests="true"
beStrictAboutTestsThatDoNotTestAnything="true"
beStrictAboutTodoAnnotatedTests="true"
colors="true"
verbose="true">
Copy link
Member

@thelovekesh thelovekesh May 22, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We might want to remove it from here, as PHPUnit doesn't support it in future releases. Verbosity can be handled from CLI instead if required?

<testsuite name="wp-cli/package-command tests">
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
<testsuite name="wp-cli/package-command tests">
<testsuite name="default">

It can remain default given this test file is specific to this package. Also, I think we should add defaultTestSuite="default" attribute in the <phpunit> element?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is more consistent with other commands though. Main thing is that the name is defined, which it previously wasn't.

<directory suffix="Test.php">tests</directory>
</testsuite>

<filter>
<whitelist processUncoveredFilesFromWhitelist="true">
<directory suffix=".php">src</directory>
</whitelist>
</filter>
</phpunit>
6 changes: 3 additions & 3 deletions tests/test-composer-json.php → tests/ComposerJsonTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,10 @@ 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_capture_exit->setValue( null, true );

$this->temp_dir = Utils\get_temp_dir() . uniqid( 'wp-cli-test-package-composer-json-', true ) . '/';
mkdir( $this->temp_dir );
Expand All @@ -44,7 +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_capture_exit->setValue( $this->prev_capture_exit );
$class_wp_cli_capture_exit->setValue( null, $this->prev_capture_exit );

rmdir( $this->temp_dir );

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -2504,7 +2504,7 @@ public function testRemoveSubNodeCaseInsensitive($json, $mainNode, $name, $expec
}
}

public function providerRemoveSubNodeCaseInsensitive()
public static function providerRemoveSubNodeCaseInsensitive()
{
return array(
array(
Expand Down