From a872fe629fcaf06ca2b0c5233e19c083ba7b97c6 Mon Sep 17 00:00:00 2001 From: NiR- Date: Thu, 19 Mar 2015 15:26:46 +0100 Subject: [PATCH 1/3] Making AliceContext compatible with MongoDB. --- src/Knp/FriendlyContexts/Context/Context.php | 20 ++++++++++++++++++- .../Context/EntityContext.php | 1 - 2 files changed, 19 insertions(+), 2 deletions(-) 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/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) } } } - } /** From 93c117207cbbfe26c3eaecfccb1d3abc01d3a486 Mon Sep 17 00:00:00 2001 From: NiR- Date: Thu, 19 Mar 2015 15:41:41 +0100 Subject: [PATCH 2/3] Adding a DocumentContext. --- .../Context/DocumentContext.php | 25 +++++++++++++++++++ 1 file changed, 25 insertions(+) create mode 100644 src/Knp/FriendlyContexts/Context/DocumentContext.php diff --git a/src/Knp/FriendlyContexts/Context/DocumentContext.php b/src/Knp/FriendlyContexts/Context/DocumentContext.php new file mode 100644 index 00000000..3a0c91c9 --- /dev/null +++ b/src/Knp/FriendlyContexts/Context/DocumentContext.php @@ -0,0 +1,25 @@ +storeTags($event); + + if ($this->hasTags([ 'reset-database', '~not-reset-database' ])) { + $dm = $this->getEntityManager(); + $scm = new SchemaManager($dm, $dm->getMetadataFactory()); + + $scm->dropDatabases(); + $scm->createDatabases(); + } + + } +} From 7cda5c897223c90898ff4dcd13377678173d736e Mon Sep 17 00:00:00 2001 From: Albin Kerouanton Date: Thu, 16 Apr 2015 16:15:06 +0200 Subject: [PATCH 3/3] Replacing reset-database by reset-collections. --- src/Knp/FriendlyContexts/Context/DocumentContext.php | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/src/Knp/FriendlyContexts/Context/DocumentContext.php b/src/Knp/FriendlyContexts/Context/DocumentContext.php index 3a0c91c9..7565862e 100644 --- a/src/Knp/FriendlyContexts/Context/DocumentContext.php +++ b/src/Knp/FriendlyContexts/Context/DocumentContext.php @@ -13,13 +13,11 @@ public function beforeScenario($event) { $this->storeTags($event); - if ($this->hasTags([ 'reset-database', '~not-reset-database' ])) { + if ($this->hasTags([ 'reset-collections', '~not-reset-collections' ])) { $dm = $this->getEntityManager(); $scm = new SchemaManager($dm, $dm->getMetadataFactory()); - $scm->dropDatabases(); - $scm->createDatabases(); + $scm->dropCollections(); } - } }