Hoa central
Dispatcher.php
Go to the documentation of this file.
1 <?php
2 
37 namespace Hoa\Dispatcher\Test\Unit;
38 
39 use Hoa\Router;
40 use Hoa\Test;
41 
51 {
52  public function case_getParameters()
53  {
54  $this
55  ->given($dispatcher = new \Mock\Hoa\Dispatcher())
56  ->when($result = $dispatcher->getParameters())
57  ->then
58  ->object($result)
59  ->isInstanceOf('Hoa\Core\Parameter');
60  }
61 
62  public function case_kitname()
63  {
64  $this
65  ->given($dispatcher = new \Mock\Hoa\Dispatcher())
66  ->when($result = $dispatcher->setKitName('foo'))
67  ->then
68  ->string($result)
69  ->isEqualTo('Hoa\Dispatcher\Kit')
70 
71  ->when($result = $dispatcher->getKitName())
72  ->string($result)
73  ->isEqualTo('foo');
74  }
75 
76  public function case_dispatch_already_routed()
77  {
78  $this
79  ->given(
80  $dispatcher = new \Mock\Hoa\Dispatcher(),
81  $parameters = $dispatcher->getParameters(),
82  $routedRule = null,
83  $routedRouter = null,
84  $routedView = null,
85  $routedParameters = null,
86  $this->calling($dispatcher)->resolve = function ($rule, $router, $view) use (
87  &$routedRule,
88  &$routedRouter,
89  &$routedView,
90  &$routedParameters
91  ) {
92 
93  $routedRule = $rule;
94  $routedRouter = $router;
95  $routedView = $view;
96  $routedParameters = $this->getParameters();
97 
98  return;
99  },
100  $router = new Router\Cli(),
101  $router->get('a', '(?<foo>fooo) (?<bar>baar)'),
102  $router->route('fooo baar')
103  )
104  ->when($dispatcher->dispatch($router))
105  ->then
106  ->array($routedRule)
107  ->object($routedRouter)
108  ->isIdenticalTo($router)
109  ->variable($routedView)
110  ->isNull()
111  ->object($routedParameters)
112  ->isInstanceOf('Hoa\Core\Parameter')
113 
114  ->object($dispatcher->getParameters())
115  ->isIdenticalTo($parameters)
116  ->object($parameters)
117  ->isNotIdenticalTo($routedParameters)
118  ->string($routedParameters->getParameter('variables.foo'))
119  ->isEqualTo('fooo')
120  ->string($routedParameters->getParameter('variables.bar'))
121  ->isEqualTo('baar');
122  }
123 
124  public function case_dispatch_auto_route()
125  {
126  $this
127  ->given(
128  $dispatcher = new \Mock\Hoa\Dispatcher(),
129  $parameters = $dispatcher->getParameters(),
130  $routedRule = null,
131  $routedRouter = null,
132  $routedView = null,
133  $routedParameters = null,
134  $this->calling($dispatcher)->resolve = function ($rule, $router, $view) use (
135  &$routedRule,
136  &$routedRouter,
137  &$routedView,
138  &$routedParameters
139  ) {
140 
141  $routedRule = $rule;
142  $routedRouter = $router;
143  $routedView = $view;
144  $routedParameters = $this->getParameters();
145 
146  return;
147  },
148  $router = new Router\Cli(),
149  $router->get('a', '(?<foo>fooo) (?<bar>baar)'),
150  $router->route('fooo baar'),
151  $theRule = $router->getTheRule(),
152 
153  $router = new \Mock\Hoa\Router(),
154  $this->calling($router)->getTheRule[0] = $theRule,
155  $this->calling($router)->getTheRule[1] = null,
156  $this->calling($router)->route = null
157  )
158  ->when($dispatcher->dispatch($router))
159  ->then
160  ->array($routedRule)
161  ->object($routedRouter)
162  ->isIdenticalTo($router)
163  ->variable($routedView)
164  ->isNull()
165  ->object($routedParameters)
166  ->isInstanceOf('Hoa\Core\Parameter')
167 
168  ->object($dispatcher->getParameters())
169  ->isIdenticalTo($parameters)
170  ->object($parameters)
171  ->isNotIdenticalTo($routedParameters)
172  ->string($routedParameters->getParameter('variables.foo'))
173  ->isEqualTo('fooo')
174  ->string($routedParameters->getParameter('variables.bar'))
175  ->isEqualTo('baar');
176  }
177 
178  public function case_dispatch_return()
179  {
180  $this
181  ->given(
182  $dispatcher = new \Mock\Hoa\Dispatcher(),
183  $this->calling($dispatcher)->resolve = 42,
184 
185  $router = new Router\Cli(),
186  $router->get('a', '(?<foo>foo) (?<bar>bar)'),
187  $router->route('foo bar')
188  )
189  ->when($result = $dispatcher->dispatch($router))
190  ->then
191  ->integer($result)
192  ->isEqualTo(42);
193  }
194 }
$dispatcher
Definition: Hoa.php:98
route($uri=null)
Definition: Cli.php:195
getParameters()
Definition: Core.php:266