How can i get phpunit to run tests from all files in a folder? How can i get phpunit to run tests from all files in a folder? php php

How can i get phpunit to run tests from all files in a folder?


It is not a bug, it is a feature.

You have a directory full of .php files, in your case they all contain testcases.

But as your testsuite grows, you will likely want to have other php files inside tests directory, files that do not contains tests, that exist solely to support tests. Those files should never be executed by PHPUnit itself.

This is a very common scenario.

So how would PHPUnit know which files it needs to run and which ones not? Checking the file name suffix is one option for doing it - by default PHPUnit considers everything with name ending with Test.php as being a test and ignores everything else.

You can change that behaviour if you really want to - by creating a file named phpunit.xml in your tests directory with the following content

<?xml version="1.0" encoding="utf-8" ?><phpunit><testsuite name='Name your suite'>    <directory suffix='.php'>./</directory></testsuite></phpunit>

Once you have done that, PHPUnit will run all files with '.php' at the end of the file name(in this context file extension is considered to be part of the file name)

But it really is better to get used to the convention and name your tests accordingly.


The simpler way to running test on folder is to add "Test.php" at the end all of your tests and run phpunit specifing your folder like this

phpunit .

or

phpunit your_test_folder/.


Annoying little quirk, but I figured it out.

At least with the default configuration, test files have to end with "Test.php", eg. fooTest.php, or they are not found by the test runner.