My project uses Symfony 2.6. I am trying to isolate my test in order to don't commit any change on my database.
I manage to isolate my test with only one request. But when there are many of them, it doesn't work and I can't manage to find why. Any ideas ?
Here is my testController code :
use Symfony\Bundle\FrameworkBundle\Test\WebTestCase;
class RequestControllerTest extends WebTestCase{
protected $client;
protected $entityManager;
protected function setUp(){
parent::setUp();
$this->client = static::createClient();
$this->entityManager = $this->client->getContainer()->get('doctrine')->getManager();
$this->entityManager->beginTransaction();
}
protected function tearDown(){
parent::tearDown();
$this->entityManager->rollback();
$this->entityManager->close();
}
// This test is working just fine : the request isn't deleted from database at the end
public function testIsolationOK(){
$this->client->request('DELETE', self::WEB_SERVICES_EXISTING_REQUEST_URL);
$this->client->request('GET', self::WEB_SERVICES_EXISTING_REQUEST_URL);
}
// But this one isn't working : the request is deleted from database at the end
public function testIsolationNOK(){
$this->client->request('GET', self::WEB_SERVICES_EXISTING_REQUEST_URL);
$this->client->request('DELETE', self::WEB_SERVICES_EXISTING_REQUEST_URL);
}
}
Aucun commentaire:
Enregistrer un commentaire