Reputation: 875
I'm just getting started with unit testing in the zend framework. I've read lots of the docs ZF and PhpUnit but there are a few things I can't figure out.
/tests/application/controllers/ControllerNameTest.php
. I assume I create my tests here.Any help appreciated.
Thanks
Upvotes: 3
Views: 2590
Reputation: 3096
You need to install the phpunit. The easiest way in my opinion is using PEAR (http://www.phpunit.de/manual/current/en/installation.html#installation.pear).
For testing controllers you can replicate the same code which you found in the ControllerNameTest.php file. For testing models you can create a PHPUnit test case.
<?php
class YourApp_Model_YourModel extends PHPUnit_Framework_TestCase
{
public function setUp()
{
$application = new Zend_Application(
APPLICATION_ENV,
APPLICATION_PATH . '/configs/application.ini'
);
$application->bootstrap('config')
->bootstrap('defaultModuleAutoloader')
->bootstrap('autoloader');
// You might need to add few more bootstrap, depends on your needs
}
public function testSomeMethod(){}
I hope that helps.
Upvotes: 3
Reputation: 875
I have found a great guide to setting everything up here with PHPUnit and Zend Framework here:
http://grover.open2space.com/content/unit-testing-zend-framework-111-and-phpunit
Upvotes: 0
Reputation: 41
You need to install PHPUnit, too. Zend Framework and PHPUnit are two different things. You find the installation instructions for PHPUnit here: https://github.com/sebastianbergmann/phpunit.
Basically, You can put the tests where you want. But the tests-Folder is a good place for them.
After you have installed phpunit, you can call your unit tests from the command line. Just enter the folder where you put your tests on command line and type "phpunit", this will run all tests in the folder. You can also use the --filter option to run a single test.
Upvotes: 4