Skip to content

Commit 7c6052b

Browse files
committed
Fix tests
1 parent 991c5dd commit 7c6052b

3 files changed

Lines changed: 132 additions & 143 deletions

File tree

tests/DispatcherTest.php

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -15,14 +15,15 @@ function setUp()
1515
$this->object->setBootstrap(new Bootstrap());
1616
$this->object->setEventManager(new EventManager());
1717
$this->object->setControllerPath(__DIR__ . '/controllers');
18+
$router = new Router();
19+
$this->object->setRouter($router);
1820
}
1921

2022
public function testDispatchARoute()
2123
{
22-
$this->markTestSkipped("Check this operation");
23-
$route = new Route();
24-
$route->explode("alone/an");
25-
24+
$request = new Request("alone/an");
25+
$this->object->setRequest($request);
26+
$route = $this->object->getRouter()->match($request);
2627
$content = $this->object->dispatch($route);
2728

2829
$this->assertEquals("an-action", $content);
@@ -33,11 +34,9 @@ public function testDispatchARoute()
3334
*/
3435
public function testDispatchAnError()
3536
{
36-
$this->markTestSkipped("Check this test");
37-
38-
$route = new Route();
39-
$route->explode("/not/exists-this-action");
40-
37+
$request = new Request("/not/exists-this-action");
38+
$this->object->setRequest($request);
39+
$route = $this->object->getRouter()->match($request);
4140
$this->object->dispatch($route);
4241
}
4342

tests/RouteTest.php

Lines changed: 1 addition & 134 deletions
Original file line numberDiff line numberDiff line change
@@ -29,112 +29,6 @@ protected function tearDown()
2929
{
3030
}
3131

32-
/**
33-
* @covers Route::explode
34-
* @todo Implement testExplode().
35-
*/
36-
public function testSlashExplode()
37-
{
38-
$this->markTestSkipped("Check if is router test");
39-
$routeObj = $this->object->explode("/");
40-
41-
$route = $routeObj->getRoute();
42-
$params = $routeObj->getParams();
43-
44-
$this->assertEquals("Index", $route["controller"]);
45-
$this->assertEquals("index", $route["action"]);
46-
47-
$this->assertInternalType("array", $params);
48-
$this->assertSame(0, count($params));
49-
}
50-
51-
public function testOnlyActionExplode()
52-
{
53-
$this->markTestSkipped("Check if is router test");
54-
$routeObj = $this->object->explode("/home");
55-
56-
$route = $routeObj->getRoute();
57-
$params = $routeObj->getParams();
58-
59-
$this->assertEquals("Index", $route["controller"]);
60-
$this->assertEquals("home", $route["action"]);
61-
62-
$this->assertInternalType("array", $params);
63-
$this->assertSame(0, count($params));
64-
}
65-
66-
public function testControllerActionExplode()
67-
{
68-
$this->markTestSkipped("Check if is router test");
69-
$routeObj = $this->object->explode("/admin/home");
70-
71-
$route = $routeObj->getRoute();
72-
$params = $routeObj->getParams();
73-
74-
$this->assertEquals("Admin", $route["controller"]);
75-
$this->assertEquals("home", $route["action"]);
76-
77-
$this->assertInternalType("array", $params);
78-
$this->assertSame(0, count($params));
79-
}
80-
81-
public function testParamsControllerActionExplode()
82-
{
83-
$this->markTestSkipped("Check if is router test");
84-
$routeObj = $this->object->explode("/walk/on/area/bar/status/inlove");
85-
86-
$route = $routeObj->getRoute();
87-
$params = $routeObj->getParams();
88-
89-
$this->assertEquals("Walk", $route["controller"]);
90-
$this->assertEquals("on", $route["action"]);
91-
92-
$this->assertInternalType("array", $params);
93-
$this->assertSame(2, count($params));
94-
95-
$keys = array_keys($params);
96-
$this->assertEquals("area", $keys[0]);
97-
$this->assertEquals("status", $keys[1]);
98-
99-
$this->assertEquals("bar", $params["area"]);
100-
$this->assertEquals("inlove", $params["status"]);
101-
}
102-
103-
public function testUnbalancedParamsExplode()
104-
{
105-
$this->markTestSkipped("Check if is router test");
106-
$routeObj = $this->object->explode("/walk/on/area/bar/status");
107-
108-
$route = $routeObj->getRoute();
109-
$params = $routeObj->getParams();
110-
111-
$this->assertEquals("Walk", $route["controller"]);
112-
$this->assertEquals("on", $route["action"]);
113-
114-
$this->assertInternalType("array", $params);
115-
$this->assertSame(1, count($params));
116-
117-
$keys = array_keys($params);
118-
$this->assertEquals("area", $keys[0]);
119-
120-
$this->assertEquals("bar", $params["area"]);
121-
}
122-
123-
public function testComplexControllerName()
124-
{
125-
$this->markTestSkipped("Check if is router test");
126-
$routeObj = $this->object->explode("/walk-on-files/hello-sunny-day/param/ok-this");
127-
128-
$route = $routeObj->getRoute();
129-
$params = $routeObj->getParams();
130-
131-
$this->assertEquals("WalkOnFiles", $route["controller"]);
132-
$this->assertEquals("helloSunnyDay", $route["action"]);
133-
134-
$params = $routeObj->getParams();
135-
$this->assertEquals("ok-this", $params["param"]);
136-
}
137-
13832
/**
13933
* @expectedException RuntimeException
14034
*/
@@ -146,7 +40,7 @@ public function testStrangeExplode()
14640

14741
public function testAddParam()
14842
{
149-
$this->markTestSkipped("Check if is router test");
43+
$this->markTestSkipped("Check if is request test");
15044
$this->object->explode("/index/index");
15145
$this->object->addParams(array("hello" => "ciao"));
15246
$this->object->addParams(array("bella" => 'zi'));
@@ -165,31 +59,4 @@ public function testClearGetParams()
16559
$this->assertEquals("Index", $this->object->getControllerName());
16660
$this->assertEquals("index", $this->object->getActionName());
16761
}
168-
169-
public function testClearLongGetParams()
170-
{
171-
$this->markTestSkipped("Check if is router test");
172-
$uri = '/?hello=world&titti=totti';
173-
$this->object->explode($uri);
174-
$this->assertEquals("Index", $this->object->getControllerName());
175-
$this->assertEquals("index", $this->object->getActionName());
176-
}
177-
178-
public function testClearGet2Params()
179-
{
180-
$this->markTestSkipped("Check if is router test");
181-
$uri = '/account?hello=world';
182-
$this->object->explode($uri);
183-
$this->assertEquals("Index", $this->object->getControllerName());
184-
$this->assertEquals("account", $this->object->getActionName());
185-
}
186-
187-
public function testClearGet3Params()
188-
{
189-
$this->markTestSkipped("Check if is router test");
190-
$uri = '/admin/account-super?hello=world';
191-
$this->object->explode($uri);
192-
$this->assertEquals("Admin", $this->object->getControllerName());
193-
$this->assertEquals("accountSuper", $this->object->getActionName());
194-
}
19562
}

