Skip to content

Instantly share code, notes, and snippets.

@icambridge
Created January 21, 2012 11:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save icambridge/1652436 to your computer and use it in GitHub Desktop.
Save icambridge/1652436 to your computer and use it in GitHub Desktop.
Controller Test
<?php
namespace app\tests\cases\controllers;
use app\controllers\ArticlesController;
use app\tests\mocks\controllers\MockArticlesController;
use lithium\action\Request;
class ArticlesControllerTest extends \lithium\test\Unit {
protected $_controller;
public function setUp() {}
public function tearDown() {}
public function testIndexList() {
$request = new Request();
$articlesController = new MockArticlesController(compact('request'));
$articlesController->index();
// Following comments is thanks to @mehlah with $this->_controller a MockArticlesController pre set up in $this->setUp()
// or $this->_controller(null, array('action' => 'index', 'args' => array()));
// that make use of PHP's callable syntax and yield to call `Controller::__invoke()` for dispatching requests to action methods.
// $this->_controller->__invoke(null, array('action' => 'index', 'args' => array()));
$render = $articlesController->access('_render');
$viewVars = $render['data'];
$this->assertTrue(isset($viewVars['test']),"The index 'test' isn't set");
$this->assertEqual("test",$viewVars['test'],"The string should be 'test'");
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment