Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit b4a73c1

Browse files
committed
Merge pull request laravel#1665 from driesvints/bugfix/fix-missing-method-on-controller
Fix missing method implementation on Controller class
2 parents 3cdf93c + 39a1af2 commit b4a73c1

2 files changed

Lines changed: 47 additions & 3 deletions

File tree

src/Illuminate/Routing/Controllers/Controller.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -282,12 +282,12 @@ public function getControllerFilters()
282282
/**
283283
* Handle calls to missing methods on the controller.
284284
*
285-
* @param array $parameters
285+
* @param array $parameters
286286
* @return mixed
287287
*/
288288
public function missingMethod($parameters)
289289
{
290-
throw new NotFoundHttpException;
290+
throw new NotFoundHttpException("Controller method not found.");
291291
}
292292

293293
/**
@@ -299,7 +299,7 @@ public function missingMethod($parameters)
299299
*/
300300
public function __call($method, $parameters)
301301
{
302-
throw new NotFoundHttpException;
302+
return $this->missingMethod($parameters);
303303
}
304304

305305
}

tests/Routing/RoutingControllerTest.php

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,43 @@ public function testAfterFiltersAreExecutedWhenUsingCallbackFilters()
122122
unset($_SERVER['__controller.after']);
123123
}
124124

125+
126+
/**
127+
* @expectedException Symfony\Component\HttpKernel\Exception\NotFoundHttpException
128+
*/
129+
public function testMissingMethod()
130+
{
131+
$controller = new BasicControllerStub;
132+
$container = new Illuminate\Container\Container;
133+
$container['filter.parser'] = $container->share(function() { return m::mock('StdClass'); });
134+
$container['filter.parser']->shouldReceive('parse')->andReturn(array());
135+
$router = m::mock('Illuminate\Routing\Router');
136+
$router->shouldReceive('getRequest')->andReturn(m::mock('Symfony\Component\HttpFoundation\Request'));
137+
$router->shouldReceive('getCurrentRoute')->andReturn(m::mock('Illuminate\Routing\Route'));
138+
$router->shouldReceive('prepare')->never()->andReturnUsing(function($response, $request) { return new Response($response); });
139+
140+
// Call a method that doesn't exists.
141+
$controller->callAction($container, $router, 'thisMethodDoesntExists', array('foo'));
142+
}
143+
144+
145+
public function testMissingMethodReplacement()
146+
{
147+
$controller = new MissingMethodControllerStub;
148+
$container = new Illuminate\Container\Container;
149+
$container['filter.parser'] = $container->share(function() { return m::mock('StdClass'); });
150+
$container['filter.parser']->shouldReceive('parse')->andReturn(array());
151+
$router = m::mock('Illuminate\Routing\Router');
152+
$router->shouldReceive('getRequest')->andReturn(m::mock('Symfony\Component\HttpFoundation\Request'));
153+
$router->shouldReceive('getCurrentRoute')->andReturn(m::mock('Illuminate\Routing\Route'));
154+
$router->shouldReceive('prepare')->once()->andReturnUsing(function($response, $request) { return new Response($response); });
155+
156+
// Call a method that doesn't exists.
157+
$response = $controller->callAction($container, $router, 'thisMethodDoesntExists', array('foo'));
158+
$this->assertEquals('Missing method!', $response->getContent());
159+
}
160+
161+
125162
}
126163

127164
class BasicControllerStub extends Illuminate\Routing\Controllers\Controller {
@@ -140,4 +177,11 @@ protected function setupLayout()
140177
{
141178
$this->layout = 'Layout';
142179
}
180+
}
181+
182+
class MissingMethodControllerStub extends Illuminate\Routing\Controllers\Controller {
183+
public function missingMethod($parameters)
184+
{
185+
return 'Missing method!';
186+
}
143187
}

0 commit comments

Comments
 (0)