Last active
August 29, 2015 13:57
-
-
Save wouterj/9437441 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?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