Skip to content

Instantly share code, notes, and snippets.

@cbrunnkvist
Last active August 29, 2015 14:17
Show Gist options
  • Save cbrunnkvist/b0071b5447584b65b8c4 to your computer and use it in GitHub Desktop.
Save cbrunnkvist/b0071b5447584b65b8c4 to your computer and use it in GitHub Desktop.
Make a LiipFunctionalTestBundle::WebTestCase explicitly close (some) Doctrine DB connections
<?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