Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there any difference in naming the PHPunit configuration file phpunit.xml.dist or phpunit.xml

Can someone explain to me what is the difference between using PHPunit configuration files named phpunit.xml.dist or phpunit.xml.

The official documentation mentions both names:

PHPUnit's XML configuration file (Appendix C) can also be used to compose a test suite. Example 5.1 shows a minimal phpunit.xml file that will add all *Test classes that are found in *Test.php files when the tests directory is recursively traversed.

with giving phpunit.xml a higher priority when loading configuration without the configuration parameter.

If phpunit.xml or phpunit.xml.dist (in that order) exist in the current working directory and --configuration is not used, the configuration will be automatically read from that file.

I did find some questions (e.g. is this .xml.dist file really required to be used) relating to the fact, that .dist files usually are used as a template (distribution) which should be copied to a version without the .dist ending to activate them (e.g. .htaccess.dist). But this seems not to be the case with PHPunit as it picks up and runs the dist file as well. Other questions (Can I use phpunit.xml for credentials and phpunit.xml.dist for testsuites?) seem to deal with other weird usage ideas about these two files.

In the Symfony world, it is mandatory for reusable bundles to include a phpunit.xml.dist file and I wonder why not a phpunit.xml file instead.

A test suite must not contain AllTests.php scripts, but must rely on the existence of a phpunit.xml.dist file.

So if anyone can shed some light onto this I would be happy ;-)

like image 321
lordrhodos Avatar asked Jun 26 '17 16:06

lordrhodos


People also ask

What is PHPUnit xml?

PHPUnit uses XML file for configuration. This configuration file can be added to your version control system so all developers get the same output. These settings will help you make sure your tests work the way you want.

What is the PHPUnit XML configuration file used to organize tests?

The <testsuite> Element.

How to check if PHPUnit is installed?

Once done, you can verify PHPUnit is installed by enterting the following command in your terminal: And you should see something like the following: If you see something like the above, then you can execute PHPUnit anywhere from your system. 3. The Bootstrap File Before going any further, let’s write a basic bootstrap file.

Does PHPUnit run on XML files?

With all of that said, our XML file has everything that PHPUnit needs to run without any other parameters. Remember, though, before proceeding through the rest of this article, I assume you’ve globally installed PHPUnit on your system using Composer.

What is the use of @depends attribute in PHPUnit?

This attribute configures whether arrays and object graphs that are passed from one test to another using the @depends annotation should be recursively scanned for mock objects. When phpunit.phar is used then this attribute may be used to configure a directory from which all *.phar files will be loaded as extensions for the PHPUnit test runner.

Can PHPUnit backup global variables before and after testing?

The XML Configuration File Possible values: true or false (default: false) PHPUnit can optionally backup all global and super-global variables before each test and restore this backup after each test.


1 Answers

If phpunit.xml or phpunit.xml.dist (in that order) exist in the current working directory and --configuration is not used, the configuration will be automatically read from that file.

The idea behind the fallback (to phpunit.xml.dist when phpunit.xml does not exist) is that phpunit.xml.dist can be checked into version control and phpunit.xml can be ignored from version control. This allows a developer to use a custom configuration without running the risk of accidentally checking it into version control.

like image 196
Sebastian Bergmann Avatar answered Sep 18 '22 14:09

Sebastian Bergmann