Skip to content

Instantly share code, notes, and snippets.

@tystr
Created March 29, 2013 19:34
Show Gist options
  • Select an option

  • Save tystr/5273057 to your computer and use it in GitHub Desktop.

Select an option

Save tystr/5273057 to your computer and use it in GitHub Desktop.
A simple base WebTestCase class
<?php
namespace ...\Bundle\MyBuyndle\Tests;
use Symfony\Bundle\FrameworkBundle\Test\WebTestCase as BaseWebTestCase;
use Symfony\Component\HttpFoundation\Response;
/**
* @author Tyler Stroud <tyler@tylerstroud.com>
*/
class WebTestCase extends BaseWebTestCase
{
/**
* @var \Symfony\Bundle\FrameworkBundle\Client
*/
protected $client;
protected $debug = false;
public function setUp()
{
$this->client = static::createClient(['debug' => $this->debug]);
$container = $this->client->getContainer();
$container
->get('doctrine.odm.mongodb.document_manager')
->getEventManager()
->addEventListener(
['loadClassMetadata'],
new ChangeDatabaseEventListener($container->getParameter('my.mongodb.database'))
);
}
public function tearDown()
{
$container = $this->client->getContainer();
$dm = $container->get('doctrine.odm.mongodb.document_manager');
$collections = $dm->getConnection()
->selectDatabase($container->getParameter('my.mongodb.database'))->listCollections();
foreach ($collections as $collection) {
$collection->drop();
}
$refl = new \ReflectionObject($this);
foreach ($refl->getProperties() as $prop) {
if (!$prop->isStatic() && 0 !== strpos($prop->getDeclaringClass()->getName(), 'PHPUnit_')) {
$prop->setAccessible(true);
$prop->setValue($this, null);
}
}
}
}
@dizda
Copy link

dizda commented Jun 9, 2013

Where did you get ChangeDatabaseEventListener ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment