Speedup phpUnit test in Symfony2/3

A few ways to speedup your functional/unit tests in symfony2:

  • See this link for an easy Symfony2 / PHPUnit optimization.
  • Paratest - Parallel testing for PHPUnit
  • Turn SQL logger off
    $this->em->getConnection()->getConfiguration()->setSQLLogger(null);
  • Put cache for test into shared memory
    // AppKernel.php
    /**
     * @return string
     */
    public function getCacheDir()
    {
        if ($this->environment === 'test') {
            return '/dev/shm/appname/cache/' .  $this->environment;
        }
    }

Updated: