How to use zend test phpunit in zend project

610 Views Asked by At

I am a very new zend framework and phpunit test learner. I have a zend project, I want to use the zend-test-phpunit to test the model and controllers under the application folder. How could I test it? I notice there is a tests folder in this project, and all the tests should be done in this folder? in this case, I have to copy all the controllers and model into this folder? who can provide me a example?

thank you for help in advance!

1

There are 1 best solutions below

0
On BEST ANSWER

A good place to start is the Zend Framework documentation and PHPUnit manual: Chapter 3. Installing PHPUnit

You need to populate the phpunit.xml file with something along the lines of:

<phpunit bootstrap="./application/bootstrap.php" colors="true">
        <testsuite name="Application" >
                <directory>./library</directory>
                <directory>./application</directory>
        </testsuite>
        <filter>
                <whitelist>
                        <directory suffix=".php">../application</directory>
                        <directory suffix=".php">../library/My</directory>
                        <exclude>
                                <directory suffix=".phtml">../application/</directory>
                                <file>../application/Bootstrap.php</file>
                        </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" target="./log/testdox.html" />
    </logging>
</phpunit>

Then it's just to run 'phpunit' from command line when in your test folder. If you want phpunit to produce a code coverage report, then you also need to enable xdebug in your environment