Skip to content

Commit 2d1da47

Browse files
authored
Merge pull request #172 from wp-cli/fix/unit-tests
Fix unit tests
2 parents a6bb946 + 8a56070 commit 2d1da47

11 files changed

+50
-63
lines changed

.travis.yml

Lines changed: 0 additions & 26 deletions
This file was deleted.

README.md

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,11 @@
11
PHP Command Line Tools
22
======================
33

4-
[![Build Status](https://travis-ci.org/wp-cli/php-cli-tools.png?branch=master)](https://travis-ci.org/wp-cli/php-cli-tools)
5-
64
A collection of functions and classes to assist with command line development.
75

86
Requirements
97

10-
* PHP >= 5.3
8+
* PHP >= 5.6
119

1210
Suggested PHP extensions
1311

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
}
1919
],
2020
"require": {
21-
"php": ">= 5.3.0"
21+
"php": ">= 5.6.0"
2222
},
2323
"require-dev": {
2424
"roave/security-advisories": "dev-latest",

phpunit.xml.dist

Lines changed: 18 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,20 @@
11
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
2-
xsi:noNamespaceSchemaLocation="http://schema.phpunit.de/4.8/phpunit.xsd"
3-
bootstrap="tests/bootstrap.php"
4-
colors="always"
5-
beStrictAboutTestsThatDoNotTestAnything="true"
6-
beStrictAboutOutputDuringTests="true"
7-
beStrictAboutTestSize="true"
8-
beStrictAboutChangesToGlobalState="false">
9-
<testsuites>
10-
<testsuite>
11-
<directory prefix="spec-" suffix=".php">tests/</directory>
12-
<directory prefix="test-" suffix=".php">tests/</directory>
13-
<directory suffix="Test.php">tests/</directory>
14-
</testsuite>
15-
</testsuites>
2+
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/4.8/phpunit.xsd"
3+
bootstrap="tests/bootstrap.php"
4+
backupGlobals="false"
5+
beStrictAboutCoversAnnotation="true"
6+
beStrictAboutOutputDuringTests="true"
7+
beStrictAboutTestsThatDoNotTestAnything="true"
8+
beStrictAboutTodoAnnotatedTests="true"
9+
colors="true"
10+
verbose="true">
11+
<testsuite name="wp-cli/php-cli-tools tests">
12+
<directory prefix="Test" suffix=".php">tests/</directory>
13+
</testsuite>
14+
15+
<filter>
16+
<whitelist processUncoveredFilesFromWhitelist="true">
17+
<directory suffix=".php">lib/</directory>
18+
</whitelist>
19+
</filter>
1620
</phpunit>

tests/test-arguments.php renamed to tests/Test_Arguments.php

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,12 @@
44
use WP_CLI\Tests\TestCase;
55

66
/**
7-
* Class TestArguments
7+
* Class Test_Arguments
88
* @todo add more tests to increase coverage
99
*
1010
* @backupGlobals enabled
1111
*/
12-
class TestArguments extends TestCase
12+
class Test_Arguments extends TestCase
1313
{
1414
/**
1515
* Array of expected settings
@@ -91,6 +91,13 @@ public function set_up()
9191
'flags' => $this->flags,
9292
'options' => $this->options
9393
);
94+
95+
set_error_handler(
96+
static function ( $errno, $errstr ) {
97+
throw new \Exception( $errstr, $errno );
98+
},
99+
E_ALL
100+
);
94101
}
95102

96103
/**
@@ -102,6 +109,7 @@ public function tear_down()
102109
$this->options = null;
103110
$this->settings = null;
104111
self::clearArgv();
112+
restore_error_handler();
105113
}
106114

107115
/**
@@ -151,7 +159,7 @@ public function testAddOptions()
151159
*
152160
* @return array set of args and expected parsed values
153161
*/
154-
public function settingsWithValidOptions()
162+
public static function settingsWithValidOptions()
155163
{
156164
return array(
157165
array(
@@ -174,7 +182,7 @@ public function settingsWithValidOptions()
174182
*
175183
* @return array set of args and expected parsed values
176184
*/
177-
public function settingsWithMissingOptions()
185+
public static function settingsWithMissingOptions()
178186
{
179187
return array(
180188
array(
@@ -193,7 +201,7 @@ public function settingsWithMissingOptions()
193201
*
194202
* @return array set of args and expected parsed values
195203
*/
196-
public function settingsWithMissingOptionsWithDefault()
204+
public static function settingsWithMissingOptionsWithDefault()
197205
{
198206
return array(
199207
array(
@@ -207,7 +215,7 @@ public function settingsWithMissingOptionsWithDefault()
207215
);
208216
}
209217

210-
public function settingsWithNoOptionsWithDefault()
218+
public static function settingsWithNoOptionsWithDefault()
211219
{
212220
return array(
213221
array(
@@ -259,8 +267,8 @@ public function testParseWithValidOptions($cliParams, $expectedValues)
259267
*/
260268
public function testParseWithMissingOptions($cliParams, $expectedValues)
261269
{
262-
$this->expectWarning();
263-
$this->expectWarningMessage('no value given for --option1');
270+
$this->expectException(\Exception::class);
271+
$this->expectExceptionMessage('no value given for --option1');
264272
$this->_testParse($cliParams, $expectedValues);
265273
}
266274

tests/test-cli.php renamed to tests/Test_Cli.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@
22

33
use cli\Colors;
44
use WP_CLI\Tests\TestCase;
5-
class testsCli extends TestCase {
5+
6+
class Test_Cli extends TestCase {
67

78
function set_up() {
89
// Reset enable state

tests/test-colors.php renamed to tests/Test_Colors.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,12 @@
33
use cli\Colors;
44
use WP_CLI\Tests\TestCase;
55

6-
class testsColors extends TestCase {
6+
class Test_Colors extends TestCase {
77

88
/**
99
* @dataProvider dataColors
10-
*/
11-
function testColors( $str, $color ) {
10+
*/
11+
public function testColors( $str, $color ) {
1212
// Colors enabled.
1313
Colors::enable( true );
1414

@@ -21,7 +21,7 @@ function testColors( $str, $color ) {
2121
}
2222
}
2323

24-
function dataColors() {
24+
public static function dataColors() {
2525
$ret = array();
2626
foreach ( Colors::getColors() as $str => $color ) {
2727
$ret[] = array( $str, $color );

tests/test-shell.php renamed to tests/Test_Shell.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@
44
use WP_CLI\Tests\TestCase;
55

66
/**
7-
* Class TestShell
7+
* Class Test_Shell
88
*/
9-
class TestShell extends TestCase {
9+
class Test_Shell extends TestCase {
1010

1111
/**
1212
* Test getting TERM columns.

tests/test-table.php renamed to tests/Test_Table.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
<?php
22

3-
use cli\Colors, cli\Table, cli\Table\Ascii;
3+
use cli\Colors;
4+
use cli\Table;
5+
use cli\Table\Ascii;
46
use WP_CLI\Tests\TestCase;
57

68
/**

tests/test-table-ascii.php renamed to tests/Test_Table_Ascii.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
<?php
22

3+
use cli\Colors;
34
use cli\Streams;
45
use cli\Table;
56
use cli\table\Ascii;
6-
use cli\Colors;
77
use WP_CLI\Tests\TestCase;
88

99
/**

tests/bootstrap.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ function cli_autoload( $className ) {
66
$fileName = '';
77
$namespace = '';
88
if ($lastNsPos = strrpos($className, '\\')) {
9-
$namespace = substr($className, 0, $lastNsPos);
9+
$namespace = strtolower(substr($className, 0, $lastNsPos));
1010
$className = substr($className, $lastNsPos + 1);
1111
$fileName = str_replace('\\', DIRECTORY_SEPARATOR, $namespace) . DIRECTORY_SEPARATOR;
1212
}
@@ -16,7 +16,7 @@ function cli_autoload( $className ) {
1616
return;
1717
}
1818

19-
require dirname( dirname( __FILE__ ) ) . '/lib/' . $fileName;
19+
require dirname( __DIR__ ) . '/lib/' . $fileName;
2020
}
2121

2222
spl_autoload_register( 'cli_autoload' );

0 commit comments

Comments
 (0)