Created
March 29, 2013 19:34
-
-
Save tystr/5273057 to your computer and use it in GitHub Desktop.
A simple base WebTestCase class
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?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); | |
| } | |
| } | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Where did you get ChangeDatabaseEventListener ?