Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Global constants in PHPUnit

Tags:

php

phpunit

Is there a way to define constants in PHPUnit that can be used in all your test suites? For example, say I want to be able to test on jason.dev.mysite.com sometimes and jim.dev.mysite.com sometimes, and maybe specify when I run the command on which site I want to test. Is anything like this possible?

The closest thing I found was this: http://www.phpunit.de/manual/3.4/en/appendixes.configuration.html

like image 670
Jason Swett Avatar asked Oct 11 '10 14:10

Jason Swett


2 Answers

This should be in the bootstrap file.

Check here : http://www.phpunit.de/manual/current/en/textui.html for the bootstrap file option.

You can also check out the setUp() and setUpBeforeClass() methods, but they are related to one test class only.

like image 116
Matthieu Napoli Avatar answered Sep 27 '22 23:09

Matthieu Napoli


For those who already have a bootstrap and are wanting to define a constant separately checkout the <php> tag in the XML Configuration file. The link seem to change on a regular basis with version updates so an example is:

<phpunit bootstrap="../libraries/global/bootstrap.lib.php">
    <php>
        <env name="db_user" value="admin"/>
        <env name="db_pass" value="admin"/>
        <env name="db_host" value="127.0.0.1"/>
        <env name="db_port" value="1433"/>
        <const name="DEBUG" value="FALSE"/>
    </php>
    <testsuites>
        <testsuite name="role">
            <file>modules/role/role.test.php</file>
        </testsuite>
    </testsuites>
</phpunit>
like image 20
danielson317 Avatar answered Sep 27 '22 23:09

danielson317