Skip to content

Instantly share code, notes, and snippets.

@wouterj
Last active August 29, 2015 13:57
Show Gist options
  • Select an option

  • Save wouterj/9437441 to your computer and use it in GitHub Desktop.

Select an option

Save wouterj/9437441 to your computer and use it in GitHub Desktop.
<?php
use Symfony\Component\Config\FileLocator;
use Symfony\Component\Config\Loader\LoaderResolver;
use Symfony\Component\DependencyInjection\Loader;
use Symfony\Component\DependencyInjection\ContainerBuilder;
abstract class ContainerTestCase extends \PHPUnit_Framework_TestCase
{
protected $container;
protected $serviceConfigDir = '/../../Resources/config';
protected function getContainer()
{
if (null === $this->container) {
$this->initializeContainer();
}
return $this->container;
}
protected function initializeContainer()
{
$this->container = new ContainerBuilder();
$locator = new FileLocator($this->serviceConfigDir);
$loader = new LoaderResolver(array(
new Loader\YamlFileLoader($this->container, $locator),
new Loader\XmlFileLoader($this->container, $locator),
new Loader\PhpFileLoader($this->container, $locator),
));
foreach ($this->getServiceFiles() as $file) {
$loader->load($file);
}
}
/**
* Returns an array of service files to load.
*
* @return array
*/
abstract protected getServiceFiles();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment