PHPUnit Bridge - MiguelFieira/AMO-HANDBOEK GitHub Wiki
For unit testing, you could use PHPunit, Symfony has a bundle called PHPUnit Bridge, that sets up PHPUnit in your Symfony project.
composer require --dev symfony/phpunit-bridge
after Installation is complete, do the following to install PHPUnit and update dependencies.
php bin/phpunit
Now, if you want to run your tests, run the command again.
php bin/phpunit
There should be a tests folder in your project. there should at least be a file named bootstrap.php located there.
you can use the following command to make a unit testing class.
php bin/console make:unit-test
Alternatively you can manually make a unit testing class as described under here.
Now if we want to add unit tests, we make a file inside out tests folder. Conventions may differ from project to project, but in this case we're basically copying the folder structure of our src folder inside our tests folder for testing and add the word "Test" to the name of our file. So if we have a controller DefaultController we would have a file src/Controller/DefaultController.php, if want to test that controller we are going to add tests/Controller/DefaultControllerTest.php.
Here is an example of what a test class may look like:
namespace App\Tests\Controller;
use App\Controller\DefaultController;
use PHPUnit\Framework\TestCase;
class DefaultControllerTest extends TestCase
{
public function testThingy()
{
// Example test
$goodCops = [];
$this->assertEmpty($goodCops);
return "That's right, you fucking bastards";
}
}
PHPUnit
Read the PHPUnit docs for a complete list of features.