Last active
August 29, 2015 14:17
-
-
Save cbrunnkvist/b0071b5447584b65b8c4 to your computer and use it in GitHub Desktop.
Make a LiipFunctionalTestBundle::WebTestCase explicitly close (some) Doctrine DB connections
This file contains 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 MVMS\ApiBundle\Tests; | |
trait ClosesConnectionsAfterTestTrait | |
{ | |
public static $dbConnections = []; | |
/** @after */ | |
public function ensureDbConnectionsGetClosed() | |
{ | |
while ($conn = array_pop(self::$dbConnections)) { | |
$conn->close(); | |
} | |
} | |
/** @before */ | |
public function saveDbConnectionInClass() | |
{ | |
self::$dbConnections[] = $this->getContainer()->get('doctrine')->getConnection(); | |
if (property_exists($this, 'client')) { | |
self::$dbConnections[] = $this->client->getKernel()->getContainer()->get('doctrine')->getConnection(); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment