The document contains code for unit testing a PHP MVC application using PHPUnit. It includes:
- Code for the Todo model and its tests using PHPUnit assertions.
- Configuration for PHPUnit to run tests for the application and library.
- Tests for the IndexController using a Test_ControllerTestCase class with helper methods.
- Code for Request, Response and View classes to mock the MVC framework.
- A test to interact with the application interface using Selenium.
The document shows the project structure for an MVC application and library with tests. It demonstrates how to test models, controllers and the user interface using test doubles, assertions and helper methods in PHPUnit.
78. <?php
class IndexControllerTest extends Test_ControllerTestCase
{
public function setUp()
{
$todo = new Todo();
$this->_request = new Request();
$this->_response = new Response();
$this->_controller = new IndexController($todo);
parent::setUp();
}
public function tearDown()
{
$this->_request->reset();
$this->_response->reset();
}
public function testHome()
{
$this->dispatch('/');
$this->assertAction('index')
->assertResponseCode(200);
}
82. <?php
class IndexControllerTest extends Test_ControllerTestCase
{
public function setUp()
{
$todo = $this->_setUpTodo();
$this->_controller = new IndexController($todo);
// ...
}
protected function _setUpTodo()
{
$todo = Phake::mock('Todo');
Phake::when($todo)->fetchAll()->thenReturn(array(
array(
'id' => 1,
'task' => 'Task 1',
'done' => 'n',
),
));
return $todo;
}