Nowadays testing has become an integral part of every modern web application. Usually the term testing implies unit and functional testing. Unit testing is about testing our PHP classes. Every single PHP class is considered to be a unit, thus the name unit test. Functional tests on the other hand test various layers of our application, usually concentrated on testing the functionality overall, like the sign in or sign up process.
The PHP ecosystem has a great unit testing framework called PHPUnit, available for download at https://phpunit.de. It enables us to write primarily unit, but also functional type tests. The great thing about Symfony is that it comes with built in support for PHPUnit.
Before we can start running Symfony's tests, we need to make sure we have PHPUnit installed and available as console command. When executed, PHPUnit automatically tries to pick up and read testing configuration from phpunit.xml or phpunit.xml.dist within the current working directory, if available. By default Symfony comes with a phpunit.xml.dist file in its root folder, thus making it possible for the phpunit command to pick up its test configuration.
The following is a partial example of a default phpunit.xml.dist file:
<phpunit … >
<php>
<ini name="error_reporting" value="-1" />
<server name="KERNEL_DIR" value="app/" />
</php>
<testsuites>
<testsuite name="Project Test Suite">
<directory>tests</directory>
</testsuite>
</testsuites>
<filter>
<whitelist>
<directory>src</directory>
<exclude>
<directory>src/*Bundle/Resources</directory>
<directory>src/*/*Bundle/Resources</directory>
<directory>src/*/Bundle/*Bundle/Resources</directory>
</exclude>
</whitelist>
</filter>
</phpunit>The testsuites element defines the directory tests, in which all of our tests are located. The filter element with its children is used to configure the whitelist for the code coverage reporting. The php element with its children is used to configure PHP settings, constants, and global variables.
Running a phpunit command against a default project like ours would result in output like the following:

Note that bundle tests are not automatically picked up. Our src/AppBundle/Tests/Controller/CustomerControllerTest.php file, which was created for us automatically when we used auto-generated CRUD, was not executed. Not because its content is commented out by default, but because the bundle test directory isn't visible to phpunit. To make it execute, we need to extend the phpunit.xml.dist file by adding to directory testsuite as follows:
<testsuites>
<testsuite name="Project Test Suite">
<directory>tests</directory>
<directory>src/AppBundle/Tests</directory>
</testsuite>
</testsuites>Depending on how we build our application, we might want to add all of our bundles to the testsuite list, even if we plan on distributing bundles independently.
There is plenty more to be said about testing. We will do so bit by bit as we progress through further chapters and cover the needs of individual bundles. For the moment, it is suffice to know how to trigger tests and how to add new locations to testing configuration.