Setting up testing and fixtures in Symfony2 is vital if you plan on starting Test Driven Development or you simply want to start covering your code with properly written tests that can access mock data.
1. Install PHPUnit and php 5.6
The first thing you need to do is to install PHPUnit on your machine:
Now that have your fixtures ready, you can go ahead and write your first test. Create a new file in your AppBundle/Tests folder called UserTest.php, next to BaseTestSetup.php:
class UserTest extends BaseTestSetup
public function testSuggestImprovementEmail()
// assuming that you named your user 'username' in your Fixtures
$crawler = $this->client->request('GET', '/show/username');
$crawler->filter('html:contains("Hello first user!")')->count()
And that’s about it! You now have everything you need to properly test your awesome app.
IntelligentBee respects and applies the new policy regarding personal data protection as well as the changes proposed by European Regulation (EU) 2016/679. Before continuing to browse our website, please take time to read and understand the contents.
Necessary cookies are absolutely essential for the website to function properly. This category only includes cookies that ensures basic functionalities and security features of the website. These cookies do not store any personal information.
Any cookies that may not be particularly necessary for the website to function and is used specifically to collect user personal data via analytics, ads, other embedded contents are termed as non-necessary cookies. It is mandatory to procure user consent prior to running these cookies on your website.