Run PHPUnit Tests in Certain Order
Maybe there is a design problem in your tests.
Usually each test must not depend on any other tests, so they can run in any order.
Each test needs to instantiate and destroy everything it needs to run, that would be the perfect approach, you should never share objects and states between tests.
Can you be more specific about why you need the same object for N tests?
PHPUnit : Execute testSuites in specific order
Steven Scott's comment to use a batch file, and two configuration files, would be what I would do. It follows the Unix philosophy of using simple tools to string simple tools together, rather than one big complex tool that does everything.
Here is an alternative, based on a guess that "install" is not just doing functional tests, but also setting up the DB and other fixtures that the unit tests need. So, how about moving the functional tests to a setupBeforeClass()
call inside your unit test suite. Use shell_exec()
to run phpunit to run the functional tests, and if they failed, then call die
or similar, so that the unit tests do not run.
P.S. You sound like you know what you are doing, but for anyone coming later: when you get chance, the unit tests should be refactored to use a mock DB, so that they can be run first, and frequently. Still keep your existing unit tests suite, but merge it into the functional test suite, as it sounds like that is where it belongs. In fact that (merging the two test suites then using explicit @depends
everywhere) is another approach.
What order are phpunit tests executed?
One of the big benefits of DI is that you can avoid issues like this, by injecting a mock $settings
object that behaves the way you want. This gives you a true unit test of Widget without worrying about the implementation details of Settings:
$mockSettings = $this->createMock(Settings::class);
$mockSettings->method('someMethod')->willReturn('something');
$widget = new Widget($mockSettings);
// assertions here
Run phpunit tests by testcase class that they extend
No. Either use the @group
annotation for this or, better IMO, have a tests/unit
directory for unit tests as well as a tests/integration
directory for integration tests and then define two test suites in phpunit.xml
. By default, both will be run. Using --testsuite
you can then filter based on the test suite name.
How to run single test method with phpunit?
The following command runs the test on a single method:
phpunit --filter testSaveAndDrop EscalationGroupTest escalation/EscalationGroupTest.php
phpunit --filter methodName ClassName path/to/file.php
For newer versions of phpunit, it is just:
phpunit --filter methodName path/to/file.php
Related Topics
Storing Time Information: Timezone Required
Populate Select Drop Down from a Database Table
What Is the Name for the "<<<" Operator
How to Get Attribute of Node with Namespace Using Simplexml
How to Enable Put Requests in Azure
Multi Checkbox Fields in Woocommerce Backend
Select MySQL Rows But Rows into Columns and Column into Rows
How to Get Value from Form Without Submitting It
PHP Using Declare? What Is a Tick
How to Add Two Strings Together
Fatal Error: Call to Undefined Function Openssl_Random_Pseudo_Bytes()