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 ;-)
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.
The <testsuite> Element.
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.
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.
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.
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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With