tests/RouterTest.php

Lines changed: 123 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,4 +51,127 @@ public function testChain()
5151

5252
$this->assertEquals("Hello", $route->getControllerName());
5353
}
54+
55+
public function testSlashExplode()
56+
{
57+
$routeObj = $this->_object->match(new Request("/"));
58+
59+
$route = $routeObj->getRoute();
60+
$params = $routeObj->getParams();
61+
62+
$this->assertEquals("Index", $route["controller"]);
63+
$this->assertEquals("index", $route["action"]);
64+
65+
$this->assertInternalType("array", $params);
66+
$this->assertSame(0, count($params));
67+
}
68+
69+
public function testOnlyActionExplode()
70+
{
71+
$routeObj = $this->_object->match(new Request("/home"));
72+
73+
$route = $routeObj->getRoute();
74+
$params = $routeObj->getParams();
75+
76+
$this->assertEquals("Index", $route["controller"]);
77+
$this->assertEquals("home", $route["action"]);
78+
79+
$this->assertInternalType("array", $params);
80+
$this->assertSame(0, count($params));
81+
}
82+
83+
public function testControllerActionExplode()
84+
{
85+
$routeObj = $this->_object->match(new Request("/admin/home"));
86+
87+
$route = $routeObj->getRoute();
88+
$params = $routeObj->getParams();
89+
90+
$this->assertEquals("Admin", $route["controller"]);
91+
$this->assertEquals("home", $route["action"]);
92+
93+
$this->assertInternalType("array", $params);
94+
$this->assertSame(0, count($params));
95+
}
96+
97+
public function testParamsControllerActionExplode()
98+
{
99+
$r = new Request("/walk/on/area/bar/status/inlove");
100+
$routeObj = $this->_object->match($r);
101+
102+
$route = $routeObj->getRoute();
103+
$params = $r->getParams();
104+
105+
$this->assertEquals("Walk", $route["controller"]);
106+
$this->assertEquals("on", $route["action"]);
107+
108+
$this->assertInternalType("array", $params);
109+
$this->assertSame(2, count($params));
110+
111+
$keys = array_keys($params);
112+
$this->assertEquals("area", $keys[0]);
113+
$this->assertEquals("status", $keys[1]);
114+
115+
$this->assertEquals("bar", $params["area"]);
116+
$this->assertEquals("inlove", $params["status"]);
117+
}
118+
119+
public function testUnbalancedParamsExplode()
120+
{
121+
$r = new Request("/walk/on/area/bar/status");
122+
$routeObj = $this->_object->match($r);
123+
124+
$route = $routeObj->getRoute();
125+
$params = $r->getParams();
126+
127+
$this->assertEquals("Walk", $route["controller"]);
128+
$this->assertEquals("on", $route["action"]);
129+
130+
$this->assertInternalType("array", $params);
131+
$this->assertSame(1, count($params));
132+
133+
$keys = array_keys($params);
134+
$this->assertEquals("area", $keys[0]);
135+
136+
$this->assertEquals("bar", $params["area"]);
137+
}
138+
139+
public function testComplexControllerName()
140+
{
141+
$r = new Request("/walk-on-files/hello-sunny-day/param/ok-this");
142+
$routeObj = $this->_object->match($r);
143+
144+
$route = $routeObj->getRoute();
145+
$params = $r->getParams();
146+
147+
$this->assertEquals("WalkOnFiles", $route["controller"]);
148+
$this->assertEquals("helloSunnyDay", $route["action"]);
149+
150+
$params = $r->getParams();
151+
$this->assertEquals("ok-this", $params["param"]);
152+
}
153+
154+
public function testClearLongGetParams()
155+
{
156+
$uri = '/?hello=world&titti=totti';
157+
$route = $this->_object->match(new Request($uri));
158+
$this->assertEquals("Index", $route->getControllerName());
159+
$this->assertEquals("index", $route->getActionName());
160+
}
161+
162+
public function testClearGet2Params()
163+
{
164+
$uri = '/account?hello=world';
165+
$route = $this->_object->match(new Request($uri));
166+
$this->assertEquals("Index", $route->getControllerName());
167+
$this->assertEquals("account", $route->getActionName());
168+
}
169+
170+
public function testClearGet3Params()
171+
{
172+
$uri = '/admin/account-super?hello=world';
173+
$route = $this->_object->match(new Request($uri));
174+
$this->assertEquals("Admin", $route->getControllerName());
175+
$this->assertEquals("accountSuper", $route->getActionName());
176+
}
54177
}

0 commit comments

Comments
 (0)