4
4
5
5
class VerbalExpressionsTest extends \PHPUnit_Framework_TestCase
6
6
{
7
+ /**
8
+ * @dataProvider provideValidUrls
9
+ * @group functional
10
+ */
11
+ public function testShouldPassWhenValidUrlGiven ($ url )
12
+ {
13
+ $ regex = new VerbalExpressions ();
14
+ $ this ->buildUrlPattern ($ regex );
15
+
16
+ $ this ->assertTrue ($ regex ->test ($ url ));
17
+ }
18
+
19
+ static public function provideValidUrls ()
20
+ {
21
+ return array (
22
+ array ('http://github.com ' ),
23
+ array ('http://www.github.com ' ),
24
+ array ('https://github.com ' ),
25
+ array ('https://github.com ' ),
26
+ array ('https://github.com/blog ' ),
27
+ array ('https://foobar.github.com ' )
28
+ );
29
+ }
7
30
8
31
/**
9
- * @dataProvider provideUrls
32
+ * @dataProvider provideInvalidUrls
33
+ * @group functional
10
34
*/
11
- public function testUrlPatterns ($ url )
35
+ public function testShouldFailWithInvalidUrls ($ url )
12
36
{
13
37
$ regex = new VerbalExpressions ();
38
+ $ this ->buildUrlPattern ($ regex );
39
+
40
+ $ this ->assertFalse ($ regex ->test ($ url ));
41
+ }
14
42
15
- $ regex ->startOfLine ()
43
+ static public function provideInvalidUrls ()
44
+ {
45
+ return array (
46
+ array (' http://github.com ' ),
47
+ array ('foo ' ),
48
+ array ('htps://github.com ' ),
49
+ array ('http:/github.com ' ),
50
+ array ('https://github.com /blog ' ),
51
+ );
52
+ }
53
+
54
+ protected function buildUrlPattern (VerbalExpressions $ regex )
55
+ {
56
+ return $ regex ->startOfLine ()
16
57
->then ("http " )
17
58
->maybe ("s " )
18
59
->then (":// " )
19
60
->maybe ("www. " )
20
61
->anythingBut (" " )
21
62
->endOfLine ();
22
-
23
- $ this ->assertTrue ($ regex ->test ($ url ));
24
- }
25
-
26
- static public function provideUrls ()
27
- {
28
- return array (
29
- array ('http://github.com ' )
30
- );
31
63
}
32
- }
64
+ }
0 commit comments