Skip to content

Commit

Permalink
Merge pull request #172 from wp-cli/fix/unit-tests
Browse files Browse the repository at this point in the history
Fix unit tests
  • Loading branch information
swissspidy authored May 22, 2024
2 parents a6bb946 + 8a56070 commit 2d1da47
Show file tree
Hide file tree
Showing 11 changed files with 50 additions and 63 deletions.
26 changes: 0 additions & 26 deletions .travis.yml

This file was deleted.

4 changes: 1 addition & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
PHP Command Line Tools
======================

[![Build Status](https://travis-ci.org/wp-cli/php-cli-tools.png?branch=master)](https://travis-ci.org/wp-cli/php-cli-tools)

A collection of functions and classes to assist with command line development.

Requirements

* PHP >= 5.3
* PHP >= 5.6

Suggested PHP extensions

Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
}
],
"require": {
"php": ">= 5.3.0"
"php": ">= 5.6.0"
},
"require-dev": {
"roave/security-advisories": "dev-latest",
Expand Down
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/php-cli-tools tests">
<directory prefix="Test" suffix=".php">tests/</directory>
</testsuite>

<filter>
<whitelist processUncoveredFilesFromWhitelist="true">
<directory suffix=".php">lib/</directory>
</whitelist>
</filter>
</phpunit>
24 changes: 16 additions & 8 deletions tests/test-arguments.php → tests/Test_Arguments.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@
use WP_CLI\Tests\TestCase;

/**
* Class TestArguments
* Class Test_Arguments
* @todo add more tests to increase coverage
*
* @backupGlobals enabled
*/
class TestArguments extends TestCase
class Test_Arguments extends TestCase
{
/**
* Array of expected settings
Expand Down Expand Up @@ -91,6 +91,13 @@ public function set_up()
'flags' => $this->flags,
'options' => $this->options
);

set_error_handler(
static function ( $errno, $errstr ) {
throw new \Exception( $errstr, $errno );
},
E_ALL
);
}

/**
Expand All @@ -102,6 +109,7 @@ public function tear_down()
$this->options = null;
$this->settings = null;
self::clearArgv();
restore_error_handler();
}

/**
Expand Down Expand Up @@ -151,7 +159,7 @@ public function testAddOptions()
*
* @return array set of args and expected parsed values
*/
public function settingsWithValidOptions()
public static function settingsWithValidOptions()
{
return array(
array(
Expand All @@ -174,7 +182,7 @@ public function settingsWithValidOptions()
*
* @return array set of args and expected parsed values
*/
public function settingsWithMissingOptions()
public static function settingsWithMissingOptions()
{
return array(
array(
Expand All @@ -193,7 +201,7 @@ public function settingsWithMissingOptions()
*
* @return array set of args and expected parsed values
*/
public function settingsWithMissingOptionsWithDefault()
public static function settingsWithMissingOptionsWithDefault()
{
return array(
array(
Expand All @@ -207,7 +215,7 @@ public function settingsWithMissingOptionsWithDefault()
);
}

public function settingsWithNoOptionsWithDefault()
public static function settingsWithNoOptionsWithDefault()
{
return array(
array(
Expand Down Expand Up @@ -259,8 +267,8 @@ public function testParseWithValidOptions($cliParams, $expectedValues)
*/
public function testParseWithMissingOptions($cliParams, $expectedValues)
{
$this->expectWarning();
$this->expectWarningMessage('no value given for --option1');
$this->expectException(\Exception::class);
$this->expectExceptionMessage('no value given for --option1');
$this->_testParse($cliParams, $expectedValues);
}

Expand Down
3 changes: 2 additions & 1 deletion tests/test-cli.php → tests/Test_Cli.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@

use cli\Colors;
use WP_CLI\Tests\TestCase;
class testsCli extends TestCase {

class Test_Cli extends TestCase {

function set_up() {
// Reset enable state
Expand Down
8 changes: 4 additions & 4 deletions tests/test-colors.php → tests/Test_Colors.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@
use cli\Colors;
use WP_CLI\Tests\TestCase;

class testsColors extends TestCase {
class Test_Colors extends TestCase {

/**
* @dataProvider dataColors
*/
function testColors( $str, $color ) {
*/
public function testColors( $str, $color ) {
// Colors enabled.
Colors::enable( true );

Expand All @@ -21,7 +21,7 @@ function testColors( $str, $color ) {
}
}

function dataColors() {
public static function dataColors() {
$ret = array();
foreach ( Colors::getColors() as $str => $color ) {
$ret[] = array( $str, $color );
Expand Down
4 changes: 2 additions & 2 deletions tests/test-shell.php → tests/Test_Shell.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@
use WP_CLI\Tests\TestCase;

/**
* Class TestShell
* Class Test_Shell
*/
class TestShell extends TestCase {
class Test_Shell extends TestCase {

/**
* Test getting TERM columns.
Expand Down
4 changes: 3 additions & 1 deletion tests/test-table.php → tests/Test_Table.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
<?php

use cli\Colors, cli\Table, cli\Table\Ascii;
use cli\Colors;
use cli\Table;
use cli\Table\Ascii;
use WP_CLI\Tests\TestCase;

/**
Expand Down
2 changes: 1 addition & 1 deletion tests/test-table-ascii.php → tests/Test_Table_Ascii.php
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
<?php

use cli\Colors;
use cli\Streams;
use cli\Table;
use cli\table\Ascii;
use cli\Colors;
use WP_CLI\Tests\TestCase;

/**
Expand Down
4 changes: 2 additions & 2 deletions tests/bootstrap.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ function cli_autoload( $className ) {
$fileName = '';
$namespace = '';
if ($lastNsPos = strrpos($className, '\\')) {
$namespace = substr($className, 0, $lastNsPos);
$namespace = strtolower(substr($className, 0, $lastNsPos));
$className = substr($className, $lastNsPos + 1);
$fileName = str_replace('\\', DIRECTORY_SEPARATOR, $namespace) . DIRECTORY_SEPARATOR;
}
Expand All @@ -16,7 +16,7 @@ function cli_autoload( $className ) {
return;
}

require dirname( dirname( __FILE__ ) ) . '/lib/' . $fileName;
require dirname( __DIR__ ) . '/lib/' . $fileName;
}

spl_autoload_register( 'cli_autoload' );

0 comments on commit 2d1da47

Please sign in to comment.