33namespace Matthias \SymfonyDependencyInjectionTest \PhpUnit ;
44
55use Symfony \Component \DependencyInjection \Extension \ExtensionInterface ;
6+ use Symfony \Component \DependencyInjection \Extension \PrependExtensionInterface ;
67
78abstract class AbstractExtensionTestCase extends AbstractContainerBuilderTestCase
89{
10+ /**
11+ * @var bool denotes if load() method has been invoked.
12+ */
13+ private $ loadMethodInvoked ;
14+
915 /**
1016 * Return an array of container extensions you need to be registered for each test (usually just the container
1117 * extension you are testing.
@@ -35,11 +41,35 @@ protected function setUp()
3541 {
3642 parent ::setUp ();
3743
44+ $ this ->loadMethodInvoked = false ;
45+
3846 foreach ($ this ->getContainerExtensions () as $ extension ) {
3947 $ this ->container ->registerExtension ($ extension );
4048 }
4149 }
4250
51+ /**
52+ * Call this method (optionally) form within your test after you have (optionally) modified the ContainerBuilder
53+ * for this test ($this->container), but BEFORE you call load method ($this->load()) - if your extension(s) implements
54+ * \Symfony\Component\DependencyInjection\Extension\PrependExtensionInterface
55+ *
56+ * @see http://symfony.com/doc/current/bundles/prepend_extension.html
57+ * @see \Symfony\Component\DependencyInjection\Extension\PrependExtensionInterface
58+ */
59+ protected function prepend ()
60+ {
61+ if ($ this ->loadMethodInvoked ) {
62+ throw new \LogicException (sprintf ('Method "prepend()" from "%s" must not be invoked after "load()" method. ' , PrependExtensionInterface::class));
63+ }
64+
65+ foreach ($ this ->container ->getExtensions () as $ extension ) {
66+
67+ if ($ extension instanceof PrependExtensionInterface) {
68+ $ extension ->prepend ($ this ->container );
69+ }
70+ }
71+ }
72+
4373 /**
4474 * Call this method from within your test after you have (optionally) modified the ContainerBuilder for this test
4575 * ($this->container).
@@ -48,6 +78,8 @@ protected function setUp()
4878 */
4979 protected function load (array $ configurationValues = array ())
5080 {
81+ $ this ->loadMethodInvoked = true ;
82+
5183 $ configs = array ($ this ->getMinimalConfiguration (), $ configurationValues );
5284
5385 foreach ($ this ->container ->getExtensions () as $ extension ) {
0 commit comments