My Symfony application has a few dependencies that are only required for development, testing and the like. These are defined in my composer.json
in the require-dev
section.
Here is how I add them in AppKernel.php
:
class AppKernel extends Kernel
{
public function registerBundles()
{
$bundles = array(
new Symfony\Bundle\FrameworkBundle\FrameworkBundle(),
new Symfony\Bundle\SecurityBundle\SecurityBundle(),
// ...
);
if (in_array($this->getEnvironment(), array('dev', 'test'))) {
$bundles[] = new Symfony\Bundle\WebProfilerBundle\WebProfilerBundle();
$bundles[] = new Sensio\Bundle\DistributionBundle\SensioDistributionBundle();
$bundles[] = new Sensio\Bundle\GeneratorBundle\SensioGeneratorBundle();
$bundles[] = new Doctrine\Bundle\FixturesBundle\DoctrineFixturesBundle();
$bundles[] = new Liip\FunctionalTestBundle\LiipFunctionalTestBundle();
}
return $bundles;
}
}
When I update my application, I run php composer.phar install --no-dev --optimize-autoloader
. This installs all requirements not required for the dev environment and then clears the cache.
However, clearing the cache fails with the following message:
PHP Fatal error: Class 'Doctrine\Bundle\FixturesBundle\DoctrineFixturesBundle' not found in /my/project/app/AppKernel.php on line 29 Script Sensio\Bundle\DistributionBundle\Composer\ScriptHandler::clearCache handling the post-install-cmd event terminated with an exception [RuntimeException] An error occurred when executing the "'cache:clear --no-warmup'" command.
This is not only a problem with the Doctrine Fixtures Bundle. If I change the order so the Liip Functional Test Bundle comes first then the error will be about that bundle.
Why am I seeing this error? Why does Symfony try to access these bundles even though we are explicitly not in the dev environment (notice the --no-dev
composer flag)? And what can I do to make this go away without having to install all dev dependencies on the production machine?