Skip to content
This repository was archived by the owner on Sep 15, 2022. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 19 additions & 1 deletion src/Knp/FriendlyContexts/Context/Context.php
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -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)) {
Expand Down
23 changes: 23 additions & 0 deletions src/Knp/FriendlyContexts/Context/DocumentContext.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<?php

namespace Knp\FriendlyContexts\Context;

use Doctrine\ODM\MongoDB\SchemaManager;

class DocumentContext extends Context
{
/**
* @BeforeScenario
*/
public function beforeScenario($event)
{
$this->storeTags($event);

if ($this->hasTags([ 'reset-collections', '~not-reset-collections' ])) {
$dm = $this->getEntityManager();
$scm = new SchemaManager($dm, $dm->getMetadataFactory());

$scm->dropCollections();
}
}
}
1 change: 0 additions & 1 deletion src/Knp/FriendlyContexts/Context/EntityContext.php
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,6 @@ public function beforeScenario($event)
}
}
}

}

/**
Expand Down