From cb660e2624868a4d0b967526876317907e861870 Mon Sep 17 00:00:00 2001 From: Jean BILLAUD Date: Thu, 21 Mar 2019 11:14:53 +0100 Subject: [PATCH 1/4] [FEATURE#133499] Ajout du Doctrine Context --- src/DoctrineContext.php | 75 +++++++++++++---------------------------- 1 file changed, 24 insertions(+), 51 deletions(-) diff --git a/src/DoctrineContext.php b/src/DoctrineContext.php index 5a6a0ce..3214e02 100644 --- a/src/DoctrineContext.php +++ b/src/DoctrineContext.php @@ -1,63 +1,36 @@ = self::$max_queries) { - $queries = []; - foreach (json_decode($response["headers"]["x-orm-profiler-queries"]) as $query) { - $queries[md5($query->sql)]["sql"] = $query->sql; - $queries[md5($query->sql)]["params"][] = $query->params; - } - - throw new PendingException("Too many SQL queries ({$response["headers"]["x-orm-profiler-count"]})"); + $actual_queries_count = $response["headers"]["x-orm-profiler-count"]; + self::$query_count += $actual_queries_count; + if ($actual_queries_count >= self::$max_queries) { + $this->getContext("ETNA\FeatureContext\ExceptionContainerContext") + ->setException(new PendingException("Too many SQL queries ({$response["headers"]["x-orm-profiler-count"]})")); } } - /** - * @BeforeScenario - */ - public function resetProfiler() - { - // Ouais - self::$query_count += self::$silex_app["orm.profiler"]->currentQuery; - - self::$silex_app["orm.profiler"]->queries = []; - self::$silex_app["orm.profiler"]->currentQuery = 0; - - self::$max_queries = $this->getParameter("max_queries"); - } - - /** - * @AfterSuite - */ - public static function showQueryCount() - { - echo "\n# total queries : ", self::$query_count, "\n"; - } - /** * @Given /j\'ai le droit de faire (\d+) requetes SQL$/ */ @@ -66,14 +39,14 @@ public function jaiLeDroitDeFaireRequetesSql($nb) self::$max_queries = $nb; } - /** + /** * @BeforeScenario */ public function beginTransaction() { - //Ouais - self::$silex_app["db"]->beginTransaction(); - self::$silex_app["orm.em"]->clear(); + $em = $this->getContainer()->get('doctrine')->getManager(); + $em->getConnection()->beginTransaction(); + $em->clear(); } /** @@ -81,7 +54,7 @@ public function beginTransaction() */ public function rollback() { - //Ouais - self::$silex_app["db"]->rollback(); + $em = $this->getContainer()->get('doctrine')->getManager(); + $em->getConnection()->rollback(); } } From edc0e832dc6edefc398ab429550c34709aa8d3e7 Mon Sep 17 00:00:00 2001 From: Jean BILLAUD Date: Thu, 21 Mar 2019 11:19:19 +0100 Subject: [PATCH 2/4] [FEATURE#133499] Suppression lignes inutiles --- src/DoctrineContext.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/DoctrineContext.php b/src/DoctrineContext.php index 3214e02..162e9f3 100644 --- a/src/DoctrineContext.php +++ b/src/DoctrineContext.php @@ -1,10 +1,10 @@ Date: Thu, 21 Mar 2019 11:43:55 +0100 Subject: [PATCH 3/4] [FEATURE#133499] Retour de la fonction dump --- src/DoctrineContext.php | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/src/DoctrineContext.php b/src/DoctrineContext.php index 162e9f3..438b87e 100644 --- a/src/DoctrineContext.php +++ b/src/DoctrineContext.php @@ -21,6 +21,15 @@ public function __construct($max_queries) self::$max_queries = $max_queries; } + /** + * @BeforeSuite + */ + public static function dump() + { + passthru("vendor/doctrine/orm/bin/doctrine orm:schema-tool:drop --force --full-database"); + passthru("./bin/dump ./Tests/Data/test*.sql"); + } + public function checkMaxQueries($response) { $actual_queries_count = $response["headers"]["x-orm-profiler-count"]; From af474734f5ccfc458b04561005db2dd178ce2d83 Mon Sep 17 00:00:00 2001 From: Jean BILLAUD Date: Fri, 22 Mar 2019 10:40:21 +0100 Subject: [PATCH 4/4] [FEATURE#133499] PendingException -> Exception --- src/DoctrineContext.php | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/DoctrineContext.php b/src/DoctrineContext.php index 438b87e..2d17f90 100644 --- a/src/DoctrineContext.php +++ b/src/DoctrineContext.php @@ -3,7 +3,6 @@ namespace ETNA\FeatureContext; use ETNA\FeatureContext\BaseContext; -use Behat\Behat\Tester\Exception\PendingException; /** * This context class contains the definitions of the steps used by the demo @@ -36,7 +35,7 @@ public function checkMaxQueries($response) self::$query_count += $actual_queries_count; if ($actual_queries_count >= self::$max_queries) { $this->getContext("ETNA\FeatureContext\ExceptionContainerContext") - ->setException(new PendingException("Too many SQL queries ({$response["headers"]["x-orm-profiler-count"]})")); + ->setException(new \Exception("Too many SQL queries ({$response["headers"]["x-orm-profiler-count"]})")); } }