Passed
Push — 1.0.0-dev ( 407604...83bedf )
by nguereza
03:26
created

RouterTest::testWithCustomConfigUsingAlphaPattern()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 12
Code Lines 10

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 10
nc 1
nop 0
dl 0
loc 12
rs 9.9332
c 0
b 0
f 0
1
<?php 
2
3
	use PHPUnit\Framework\TestCase;
4
5
	class RouterTest extends TestCase
6
	{	
7
	
8
		public static function setUpBeforeClass()
9
		{
10
		
11
		}
12
		
13
		public static function tearDownAfterClass()
14
		{
15
			
16
		}
17
		
18
		protected function setUp()
19
		{
20
		}
21
22
		protected function tearDown()
23
		{
24
		}
25
		
26
		public function testAutoUri()
27
		{
28
            //when application run in CLI the first argument will be used as route URI
29
            $_SERVER['argv'][1] = '';
30
            
31
            $r = new Router();
32
            //remove all all config
33
            $r->setRouteConfiguration(array(), false)
34
              ->setRouteUri()
35
              ->setRouteSegments()
36
              ->determineRouteParamsInformation();
37
38
            $this->assertNull($r->getController());
39
			$this->assertSame('index', $r->getMethod());
40
			$this->assertSame(0, count($r->getArgs()));
41
		}
42
        
43
        public function testCustomUri()
44
		{
45
            $r = new Router();
46
            $r->setRouteUri('users/profile/34/54')
47
              ->setRouteSegments()
48
              ->determineRouteParamsInformation();
49
            $this->assertSame('users', $r->getController());
50
			$this->assertSame('profile', $r->getMethod());
51
			$this->assertSame(2, count($r->getArgs()));
52
		}
53
        
54
        public function testWithCustomConfigControllerMethod()
55
		{
56
            $r = new Router();
57
            $r->add('/foo/bar', 'fooController@fooMethod')
0 ignored issues
show
Bug introduced by
'fooController@fooMethod' of type string is incompatible with the type object expected by parameter $callback of Router::add(). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

57
            $r->add('/foo/bar', /** @scrutinizer ignore-type */ 'fooController@fooMethod')
Loading history...
58
              ->setRouteUri('/foo/bar')
59
              ->setRouteSegments()
60
              ->determineRouteParamsInformation();
61
            $this->assertSame('fooController', $r->getController());
62
			$this->assertSame('fooMethod', $r->getMethod());
63
			$this->assertSame(0, count($r->getArgs()));
64
			$this->assertNull($r->getModule());
65
		}
66
        
67
        public function testWithCustomConfigModuleControllerMethod()
68
		{
69
            $r = new Router();
70
            $r->add('/foo/bar', 'fooModule#fooController@fooMethod')
0 ignored issues
show
Bug introduced by
'fooModule#fooController@fooMethod' of type string is incompatible with the type object expected by parameter $callback of Router::add(). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

70
            $r->add('/foo/bar', /** @scrutinizer ignore-type */ 'fooModule#fooController@fooMethod')
Loading history...
71
              ->setRouteUri('/foo/bar')
72
              ->setRouteSegments()
73
              ->determineRouteParamsInformation();
74
            $this->assertSame('fooController', $r->getController());
75
			$this->assertSame('fooMethod', $r->getMethod());
76
			$this->assertSame('fooModule', $r->getModule());
77
			$this->assertSame(0, count($r->getArgs()));
78
		}
79
        
80
        public function testWithCustomConfigUsingAnyPattern()
81
		{
82
            $r = new Router();
83
            $r->add('/foo/(:any)', 'fooController@fooMethod')
0 ignored issues
show
Bug introduced by
'fooController@fooMethod' of type string is incompatible with the type object expected by parameter $callback of Router::add(). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

83
            $r->add('/foo/(:any)', /** @scrutinizer ignore-type */ 'fooController@fooMethod')
Loading history...
84
              ->setRouteUri('/foo/bar123-baz')
85
              ->setRouteSegments()
86
              ->determineRouteParamsInformation();
87
            $this->assertSame('fooController', $r->getController());
88
			$this->assertSame('fooMethod', $r->getMethod());
89
			$this->assertSame(1, count($r->getArgs()));
90
            $args = $r->getArgs();
91
            $this->assertSame('bar123-baz', $args[0]);
92
		}
93
        
94
         public function testWithCustomConfigUsingNumericPattern()
95
		{
96
            $r = new Router();
97
            $r->add('/foo/(:num)', 'fooController@fooMethod')
0 ignored issues
show
Bug introduced by
'fooController@fooMethod' of type string is incompatible with the type object expected by parameter $callback of Router::add(). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

97
            $r->add('/foo/(:num)', /** @scrutinizer ignore-type */ 'fooController@fooMethod')
Loading history...
98
              ->setRouteUri('/foo/34')
99
              ->setRouteSegments()
100
              ->determineRouteParamsInformation();
101
            $this->assertSame('fooController', $r->getController());
102
			$this->assertSame('fooMethod', $r->getMethod());
103
			$this->assertSame(1, count($r->getArgs()));
104
            $args = $r->getArgs();
105
            $this->assertSame('34', $args[0]);
106
		}
107
        
108
        public function testWithCustomConfigUsingAlphaPattern()
109
		{
110
            $r = new Router();
111
            $r->add('/foo/(:alpha)', 'fooController@fooMethod')
0 ignored issues
show
Bug introduced by
'fooController@fooMethod' of type string is incompatible with the type object expected by parameter $callback of Router::add(). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

111
            $r->add('/foo/(:alpha)', /** @scrutinizer ignore-type */ 'fooController@fooMethod')
Loading history...
112
              ->setRouteUri('/foo/baz')
113
              ->setRouteSegments()
114
              ->determineRouteParamsInformation();
115
            $this->assertSame('fooController', $r->getController());
116
			$this->assertSame('fooMethod', $r->getMethod());
117
			$this->assertSame(1, count($r->getArgs()));
118
            $args = $r->getArgs();
119
            $this->assertSame('baz', $args[0]);
120
		}
121
        
122
        public function testWithCustomConfigUsingAlphaNumericPattern()
123
		{
124
            $r = new Router();
125
            $r->add('/foo/(:alnum)', 'fooController@fooMethod')
0 ignored issues
show
Bug introduced by
'fooController@fooMethod' of type string is incompatible with the type object expected by parameter $callback of Router::add(). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

125
            $r->add('/foo/(:alnum)', /** @scrutinizer ignore-type */ 'fooController@fooMethod')
Loading history...
126
              ->setRouteUri('/foo/baz123')
127
              ->setRouteSegments()
128
              ->determineRouteParamsInformation();
129
            $this->assertSame('fooController', $r->getController());
130
			$this->assertSame('fooMethod', $r->getMethod());
131
			$this->assertSame(1, count($r->getArgs()));
132
            $args = $r->getArgs();
133
            $this->assertSame('baz123', $args[0]);
134
		}
135
        
136
        public function testWithCustomConfigUsingMultiplePattern()
137
		{
138
            $r = new Router();
139
            $r->add('/foo/(:alpha)/(:num)', 'fooController@fooMethod')
0 ignored issues
show
Bug introduced by
'fooController@fooMethod' of type string is incompatible with the type object expected by parameter $callback of Router::add(). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

139
            $r->add('/foo/(:alpha)/(:num)', /** @scrutinizer ignore-type */ 'fooController@fooMethod')
Loading history...
140
              ->setRouteUri('/foo/baz/123')
141
              ->setRouteSegments()
142
              ->determineRouteParamsInformation();
143
            $this->assertSame('fooController', $r->getController());
144
			$this->assertSame('fooMethod', $r->getMethod());
145
			$this->assertSame(2, count($r->getArgs()));
146
            $args = $r->getArgs();
147
            $this->assertSame('baz', $args[0]);
148
            $this->assertSame('123', $args[1]);
149
		}
150
151
	}