Skip to content

Commit

Permalink
Fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
swissspidy committed May 22, 2024
1 parent 60fe7f5 commit cbe7b57
Show file tree
Hide file tree
Showing 16 changed files with 45 additions and 39 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,5 @@ phpunit.xml
phpcs.xml
.phpcs.xml
composer.lock
.phpunit.result.cache
.phpunit.cache
32 changes: 18 additions & 14 deletions phpunit.xml.dist
Original file line number Diff line number Diff line change
@@ -1,16 +1,20 @@
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="http://schema.phpunit.de/4.8/phpunit.xsd"
bootstrap="tests/bootstrap.php"
colors="always"
beStrictAboutTestsThatDoNotTestAnything="true"
beStrictAboutOutputDuringTests="true"
beStrictAboutTestSize="true"
beStrictAboutChangesToGlobalState="false">
<testsuites>
<testsuite>
<directory prefix="spec-" suffix=".php">tests/</directory>
<directory prefix="test-" suffix=".php">tests/</directory>
<directory suffix="Test.php">tests/</directory>
</testsuite>
</testsuites>
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/4.8/phpunit.xsd"
bootstrap="tests/bootstrap.php"
backupGlobals="false"
beStrictAboutCoversAnnotation="true"
beStrictAboutOutputDuringTests="true"
beStrictAboutTestsThatDoNotTestAnything="true"
beStrictAboutTodoAnnotatedTests="true"
colors="true"
verbose="true">
<testsuite name="wp-cli/wp-cli tests">
<directory suffix="Test.php">tests</directory>
</testsuite>

<filter>
<whitelist processUncoveredFilesFromWhitelist="true">
<directory suffix=".php">src</directory>
</whitelist>
</filter>
</phpunit>
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
use WP_CLI\SynopsisValidator;
use WP_CLI\Tests\TestCase;

