Extends
lithium\test\Unit
Tests the use of `Controller::__invoke()` for dispatching requests to action methods. Also
tests that using PHP's callable syntax yields the same result as calling `__invoke()`
explicitly.
Returns
voidSource
public function testMethodInvocation() {
$postsController = new MockPostsController();
$result = $postsController->__invoke(null, array('action' => 'index', 'args' => array()));
$this->assertTrue(is_a($result, 'lithium\action\Response'));
$this->assertEqual('List of posts', $result->body());
$this->assertEqual(array('Content-type' => 'text/plain; charset=UTF-8'), $result->headers);
$result2 = $postsController(null, array('action' => 'index', 'args' => array()));
$this->assertEqual($result2, $result);
$postsController = new MockPostsController();
$this->expectException('/Unhandled media type/');
$result = $postsController(null, array('action' => 'index', 'args' => array(true)));
$this->assertTrue(is_a($result, 'lithium\action\Response'));
$this->assertEqual($result->body, '');
$headers = array('Content-type' => 'text/html; charset=UTF-8');
$this->assertEqual($result->headers, $headers);
$result = $postsController->access('_render');
$this->assertEqual($result['data'], array('foo' => 'bar'));
$postsController = new MockPostsController();
$result = $postsController(null, array('action' => 'view', 'args' => array('2')));
$this->assertTrue(is_a($result, 'lithium\action\Response'));
$this->assertEqual($result->body, "Array\n(\n [0] => This is a post\n)\n");
$headers = array('status' => 200, 'Content-type' => 'text/plain; charset=UTF-8');
$this->assertEqual($result->headers(), $headers);
$result = $postsController->access('_render');
$this->assertEqual($result['data'], array('This is a post'));
}