I want to know how to test models in the zend framework, I already tested the controller in the zend project.
my phpunit.xml:
<phpunit bootstrap="./bootstrap.php" colors="true">
<testsuite>
<directory>./</directory>
</testsuite>
<filter>
<whitelist>
<directory suffix="MyApp.php">../application/</directory>
<exclude>
<file>../application/Bootstrap.php</file>
<file>../application/controllers/ErrorController.php</file>
<directory suffix=".phtml">../application/</directory>
</exclude>
</whitelist>
</filter>
<logging>
<log type="coverage-html" target="./log/report" charset="UTF-8"
yui="true" highlight="true" lowUpperBound="50" highLowerBound="80"/>
<log type="testdox-html" target="./log/testdox.html" />
</logging>
</phpunit>
bootstrap.php is located in the same folder as phpunit.xml
<?php
error_reporting(E_ALL);
defined('APPLICATION_PATH')
|| define('APPLICATION_PATH', realpath(dirname(__FILE__) . '/../application'));
defined('APPLICATION_ENV')
|| define('APPLICATION_ENV', (getenv('APPLICATION_ENV') ? getenv('APPLICATION_ENV') : 'testing'));
set_include_path(implode(PATH_SEPARATOR, array(
realpath(APPLICATION_PATH . '/../library'),
realpath(APPLICATION_PATH . '/../tests'),
get_include_path(),
)));
require_once 'Zend/Application.php';
require_once './application/controllers/ControllerTestCase.php';
ControllerTestCase.php:
<?php
require_once 'Zend/Application.php';
require_once 'Zend/Test/PHPUnit/ControllerTestCase.php';
class ControllerTestCase
extends Zend_Test_PHPUnit_ControllerTestCase
{
protected $application;
public function setUp() {
$this->bootstrap = array($this,'appBootstrap');
parent::setUp();
}
public function appBootstrap() {
$this->application =
new Zend_Application(APPLICATION_ENV,
APPLICATION_PATH.'/configs/application.ini');
$this->application->bootstrap();
}
}
I used ControllerTestCase as the base and wrote a test case for the controller, and it works, but I donβt know how to write a test case for models, should the test case for the model extend ControllerTestCase as well? or should it extend Zend_Test_PHPUnit_Db? And since the model will connect to the database, so how can I check it? can anyone help me with this? For example, I have a model:
<?php class Application_Model_User2 extends Custom_Model_Base {
public function __construct() {
parent::__construct();
}
static function create(array $data) {
return parent::_create(
$_table,
get_class(),
$data,
self::$_columns,
true
);
}
}
How to check it?