Skip to content

Commit 991c5dd

Browse files
committed
Application tests ok
1 parent 67963a1 commit 991c5dd

4 files changed

Lines changed: 65 additions & 24 deletions

File tree

src/Application.php

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,9 @@ class Application
66
private $_eventManager;
77
private $_page = '';
88

9+
private $_router;
10+
private $_request;
11+
912
public function __construct(Bootstrap $bootstrap = null, EventManager $eventManager = null)
1013
{
1114
$this->_bootstrap = ($bootstrap) ? $bootstrap : new Bootstrap();
@@ -47,8 +50,9 @@ public function dispatch(Route $route)
4750
$protoView = ($this->getBootstrap()->getResource("view")) ? $this->getBootstrap()->getResource("view") : new View();
4851

4952
$controllerPath = $this->getControllerPath();
50-
$protoView->addHelper("pull", function($uri) use ($controllerPath) {
51-
return;
53+
$router = $this->_router;
54+
$request = $this->_request;
55+
$protoView->addHelper("pull", function($uri) use ($controllerPath, $router, $request) {
5256
$request = clone $request;
5357
$request->setUri($uri);
5458
$routeObj = $router->match($request);
@@ -77,6 +81,8 @@ public function dispatch(Route $route)
7781
});
7882

7983
$dispatcher = new Dispatcher($protoView);
84+
$dispatcher->setRouter($this->_router);
85+
$dispatcher->setRequest($this->_request);
8086
$dispatcher->setEventManager($this->getEventManager());
8187
$dispatcher->setBootstrap($this->_bootstrap);
8288
$dispatcher->setControllerPath($this->getControllerPath());
@@ -105,13 +111,13 @@ public function dispatch(Route $route)
105111

106112
public function run(Request $request = null)
107113
{
108-
$router = ($this->getBootstrap()->getResource("router")) ? $this->getResource("router") : new Router();
109-
$request = (!$request) ? Request::newHttp() : $request;
114+
$this->_router = ($this->getBootstrap()->getResource("router")) ? $this->getResource("router") : new Router();
115+
$this->_request = (!$request) ? Request::newHttp() : $request;
110116

111117
$outputBuffer = '';
112118
$this->getEventManager()->publish("loop.startup", array($this));
113119

114-
$status = $this->dispatch($router->match($request));
120+
$status = $this->dispatch($this->_router->match($this->_request));
115121

116122
if (($layout = $this->getBootstrap()->getResource("layout")) instanceof Layout) {
117123
$layout->content = $this->_page;

src/Controller.php

Lines changed: 28 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,31 @@ class Controller
55
private $_rawBody;
66
private $_viewScript;
77

8+
private $_router;
9+
private $_request;
10+
811
public $view;
912

13+
public function setRequest(Request $request)
14+
{
15+
$this->_request = $request;
16+
}
17+
18+
public function getRequest()
19+
{
20+
return $this->_request;
21+
}
22+
23+
public function setRouter(Router $router)
24+
{
25+
$this->_router = $router;
26+
}
27+
28+
public function getRouter()
29+
{
30+
return $this->_router;
31+
}
32+
1033
public function setView($view)
1134
{
1235
$this->view = $view;
@@ -46,9 +69,11 @@ public function getRawBody()
4669

4770
public function then($uri)
4871
{
49-
throw new Exception("Refactor then!");
50-
$route = new Route();
51-
$this->_params["dispatcher"]->add($route->explode($uri));
72+
$request = clone $this->_request;
73+
$request->setUri($uri);
74+
75+
$route = $this->_router->match($request);
76+
$this->_params["dispatcher"]->add($route);
5277
}
5378

5479
public function clearHeaders()

src/Dispatcher.php

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,36 @@ class Dispatcher
1616

1717
private $_headers = array();
1818

19+
private $_router;
20+
private $_request;
21+
1922
public function __construct(View $view)
2023
{
2124
$this->_view = $view;
2225
$this->_actions = array();
2326
$this->_viewsQueue = array();
2427
}
2528

29+
public function setRouter(Router $router)
30+
{
31+
$this->_router = $router;
32+
}
33+
34+
public function getRouter()
35+
{
36+
return $this->_router;
37+
}
38+
39+
public function setRequest(Request $request)
40+
{
41+
$this->_request = $request;
42+
}
43+
44+
public function getRequest()
45+
{
46+
return $this->_request;
47+
}
48+
2649
public function setControllerPath($path)
2750
{
2851
$this->_controllerPath = $path;
@@ -83,6 +106,8 @@ public function dispatch(Route $route)
83106
}
84107

85108
$controller = new $controllerClassName($this);
109+
$controller->setRouter($this->getRouter());
110+
$controller->setRequest($this->getRequest());
86111
$controller->setParams(
87112
array_merge(
88113
array(

tests/ApplicationTest.php

Lines changed: 1 addition & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,6 @@ public function testPreDispatchHook()
157157

158158
public function testThenMethod()
159159
{
160-
$this->markTestSkipped("Skip then operation");
161160
ob_start();
162161
$this->object->run(new Request("/then/first"));
163162
$thenOutput = ob_get_contents();
@@ -171,13 +170,8 @@ public function testThenMethod()
171170
*/
172171
public function testMissingAction()
173172
{
174-
// $this->setExpectedException("RuntimeException", "Page not found admin/missing-action", 404);
175-
$route = new Route();
176-
$route->setControllerName("admin");
177-
$route->setActionName("missing-action");
178-
179173
$this->object->setControllerPath(__DIR__);
180-
$this->object->dispatch($route);
174+
$this->object->run(new Request("/admin/missing-action"));
181175
}
182176

183177
public function testMissingEventManager()
@@ -240,7 +234,6 @@ public function testLayoutViewHelpersPass()
240234

241235
public function testEmptyPullDrivenRequest()
242236
{
243-
$this->markTestSkipped("Skip pull");
244237
$this->object->bootstrap("view", function(){
245238
$v = new View();
246239
$v->setViewPath(__DIR__ . '/views');
@@ -258,7 +251,6 @@ public function testEmptyPullDrivenRequest()
258251

259252
public function testCompletelyMissingPullDrivenRequest()
260253
{
261-
$this->markTestSkipped("Skip pull");
262254
$this->object->setControllerPath(null);
263255
$this->object->bootstrap("view", function(){
264256
$v = new View();
@@ -277,7 +269,6 @@ public function testCompletelyMissingPullDrivenRequest()
277269

278270
public function testCompletelyMissingPullWithDataDrivenRequest()
279271
{
280-
$this->markTestSkipped("Skip pull");
281272
$this->object->bootstrap("view", function(){
282273
$v = new View();
283274
$v->setViewPath(__DIR__ . '/views');
@@ -295,7 +286,6 @@ public function testCompletelyMissingPullWithDataDrivenRequest()
295286

296287
public function testMissingControllerPull()
297288
{
298-
$this->markTestSkipped("Skip pull");
299289
$this->object->bootstrap("view", function(){
300290
$v = new View();
301291
$v->setViewPath(__DIR__ . '/views');
@@ -313,7 +303,6 @@ public function testMissingControllerPull()
313303

314304
public function testMissingActionPull()
315305
{
316-
$this->markTestSkipped("Skip pull");
317306
$this->object->bootstrap("view", function(){
318307
$v = new View();
319308
$v->setViewPath(__DIR__ . '/views');
@@ -366,7 +355,6 @@ public function testViewRewrited()
366355

367356
public function testViewPullRewrited()
368357
{
369-
$this->markTestSkipped("Skip pull");
370358
$this->object->bootstrap("view", function(){
371359
$v = new View();
372360
$v->addViewPath(__DIR__ . '/views');
@@ -405,7 +393,6 @@ public function testPartialViewRewrite()
405393

406394
public function testBufferOutPullRequest()
407395
{
408-
$this->markTestSkipped("Skip pull");
409396
$this->object->bootstrap("view", function(){
410397
$v = new View();
411398
$v->addViewPath(__DIR__ . '/views');
@@ -480,7 +467,6 @@ public function testPrePostDispatch()
480467

481468
public function testMultiplePrePostDispatch()
482469
{
483-
$this->markTestSkipped("Skip then operation");
484470
$preDispatch = 0;
485471
$postDispatch = 0;
486472

@@ -506,7 +492,6 @@ public function testMultiplePrePostDispatch()
506492

507493
public function testDisableLayout()
508494
{
509-
510495
$this->object->bootstrap("view", function(){
511496
$v = new View();
512497
$v->addViewPath(__DIR__ . '/views');

0 commit comments

Comments
 (0)