Unit testing

The FoggylineShipmentBundle module is quite simple. By providing only two simple services and two simple controllers, it's easy to test.

We will start off by adding the following line under the testsuites element of our phpunit.xml.dist file:

<directory>src/Foggyline/ShipmentBundle/Tests</directory>

With that in place, running the phpunit command from root of our shop should pick up any test we have defined under the src/Foggyline/ShipmentBundle/Tests/ directory.

Now, let's go ahead and create a test for our FlatRateShipment service. We will do so by creating a src/Foggyline/ShipmentBundle/Tests/Service/FlatRateShipmentTest.php file, with content as follows:

namespace Foggyline\ShipmentBundle\Tests\Service; use Symfony\Bundle\FrameworkBundle\Test\KernelTestCase; ...

Get Modular Programming with PHP 7 now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.