Skip to content

Instantly share code, notes, and snippets.

@icambridge
Created December 18, 2011 00:13
Show Gist options
  • Save icambridge/1491881 to your computer and use it in GitHub Desktop.
Save icambridge/1491881 to your computer and use it in GitHub Desktop.
Controller testing lithium
<?php
namespace app\tests\cases\controllers;
use app\controllers\ArticlesController;
use app\tests\mocks\MockArticlesController;
class ArticlesControllerTest extends \lithium\test\Unit {
protected $_controller;
public function setUp() {
$this->_controller = new MockArticlesController();
}
public function tearDown() {}
public function testIndexList() {
$this->_controller->index();
$render = $this->_controller->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'");
}
}
<?php
namespace app\controllers;
class ArticlesController extends \lithium\action\Controller {
public function index() {
$this->set(array('test' => 'test'));
}
}
<?php
namespace app\tests\mocks;
use app\controllers\ArticlesController;
class MockArticlesController extends ArticlesController {
public function access($varName) {
return $this->{$varName};
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment