lithium\tests\cases\action\ControllerTest::testMethodInvocation PHP Метод

testMethodInvocation() публичный Метод

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.
    public function testMethodInvocation()
    {
        $postsController = new MockPostsController();
        $result = $postsController->__invoke(null, array('action' => 'index', 'args' => array()));
        $this->assertInstanceOf('lithium\\action\\Response', $result);
        $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->assertException('/Unhandled media type/', function () use($postsController) {
            $postsController(null, array('action' => 'index', 'args' => array(true)));
        });
        $result = $postsController->access('_render');
        $this->assertEqual($result['data'], array('foo' => 'bar'));
        $postsController = new MockPostsController();
        $this->assertException('/Unhandled media type/', function () use($postsController) {
            $postsController(null, array('action' => 'view', 'args' => array('2')));
        });
        $result = $postsController->access('_render');
        $this->assertEqual($result['data'], array('This is a post'));
    }