diff --git a/src/Knp/FriendlyContexts/Context/Context.php b/src/Knp/FriendlyContexts/Context/Context.php index e11d06bd..b4094a01 100644 --- a/src/Knp/FriendlyContexts/Context/Context.php +++ b/src/Knp/FriendlyContexts/Context/Context.php @@ -68,9 +68,18 @@ protected function getAliceLoader() return $this->get('friendly.alice.loader.yaml'); } + /** + * @return \Doctrine\Common\Persistence\ObjectManager + */ protected function getEntityManager() { - return $this->get('doctrine')->getManager(); + if ($this->has('doctrine')) { + return $this->get('doctrine')->getManager(); + } elseif ($this->has('doctrine_mongodb')) { + return $this->get('doctrine_mongodb')->getManager(); + } + + throw new \RuntimeException('Neither "doctrine" nor "doctrine_mongodb" is available.'); } protected function getUniqueCache() @@ -106,6 +115,15 @@ protected function get($service) throw new ServiceNotFoundException($service); } + protected function has($service) + { + return + $this->container->has($service) + || + null !== $this->getKernel() && $this->getKernel()->getContainer()->has($service) + ; + } + protected function getParameter($name) { if ($this->container->hasParameter($name)) { diff --git a/src/Knp/FriendlyContexts/Context/DocumentContext.php b/src/Knp/FriendlyContexts/Context/DocumentContext.php new file mode 100644 index 00000000..7565862e --- /dev/null +++ b/src/Knp/FriendlyContexts/Context/DocumentContext.php @@ -0,0 +1,23 @@ +storeTags($event); + + if ($this->hasTags([ 'reset-collections', '~not-reset-collections' ])) { + $dm = $this->getEntityManager(); + $scm = new SchemaManager($dm, $dm->getMetadataFactory()); + + $scm->dropCollections(); + } + } +} diff --git a/src/Knp/FriendlyContexts/Context/EntityContext.php b/src/Knp/FriendlyContexts/Context/EntityContext.php index 32b85d8c..71529c85 100644 --- a/src/Knp/FriendlyContexts/Context/EntityContext.php +++ b/src/Knp/FriendlyContexts/Context/EntityContext.php @@ -163,7 +163,6 @@ public function beforeScenario($event) } } } - } /**