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,9 @@ class MatcherTest extends \PHPUnit_Framework_TestCase
13
14
*/
14
15
protected $ matcher ;
15
16
16
- protected $ arrayValue ;
17
-
17
+ /**
18
+ * @var Matcher\CaptureMatcher
19
+ */
18
20
protected $ captureMatcher ;
19
21
20
22
public function setUp ()
@@ -67,7 +69,7 @@ public function test_matcher_with_array_value()
67
69
'data ' => new \stdClass (),
68
70
);
69
71
70
- $ expecation = array (
72
+ $ expectation = array (
71
73
'users ' => array (
72
74
array (
73
75
'id ' => '@integer@ ' ,
@@ -86,25 +88,17 @@ public function test_matcher_with_array_value()
86
88
'data ' => '@wildcard@ ' ,
87
89
);
88
90
89
- $ this ->assertTrue ($ this ->matcher ->match ($ value , $ expecation ), $ this ->matcher ->getError ());
91
+ $ this ->assertTrue ($ this ->matcher ->match ($ value , $ expectation ), $ this ->matcher ->getError ());
92
+ $ this ->assertTrue (PHPMatcher::match ($ value , $ expectation ), PHPMatcher::getError ());
90
93
}
91
94
92
95
/**
93
- * @dataProvider scalarValues
96
+ * @dataProvider scalarValueExamples
94
97
*/
95
98
public function test_matcher_with_scalar_values ($ value , $ pattern )
96
99
{
97
100
$ this ->assertTrue ($ this ->matcher ->match ($ value , $ pattern ));
98
- }
99
-
100
- public function scalarValues ()
101
- {
102
- return array (
103
- array ('Norbert Orzechowicz ' , '@string@ ' ),
104
- array (6.66 , '@double@ ' ),
105
- array (1 , '@integer@ ' ),
106
- array (array ('foo ' ), '@array@ ' )
107
- );
101
+ $ this ->assertTrue (PHPMatcher::match ($ value , $ pattern ));
108
102
}
109
103
110
104
public function test_matcher_with_json ()
@@ -153,6 +147,7 @@ public function test_matcher_with_json()
153
147
} ' ;
154
148
155
149
$ this ->assertTrue ($ this ->matcher ->match ($ json , $ jsonPattern ));
150
+ $ this ->assertTrue (PHPMatcher::match ($ json , $ jsonPattern ));
156
151
}
157
152
158
153
public function test_matcher_with_xml ()
@@ -189,13 +184,15 @@ public function test_matcher_with_xml()
189
184
XML ;
190
185
191
186
$ this ->assertTrue ($ this ->matcher ->match ($ xml , $ xmlPattern ));
187
+ $ this ->assertTrue (PHPMatcher::match ($ xml , $ xmlPattern ));
192
188
}
193
189
194
190
public function test_text_matcher ()
195
191
{
196
192
$ value = "lorem ipsum 1234 random text " ;
197
193
$ pattern =
"@[email protected] ('lo') ipsum @[email protected] (10) random text " ;
198
194
$ this ->assertTrue ($ this ->matcher ->match ($ value , $ pattern ));
195
+ $ this ->assertTrue (PHPMatcher::match ($ value , $ pattern ));
199
196
}
200
197
201
198
@@ -206,6 +203,9 @@ public function test_error_when_json_value_does_not_match_json_pattern()
206
203
207
204
$ this ->assertFalse ($ this ->matcher ->match ($ value , $ pattern ));
208
205
$ this ->assertSame ('"5" does not match "4". ' , $ this ->matcher ->getError ());
206
+
207
+ $ this ->assertFalse (PHPMatcher::match ($ value , $ pattern ));
208
+ $ this ->assertSame ('"5" does not match "4". ' , PHPMatcher::getError ());
209
209
}
210
210
211
211
public function test_matcher_with_captures ()
@@ -220,13 +220,17 @@ public function test_matcher_with_captures()
220
220
public function test_matcher_with_callback ()
221
221
{
222
222
$ this ->assertTrue ($ this ->matcher ->match ('test ' , function ($ value ) { return $ value === 'test ' ;}));
223
+ $ this ->assertTrue (PHPMatcher::match ('test ' , function ($ value ) { return $ value === 'test ' ;}));
223
224
$ this ->assertFalse ($ this ->matcher ->match ('test ' , function ($ value ) { return $ value !== 'test ' ;}));
225
+ $ this ->assertFalse (PHPMatcher::match ('test ' , function ($ value ) { return $ value !== 'test ' ;}));
224
226
}
225
227
226
228
public function test_matcher_with_wildcard ()
227
229
{
228
230
$ this ->assertTrue ($ this ->matcher ->match ('test ' , '@*@ ' ));
231
+ $ this ->assertTrue (PHPMatcher::match ('test ' , '@*@ ' ));
229
232
$ this ->assertTrue ($ this ->matcher ->match ('test ' , '@wildcard@ ' ));
233
+ $ this ->assertTrue (PHPMatcher::match ('test ' , '@wildcard@ ' ));
230
234
}
231
235
232
236
/**
@@ -235,8 +239,19 @@ public function test_matcher_with_wildcard()
235
239
public function test_expanders ($ value , $ pattern , $ expectedResult )
236
240
{
237
241
$ this ->assertSame ($ expectedResult , $ this ->matcher ->match ($ value , $ pattern ));
242
+ $ this ->assertSame ($ expectedResult , PHPMatcher::match ($ value , $ pattern ));
238
243
}
239
244
245
+ public function scalarValueExamples ()
246
+ {
247
+ return array (
248
+ array ('Norbert Orzechowicz ' , '@string@ ' ),
249
+ array (6.66 , '@double@ ' ),
250
+ array (1 , '@integer@ ' ),
251
+ array (array ('foo ' ), '@array@ ' )
252
+ );
253
+ }
254
+
240
255
public static function expanderExamples ()
241
256
{
242
257
return array (
0 commit comments