Skip to content

Commit 2ae618e

Browse files
author
Craig Manley
committed
Update unit tests to support phpunit 6
1 parent 8579fdc commit 2ae618e

File tree

4 files changed

+32
-28
lines changed

4 files changed

+32
-28
lines changed

Diff for: t/Spec.t.php

+14-13
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
11
<?php
2+
namespace PHPUnit\Framework;
23
if (isset($argv)) {
34
print "Usage:\n";
45
print 'phpunit ' . $argv[0] . "\n";
5-
class PHPUnit_Framework_TestCase {}
6+
class TestCase {}
67
}
78

89

9-
class Test extends PHPUnit_Framework_TestCase {
10+
class T extends TestCase {
1011

1112
const CLASS_NAME = 'Validate\\Spec';
1213
const FILE_NAME = '../src/Spec.php';
@@ -58,7 +59,7 @@ public function testCreate() {
5859
'default' => '[email protected]',
5960
'description' => 'Email address',
6061
'optional' => true,
61-
'validation' => new Validate\Validation(array(
62+
'validation' => new \Validate\Validation(array(
6263
'type' => 'string',
6364
'callback' => function($x) { return filter_var($x, FILTER_VALIDATE_EMAIL); },
6465
'mb_max_length' => 50,
@@ -70,12 +71,12 @@ public function testCreate() {
7071
}
7172

7273
public function testValidate() {
73-
$spec = new Validate\Spec(array(
74+
$spec = new \Validate\Spec(array(
7475
'allow_empty' => false,
7576
'before' => function(&$x) { if (is_string($x)) { $x = mb_strtolower($x); } },
7677
'after' => function(&$x) { if (is_string($x)) { $x = ucfirst($x); } },
7778
'description' => 'Email address',
78-
'validation' => new Validate\Validation(array(
79+
'validation' => new \Validate\Validation(array(
7980
'type' => 'string',
8081
'callbacks' => array(
8182
'syntax' => function($x) { return filter_var($x, FILTER_VALIDATE_EMAIL); },
@@ -126,12 +127,12 @@ public function testValidate() {
126127
}
127128

128129
public function testValidateWithDefault() {
129-
$spec = new Validate\Spec(array(
130+
$spec = new \Validate\Spec(array(
130131
'allow_empty' => false,
131132
'after' => function(&$x) { $x = mb_strtolower($x); },
132133
'description' => 'Email address',
133134
'default' => 'nobody', # defaults aren't validated as they are trusted values
134-
'validation' => new Validate\Validation(array(
135+
'validation' => new \Validate\Validation(array(
135136
'type' => 'string',
136137
'callbacks' => array(
137138
'syntax' => function($x) { return filter_var($x, FILTER_VALIDATE_EMAIL); },
@@ -170,21 +171,21 @@ public function testValidateWithDefault() {
170171

171172
public function testReturnValuesBeforeAfter() {
172173
foreach (array('before', 'after') as $when) {
173-
$spec = new Validate\Spec(array(
174+
$spec = new \Validate\Spec(array(
174175
$when => function(&$x) {}, # void (null) result
175176
));
176177
$input = 'anything';
177178
$this->assertTrue($spec->validate($input), "Using callback '$when' with void return value validates as true.");
178179
$this->assertEquals(null, $spec->getLastFailure(), 'Check last failure');
179180

180-
$spec = new Validate\Spec(array(
181+
$spec = new \Validate\Spec(array(
181182
$when => function(&$x) { return false; },
182183
));
183184
$input = 'anything';
184185
$this->assertTrue(!$spec->validate($input), "Using callback '$when' with FALSE return value validates as FALSE.");
185186
$this->assertEquals("callback $when", $spec->getLastFailure(), 'Check last failure');
186187

187-
$spec = new Validate\Spec(array(
188+
$spec = new \Validate\Spec(array(
188189
$when => function(&$x) { $x = strtoupper($x); return true; },
189190
));
190191
$input = 'anything';
@@ -198,14 +199,14 @@ public function testReturnValuesBeforeAfter() {
198199

199200

200201
if (isset($argv)) {
201-
require_once(__DIR__ . '/' . Test::FILE_NAME);
202+
require_once(__DIR__ . '/' . T::FILE_NAME);
202203
if (1) {
203-
$spec = new Validate\Spec(array(
204+
$spec = new \Validate\Spec(array(
204205
'allow_empty' => false,
205206
'before' => function(&$x) { if (is_string($x)) { $x = mb_strtolower($x); } },
206207
'after' => function(&$x) { if (is_string($x)) { $x = ucfirst($x); } },
207208
'description' => 'Email address',
208-
'validation' => new Validate\Validation(array(
209+
'validation' => new \Validate\Validation(array(
209210
'type' => 'string',
210211
'callbacks' => array(
211212
'syntax' => function($x) { return filter_var($x, FILTER_VALIDATE_EMAIL); },

Diff for: t/SpecCollection.t.php

+6-5
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
11
<?php
2+
namespace PHPUnit\Framework;
23
if (isset($argv)) {
34
print "Usage:\n";
45
print 'phpunit ' . $argv[0] . "\n";
5-
class PHPUnit_Framework_TestCase {}
6+
class TestCase {}
67
}
78

89

9-
class Test extends PHPUnit_Framework_TestCase {
10+
class T extends TestCase {
1011

1112
const CLASS_NAME = 'Validate\\SpecCollection';
1213
const FILE_NAME = '../src/SpecCollection.php';
@@ -131,7 +132,7 @@ public function testValidate() {
131132
'expect' => true,
132133
),
133134
);
134-
$specs = new Validate\SpecCollection(array(
135+
$specs = new \Validate\SpecCollection(array(
135136
'firstname' => array(
136137
'description' => 'First name',
137138
'mb_max_length' => 10,
@@ -166,7 +167,7 @@ public function testValidate() {
166167

167168

168169
if (isset($argv)) {
169-
require_once(__DIR__ . '/' . Test::FILE_NAME);
170+
require_once(__DIR__ . '/' . T::FILE_NAME);
170171
if (1) {
171172
$tests = array(
172173
array(
@@ -219,7 +220,7 @@ public function testValidate() {
219220
'expect' => true,
220221
),
221222
);
222-
$specs = new Validate\SpecCollection(array(
223+
$specs = new \Validate\SpecCollection(array(
223224
'firstname' => array(
224225
'description' => 'First name',
225226
'mb_max_length' => 10,

Diff for: t/Validation.t.php

+4-3
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
11
<?php
2+
namespace PHPUnit\Framework;
23
if (isset($argv)) {
34
print "Usage:\n";
45
print 'phpunit ' . $argv[0] . "\n";
5-
class PHPUnit_Framework_TestCase {}
6+
class TestCase {}
67
}
78

89

9-
class Test extends PHPUnit_Framework_TestCase {
10+
class T extends TestCase {
1011

1112
const CLASS_NAME = 'Validate\\Validation';
1213
const FILE_NAME = '../src/Validation.php';
@@ -67,7 +68,7 @@ public function testCreate() {
6768
}
6869

6970
public function testValidate() {
70-
$validation = new Validate\Validation(array(
71+
$validation = new \Validate\Validation(array(
7172
'callbacks' => array(
7273
'is_lc' => function($s) { return mb_strtolower($s) == $s; },
7374
),

Diff for: t/Validator.t.php

+8-7
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
11
<?php
2+
namespace PHPUnit\Framework;
23
if (isset($argv)) {
34
print "Usage:\n";
45
print 'phpunit ' . $argv[0] . "\n";
5-
class PHPUnit_Framework_TestCase {}
6+
class TestCase {}
67
}
78

89

9-
class Test extends PHPUnit_Framework_TestCase {
10+
class T extends TestCase {
1011

1112
const CLASS_NAME = 'Validate\\Validator';
1213
const FILE_NAME = '../src/Validator.php';
@@ -105,7 +106,7 @@ public function testValidate() {
105106
'min_value' => 0,
106107
),
107108
);
108-
$validator = new Validate\Validator(array(
109+
$validator = new \Validate\Validator(array(
109110
'allow_extra' => false,
110111
'delete_null' => true,
111112
'null_empty_strings' => true,
@@ -159,7 +160,7 @@ public function testValidate() {
159160
try {
160161
$validated_input = $validator->validate($input);
161162
}
162-
catch (Validate\Exception\ValidationException $e) {
163+
catch (\Validate\Exception\ValidationException $e) {
163164
$got_exception = $e->getMessage();
164165
}
165166
$this->assertEquals($expect, $validated_input, "Test $i validate() returns expected result.");
@@ -332,7 +333,7 @@ public function testValidatePosSpecCollection() {
332333
foreach ($tests as $name => $test) {
333334
$args = $test['options'];
334335
$args['specs'] = $specs;
335-
$validator = new Validate\Validator($args);
336+
$validator = new \Validate\Validator($args);
336337
foreach ($inputs as $input_name => $input) {
337338
$expect = $test['expects'][$input_name]['expect'];
338339
$expect_exception = $test['expects'][$input_name]['expect_exception'];
@@ -341,7 +342,7 @@ public function testValidatePosSpecCollection() {
341342
try {
342343
$validated_input = $validator->validate_pos($input);
343344
}
344-
catch (Validate\Exception\ValidationException $e) {
345+
catch (\Validate\Exception\ValidationException $e) {
345346
$got_exception = $e->getMessage();
346347
}
347348
$this->assertEquals($expect, $validated_input, "Test \"$name\"->\"$input_name\" validate() returns expected result.");
@@ -355,5 +356,5 @@ public function testValidatePosSpecCollection() {
355356

356357

357358
if (isset($argv)) {
358-
require_once(Test::FILE_NAME);
359+
require_once(T::FILE_NAME);
359360
}

0 commit comments

Comments
 (0)