5
5
use Coduo \PHPMatcher \Lexer ;
6
6
use Coduo \PHPMatcher \Matcher ;
7
7
use Coduo \PHPMatcher \Parser ;
8
+ use Coduo \PHPMatcher \PHPMatcher ;
8
9
9
10
class MatcherTest extends \PHPUnit_Framework_TestCase
10
11
{
@@ -13,8 +14,6 @@ class MatcherTest extends \PHPUnit_Framework_TestCase
13
14
*/
14
15
protected $ matcher ;
15
16
16
- protected $ arrayValue ;
17
-
18
17
public function setUp ()
19
18
{
20
19
$ parser = new Parser (new Lexer (), new Parser \ExpanderInitializer ());
@@ -63,7 +62,7 @@ public function test_matcher_with_array_value()
63
62
'data ' => new \stdClass (),
64
63
);
65
64
66
- $ expecation = array (
65
+ $ expectation = array (
67
66
'users ' => array (
68
67
array (
69
68
'id ' => '@integer@ ' ,
@@ -82,25 +81,17 @@ public function test_matcher_with_array_value()
82
81
'data ' => '@wildcard@ ' ,
83
82
);
84
83
85
- $ this ->assertTrue ($ this ->matcher ->match ($ value , $ expecation ), $ this ->matcher ->getError ());
84
+ $ this ->assertTrue ($ this ->matcher ->match ($ value , $ expectation ), $ this ->matcher ->getError ());
85
+ $ this ->assertTrue (PHPMatcher::match ($ value , $ expectation , $ error ), $ error );
86
86
}
87
87
88
88
/**
89
- * @dataProvider scalarValues
89
+ * @dataProvider scalarValueExamples
90
90
*/
91
91
public function test_matcher_with_scalar_values ($ value , $ pattern )
92
92
{
93
93
$ this ->assertTrue ($ this ->matcher ->match ($ value , $ pattern ));
94
- }
95
-
96
- public function scalarValues ()
97
- {
98
- return array (
99
- array ('Norbert Orzechowicz ' , '@string@ ' ),
100
- array (6.66 , '@double@ ' ),
101
- array (1 , '@integer@ ' ),
102
- array (array ('foo ' ), '@array@ ' )
103
- );
94
+ $ this ->assertTrue (PHPMatcher::match ($ value , $ pattern ));
104
95
}
105
96
106
97
public function test_matcher_with_json ()
@@ -149,6 +140,7 @@ public function test_matcher_with_json()
149
140
} ' ;
150
141
151
142
$ this ->assertTrue ($ this ->matcher ->match ($ json , $ jsonPattern ));
143
+ $ this ->assertTrue (PHPMatcher::match ($ json , $ jsonPattern ));
152
144
}
153
145
154
146
public function test_matcher_with_xml ()
@@ -185,13 +177,15 @@ public function test_matcher_with_xml()
185
177
XML ;
186
178
187
179
$ this ->assertTrue ($ this ->matcher ->match ($ xml , $ xmlPattern ));
180
+ $ this ->assertTrue (PHPMatcher::match ($ xml , $ xmlPattern ));
188
181
}
189
182
190
183
public function test_text_matcher ()
191
184
{
192
185
$ value = "lorem ipsum 1234 random text " ;
193
186
$ pattern =
"@[email protected] ('lo') ipsum @[email protected] (10) random text " ;
194
187
$ this ->assertTrue ($ this ->matcher ->match ($ value , $ pattern ));
188
+ $ this ->assertTrue (PHPMatcher::match ($ value , $ pattern ));
195
189
}
196
190
197
191
@@ -202,18 +196,25 @@ public function test_error_when_json_value_does_not_match_json_pattern()
202
196
203
197
$ this ->assertFalse ($ this ->matcher ->match ($ value , $ pattern ));
204
198
$ this ->assertSame ('"5" does not match "4". ' , $ this ->matcher ->getError ());
199
+
200
+ $ this ->assertFalse (PHPMatcher::match ($ value , $ pattern , $ error ));
201
+ $ this ->assertSame ('"5" does not match "4". ' , $ error );
205
202
}
206
203
207
204
public function test_matcher_with_callback ()
208
205
{
209
206
$ this ->assertTrue ($ this ->matcher ->match ('test ' , function ($ value ) { return $ value === 'test ' ;}));
207
+ $ this ->assertTrue (PHPMatcher::match ('test ' , function ($ value ) { return $ value === 'test ' ;}));
210
208
$ this ->assertFalse ($ this ->matcher ->match ('test ' , function ($ value ) { return $ value !== 'test ' ;}));
209
+ $ this ->assertFalse (PHPMatcher::match ('test ' , function ($ value ) { return $ value !== 'test ' ;}));
211
210
}
212
211
213
212
public function test_matcher_with_wildcard ()
214
213
{
215
214
$ this ->assertTrue ($ this ->matcher ->match ('test ' , '@*@ ' ));
215
+ $ this ->assertTrue (PHPMatcher::match ('test ' , '@*@ ' ));
216
216
$ this ->assertTrue ($ this ->matcher ->match ('test ' , '@wildcard@ ' ));
217
+ $ this ->assertTrue (PHPMatcher::match ('test ' , '@wildcard@ ' ));
217
218
}
218
219
219
220
/**
@@ -222,8 +223,19 @@ public function test_matcher_with_wildcard()
222
223
public function test_expanders ($ value , $ pattern , $ expectedResult )
223
224
{
224
225
$ this ->assertSame ($ expectedResult , $ this ->matcher ->match ($ value , $ pattern ));
226
+ $ this ->assertSame ($ expectedResult , PHPMatcher::match ($ value , $ pattern ));
225
227
}
226
228
229
+ public function scalarValueExamples ()
230
+ {
231
+ return array (
232
+ array ('Norbert Orzechowicz ' , '@string@ ' ),
233
+ array (6.66 , '@double@ ' ),
234
+ array (1 , '@integer@ ' ),
235
+ array (array ('foo ' ), '@array@ ' )
236
+ );
237
+ }
238
+
227
239
public static function expanderExamples ()
228
240
{
229
241
return array (
0 commit comments