Browse Source

Modification apporté pour que les tests n'impacte pas la base de donnée.

bastien 13 years ago
parent
commit
0d63c24753
1 changed files with 40 additions and 0 deletions
  1. 40 0
      src/Muzich/CoreBundle/lib/Test/Client.php

+ 40 - 0
src/Muzich/CoreBundle/lib/Test/Client.php View File

@@ -0,0 +1,40 @@
1
+<?php
2
+
3
+namespace Muzich\CoreBundle\lib\Test;
4
+
5
+use Symfony\Bundle\FrameworkBundle\Client as BaseClient;
6
+
7
+class Client extends BaseClient
8
+{
9
+  static protected $connection;
10
+  protected $requested;
11
+
12
+    protected function doRequest($request)
13
+    {
14
+        if ($this->requested) {
15
+            $this->kernel->shutdown();
16
+            $this->kernel->boot();
17
+        }
18
+
19
+        $this->injectConnection();
20
+        $this->requested = true;
21
+
22
+        return $this->kernel->handle($request);
23
+    }
24
+
25
+    protected function injectConnection()
26
+    {
27
+        if (null === self::$connection) {
28
+            self::$connection = $this->getContainer()->get('doctrine.dbal.default_connection');
29
+        } else {
30
+            if (! $this->requested) {
31
+                self::$connection->rollback();
32
+            }
33
+            $this->getContainer()->set('doctrine.dbal.default_connection', self::$connection);
34
+        }
35
+
36
+        if (! $this->requested) {
37
+            self::$connection->beginTransaction();
38
+        }
39
+    }
40
+}