1
1
<?php
2
+ namespace PHPUnit \Framework ;
2
3
if (isset ($ argv )) {
3
4
print "Usage: \n" ;
4
5
print 'phpunit ' . $ argv [0 ] . "\n" ;
5
- class PHPUnit_Framework_TestCase {}
6
+ class TestCase {}
6
7
}
7
8
8
9
9
- class Test extends PHPUnit_Framework_TestCase {
10
+ class T extends TestCase {
10
11
11
12
const CLASS_NAME = 'Validate \\Spec ' ;
12
13
const FILE_NAME = '../src/Spec.php ' ;
@@ -58,7 +59,7 @@ public function testCreate() {
58
59
59
60
'description ' => 'Email address ' ,
60
61
'optional ' => true ,
61
- 'validation ' => new Validate \Validation (array (
62
+ 'validation ' => new \ Validate \Validation (array (
62
63
'type ' => 'string ' ,
63
64
'callback ' => function ($ x ) { return filter_var ($ x , FILTER_VALIDATE_EMAIL ); },
64
65
'mb_max_length ' => 50 ,
@@ -70,12 +71,12 @@ public function testCreate() {
70
71
}
71
72
72
73
public function testValidate () {
73
- $ spec = new Validate \Spec (array (
74
+ $ spec = new \ Validate \Spec (array (
74
75
'allow_empty ' => false ,
75
76
'before ' => function (&$ x ) { if (is_string ($ x )) { $ x = mb_strtolower ($ x ); } },
76
77
'after ' => function (&$ x ) { if (is_string ($ x )) { $ x = ucfirst ($ x ); } },
77
78
'description ' => 'Email address ' ,
78
- 'validation ' => new Validate \Validation (array (
79
+ 'validation ' => new \ Validate \Validation (array (
79
80
'type ' => 'string ' ,
80
81
'callbacks ' => array (
81
82
'syntax ' => function ($ x ) { return filter_var ($ x , FILTER_VALIDATE_EMAIL ); },
@@ -126,12 +127,12 @@ public function testValidate() {
126
127
}
127
128
128
129
public function testValidateWithDefault () {
129
- $ spec = new Validate \Spec (array (
130
+ $ spec = new \ Validate \Spec (array (
130
131
'allow_empty ' => false ,
131
132
'after ' => function (&$ x ) { $ x = mb_strtolower ($ x ); },
132
133
'description ' => 'Email address ' ,
133
134
'default ' => 'nobody ' , # defaults aren't validated as they are trusted values
134
- 'validation ' => new Validate \Validation (array (
135
+ 'validation ' => new \ Validate \Validation (array (
135
136
'type ' => 'string ' ,
136
137
'callbacks ' => array (
137
138
'syntax ' => function ($ x ) { return filter_var ($ x , FILTER_VALIDATE_EMAIL ); },
@@ -170,21 +171,21 @@ public function testValidateWithDefault() {
170
171
171
172
public function testReturnValuesBeforeAfter () {
172
173
foreach (array ('before ' , 'after ' ) as $ when ) {
173
- $ spec = new Validate \Spec (array (
174
+ $ spec = new \ Validate \Spec (array (
174
175
$ when => function (&$ x ) {}, # void (null) result
175
176
));
176
177
$ input = 'anything ' ;
177
178
$ this ->assertTrue ($ spec ->validate ($ input ), "Using callback ' $ when' with void return value validates as true. " );
178
179
$ this ->assertEquals (null , $ spec ->getLastFailure (), 'Check last failure ' );
179
180
180
- $ spec = new Validate \Spec (array (
181
+ $ spec = new \ Validate \Spec (array (
181
182
$ when => function (&$ x ) { return false ; },
182
183
));
183
184
$ input = 'anything ' ;
184
185
$ this ->assertTrue (!$ spec ->validate ($ input ), "Using callback ' $ when' with FALSE return value validates as FALSE. " );
185
186
$ this ->assertEquals ("callback $ when " , $ spec ->getLastFailure (), 'Check last failure ' );
186
187
187
- $ spec = new Validate \Spec (array (
188
+ $ spec = new \ Validate \Spec (array (
188
189
$ when => function (&$ x ) { $ x = strtoupper ($ x ); return true ; },
189
190
));
190
191
$ input = 'anything ' ;
@@ -198,14 +199,14 @@ public function testReturnValuesBeforeAfter() {
198
199
199
200
200
201
if (isset ($ argv )) {
201
- require_once (__DIR__ . '/ ' . Test ::FILE_NAME );
202
+ require_once (__DIR__ . '/ ' . T ::FILE_NAME );
202
203
if (1 ) {
203
- $ spec = new Validate \Spec (array (
204
+ $ spec = new \ Validate \Spec (array (
204
205
'allow_empty ' => false ,
205
206
'before ' => function (&$ x ) { if (is_string ($ x )) { $ x = mb_strtolower ($ x ); } },
206
207
'after ' => function (&$ x ) { if (is_string ($ x )) { $ x = ucfirst ($ x ); } },
207
208
'description ' => 'Email address ' ,
208
- 'validation ' => new Validate \Validation (array (
209
+ 'validation ' => new \ Validate \Validation (array (
209
210
'type ' => 'string ' ,
210
211
'callbacks ' => array (
211
212
'syntax ' => function ($ x ) { return filter_var ($ x , FILTER_VALIDATE_EMAIL ); },
0 commit comments