class ArgValidationTests extends TestCase {
class ArgValidationTest extends TestCase {

public function testMissingPositional() {
$validator = new SynopsisValidator( '<foo> <bar> [<baz>]' );
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

require_once dirname( __DIR__ ) . '/php/class-wp-cli-command.php';

class CommandFactoryTests extends TestCase {
class CommandFactoryTest extends TestCase {

/**
* @dataProvider dataProviderExtractLastDocComment
Expand Down Expand Up @@ -48,7 +48,7 @@ public function testExtractLastDocCommentWin( $content, $expected ) {
putenv( false === $is_windows ? 'WP_CLI_TEST_IS_WINDOWS' : "WP_CLI_TEST_IS_WINDOWS=$is_windows" );
}

public function dataProviderExtractLastDocComment() {
public static function dataProviderExtractLastDocComment() {
return [
[ '', false ],
[ '*/', false ],
Expand Down
File renamed without changes.
2 changes: 1 addition & 1 deletion tests/test-doc-parser.php → tests/DocParserTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
use WP_CLI\DocParser;
use WP_CLI\Tests\TestCase;

class DocParserTests extends TestCase {
class DocParserTest extends TestCase {

public function test_empty() {
$doc = new DocParser( '' );
Expand Down
2 changes: 1 addition & 1 deletion tests/test-extractor.php → tests/ExtractorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
use WP_CLI\Tests\TestCase;
use WP_CLI\Utils;

class Extractor_Test extends TestCase {
class ExtractorTest extends TestCase {

public static $copy_overwrite_files_prefix = 'wp-cli-test-utils-copy-overwrite-files-';

Expand Down
File renamed without changes.
File renamed without changes.
4 changes: 2 additions & 2 deletions tests/test-inflector.php → tests/InflectorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ public function testPluralize( $singular, $expected ) {
$this->assertEquals( $expected, Inflector::pluralize( $singular ) );
}

public function dataProviderPluralize() {
public static function dataProviderPluralize() {
return [
[ 'string', 'strings' ], // Regular.
[ 'person', 'people' ], // Irregular.
Expand All @@ -27,7 +27,7 @@ public function testSingularize( $singular, $expected ) {
$this->assertEquals( $expected, Inflector::singularize( $singular ) );
}

public function dataProviderSingularize() {
public static function dataProviderSingularize() {
return [
[ 'strings', 'string' ], // Regular.
[ 'people', 'person' ], // Irregular.
Expand Down
2 changes: 1 addition & 1 deletion tests/test-logging.php → tests/LoggingTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ protected function get_runner() {
}
}

class LoggingTests extends TestCase {
class LoggingTest extends TestCase {

public function testLogDebug() {
$message = 'This is a test message.';
Expand Down
4 changes: 2 additions & 2 deletions tests/test-process.php → tests/ProcessTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
use WP_CLI\Tests\TestCase;
use WP_CLI\Utils;

class ProcessTests extends TestCase {
class ProcessTest extends TestCase {

/**
* @dataProvider data_process_env
Expand All @@ -18,7 +18,7 @@ public function test_process_env( $cmd_prefix, $env, $expected_env_vars, $expect
$this->assertSame( $process_run->stdout, $expected_out );
}

public function data_process_env() {
public static function data_process_env() {
return [
[ '', [], [], '' ],
[ 'ENV=blah', [], [ 'ENV' ], 'blah' ],
Expand Down
File renamed without changes.
28 changes: 14 additions & 14 deletions tests/test-utils.php → tests/UtilsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -272,7 +272,7 @@ public function testParseSSHUrl() {
$this->assertEquals( null, Utils\parse_ssh_url( $testcase, PHP_URL_PATH ) );
}

public function parseStrToArgvData() {
public static function parseStrToArgvData() {
return [
[ [], '' ],
[ [ 'option', 'get', 'home' ], 'option get home' ],
Expand Down Expand Up @@ -414,7 +414,7 @@ public function testNormalizePath( $path, $expected ) {
$this->assertEquals( $expected, Utils\normalize_path( $path ) );
}

public function dataNormalizePath() {
public static function dataNormalizePath() {
return [
[ '', '' ],
// Windows paths.
Expand Down Expand Up @@ -476,7 +476,7 @@ public function testHttpRequestBadAddress() {
WP_CLI::set_logger( $prev_logger );
}

public function dataHttpRequestBadCAcert() {
public static function dataHttpRequestBadCAcert() {
return [
'default request' => [
[],
Expand Down Expand Up @@ -552,7 +552,7 @@ public function testHttpRequestVerify( $expected, $options ) {
$this->assertEquals( $expected, $transport_spy->requests[0]['options']['verify'] );
}

public function dataHttpRequestVerify() {
public static function dataHttpRequestVerify() {
return [
'not passed' => [
true,
Expand Down Expand Up @@ -589,7 +589,7 @@ public function testPastTenseVerb( $verb, $expected ) {
$this->assertSame( $expected, Utils\past_tense_verb( $verb ) );
}

public function dataPastTenseVerb() {
public static function dataPastTenseVerb() {
return [
// Known to be used by commands.
[ 'activate', 'activated' ],
Expand Down Expand Up @@ -645,7 +645,7 @@ public function testExpandGlobs( $path, $expected ) {
putenv( false === $expand_globs_no_glob_brace ? 'WP_CLI_TEST_EXPAND_GLOBS_NO_GLOB_BRACE' : "WP_CLI_TEST_EXPAND_GLOBS_NO_GLOB_BRACE=$expand_globs_no_glob_brace" );
}

public function dataExpandGlobs() {
public static function dataExpandGlobs() {
// Files in "data/expand_globs": foo.ab1, foo.ab2, foo.efg1, foo.efg2, bar.ab1, bar.ab2, baz.ab1, baz.ac1, baz.efg2.
return [
[ 'foo.ab1', [ 'foo.ab1' ] ],
Expand Down Expand Up @@ -695,7 +695,7 @@ public function testReportBatchOperationResults( $stdout, $stderr, $noun, $verb,
WP_CLI::set_logger( $prev_logger );
}

public function dataReportBatchOperationResults() {
public static function dataReportBatchOperationResults() {
return [
[ "Success: Noun already verbed.\n", '', 'noun', 'verb', 1, 0, 0, null ],
[ "Success: Verbed 1 of 1 nouns.\n", '', 'noun', 'verb', 1, 1, 0, null ],
Expand Down Expand Up @@ -754,7 +754,7 @@ public function testProcOpenCompatWinEnv( $cmd, $env, $expected_cmd, $expected_e
putenv( false === $env_is_windows ? 'WP_CLI_TEST_IS_WINDOWS' : "WP_CLI_TEST_IS_WINDOWS=$env_is_windows" );
}

public function dataProcOpenCompatWinEnv() {
public static function dataProcOpenCompatWinEnv() {
return [
[ 'echo', [], 'echo', [] ],
[ 'ENV=blah echo', [], 'echo', [ 'ENV' => 'blah' ] ],
Expand Down Expand Up @@ -806,7 +806,7 @@ public function testIsJson( $argument, $ignore_scalars, $expected ) {
$this->assertEquals( $expected, Utils\is_json( $argument, $ignore_scalars ) );
}

public function dataIsJson() {
public static function dataIsJson() {
return [
[ '42', true, false ],
[ '42', false, true ],
Expand All @@ -830,7 +830,7 @@ public function testParseShellArray( $assoc_args, $array_arguments, $expected )
$this->assertEquals( $expected, Utils\parse_shell_arrays( $assoc_args, $array_arguments ) );
}

public function dataParseShellArray() {
public static function dataParseShellArray() {
return [
[ [ 'alpha' => '{"key":"value"}' ], [], [ 'alpha' => '{"key":"value"}' ] ],
[ [ 'alpha' => '{"key":"value"}' ], [ 'alpha' ], [ 'alpha' => [ 'key' => 'value' ] ] ],
Expand All @@ -845,7 +845,7 @@ public function testPluralize( $singular, $count, $expected ) {
$this->assertEquals( $expected, Utils\pluralize( $singular, $count ) );
}

public function dataPluralize() {
public static function dataPluralize() {
return [
[ 'string', 1, 'string' ],
[ 'string', 2, 'strings' ],
Expand All @@ -860,7 +860,7 @@ public function testPickFields( $data, $fields, $expected ) {
$this->assertEquals( $expected, Utils\pick_fields( $data, $fields ) );
}

public function dataPickFields() {
public static function dataPickFields() {
return [
[ [ 'keyA' => 'valA', 'keyB' => 'valB', 'keyC' => 'valC' ], [ 'keyB' ], [ 'keyB' => 'valB' ] ],

Check failure on line 865 in tests/UtilsTest.php

View workflow job for this annotation

GitHub Actions / code-quality / PHPCS

When a multi-item array uses associative keys, each value should start on a new line.
[ [ '1' => 'valA', '2' => 'valB', '3' => 'valC' ], [ '2' ], [ '2' => 'valB' ] ],

Check failure on line 866 in tests/UtilsTest.php

View workflow job for this annotation

GitHub Actions / code-quality / PHPCS

When a multi-item array uses associative keys, each value should start on a new line.
Expand All @@ -879,7 +879,7 @@ public function testParseUrl( $url, $component, $auto_add_scheme, $expected ) {
$this->assertEquals( $expected, Utils\parse_url( $url, $component, $auto_add_scheme ) );
}

public function dataParseUrl() {
public static function dataParseUrl() {
return [
[ 'http://user:pass@example.com:9090/path?arg=value#anchor', -1, true, [ 'scheme' => 'http', 'host' => 'example.com', 'port' => 9090, 'user' => 'user', 'pass' => 'pass', 'path' => '/path', 'query' => 'arg=value', 'fragment' => 'anchor' ] ],
[ 'example.com:9090/path?arg=value#anchor', -1, true, [ 'scheme' => 'http', 'host' => 'example.com', 'port' => 9090, 'path' => '/path', 'query' => 'arg=value', 'fragment' => 'anchor' ] ],
Expand All @@ -902,7 +902,7 @@ public function testValidClassAndMethodPair( $pair, $is_valid ) {
$this->assertEquals( $is_valid, Utils\is_valid_class_and_method_pair( $pair ) );
}

public function dataValidClassAndMethodPair() {
public static function dataValidClassAndMethodPair() {
return [
[ 'string', false ],
[ [], false ],
Expand Down
2 changes: 1 addition & 1 deletion tests/test-wp-cli.php → tests/WPCLITest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

use WP_CLI\Tests\TestCase;

class WP_CLI_Test extends TestCase {
class WPCLITest extends TestCase {

public function testGetPHPBinary() {
$this->assertSame( WP_CLI\Utils\get_php_binary(), WP_CLI::get_php_binary() );
Expand Down
File renamed without changes.

0 comments on commit cbe7b57

Please sign in to comment.