diff --git a/README.md b/README.md index 998fe91..43a03cc 100644 --- a/README.md +++ b/README.md @@ -29,15 +29,15 @@ default: paths: - %paths.base%/Tests/Functional/features contexts: - - MainContext - - ApiContext - - DoctrineContext: + - ETNA\FeatureContext\MainContext + - ETNA\FeatureContext\ApiContext + - ETNA\FeatureContext\DoctrineContext: max_queries: 10 - - ElasticContext - - FixedDateContext: + - ETNA\FeatureContext\ElasticContext + - ETNA\FeatureContext\FixedDateContext: date: "2016-04-12 14:42:42" - - AuthContext - - TimeProfilerContext: + - ETNA\FeatureContext\AuthContext + - ETNA\FeatureContext\TimeProfilerContext: max_time: 200 formatters: progress: @@ -51,15 +51,15 @@ ci: suites: default: contexts: - - MainContext - - ApiContext - - DoctrineContext: + - ETNA\FeatureContext\MainContext + - ETNA\FeatureContext\ApiContext + - ETNA\FeatureContext\DoctrineContext: max_queries: 10 - - ElasticContext - - FixedDateContext: + - ETNA\FeatureContext\ElasticContext + - ETNA\FeatureContext\FixedDateContext: date: "2016-04-12 14:42:42" - - AuthContext - - CoverageContext: + - ETNA\FeatureContext\AuthContext + - ETNA\FeatureContext\CoverageContext: coverage_path: /tmp/behat/coverage whitelist: - app diff --git a/src/contexts/ApiContext.php b/src/ApiContext.php similarity index 86% rename from src/contexts/ApiContext.php rename to src/ApiContext.php index f3bd303..b8969e7 100644 --- a/src/contexts/ApiContext.php +++ b/src/ApiContext.php @@ -1,5 +1,7 @@ getContext('DoctrineContext')->checkMaxQueries($method, $result); + $this->getContext('ETNA\FeatureContext\DoctrineContext')->checkMaxQueries($method, $result); $this->response = $result; } @@ -100,6 +102,16 @@ public function leStatusHTTPDevraitEtre($code) } } + /** + * @Then /^le message HTTP devrait être "([^"]*)"$/ + */ + public function leMessageHTTPDevraitEtre($mess) + { + if (trim($this->response['http_message']) != "$mess") { + throw new Exception("Bad message response message {$this->response['http_message']} != {$mess}"); + } + } + /** * @Then /^je devrais avoir un résultat d\'API en JSON$/ */ @@ -119,6 +131,15 @@ public function jeDevraisAvoirUnResultatDApiEnJSON() $this->data = $json; } + /** + * @Given /^je devrais avoir un résultat d\'API en PDF$/ + */ + public function jeDevraisAvoirUnResultatDApiEnPdf() + { + if ("application/pdf" !== $this->response["headers"]["content-type"]) { + throw new Exception("Invalid response type"); + } + } /** * @Given /^je devrais avoir un résultat d\'API en CSV$/ @@ -199,4 +220,14 @@ public function leResultatDevraitRessemblerAuFichier($file) $file = realpath($this->results_path . "/" . $file); $this->leResultatDevraitRessemblerAuJsonSuivant(file_get_contents($file)); } + + /** + * @Then /^je devrais avoir un objet comme résultat$/ + */ + public function jeDevraisAvoirUnObjetCommeResultat() + { + if (!is_object($this->data)) { + throw new Exception("{$this->data} is not an object"); + } + } } diff --git a/src/contexts/AuthContext.php b/src/AuthContext.php similarity index 92% rename from src/contexts/AuthContext.php rename to src/AuthContext.php index 8a0f7f3..4ff5987 100644 --- a/src/contexts/AuthContext.php +++ b/src/AuthContext.php @@ -1,5 +1,7 @@ getEnvironment(); - $this->request = $environment->getContext('ApiContext')->getRequest(); + $this->request = $environment->getContext('ETNA\FeatureContext\ApiContext')->getRequest(); } /** @@ -50,7 +52,7 @@ public function setRequest(AfterStepScope $scope) { $environment = $scope->getEnvironment(); - $environment->getContext('ApiContext')->setRequest($this->request); + $environment->getContext('ETNA\FeatureContext\ApiContext')->setRequest($this->request); } /** diff --git a/src/contexts/BaseContext.php b/src/BaseContext.php similarity index 94% rename from src/contexts/BaseContext.php rename to src/BaseContext.php index 489b520..c0e30b5 100644 --- a/src/contexts/BaseContext.php +++ b/src/BaseContext.php @@ -1,5 +1,7 @@ getSilexApp(); + self::$silex_app = $contexts['ETNA\FeatureContext\MainContext']->getSilexApp(); } /** @@ -40,12 +42,12 @@ protected function getContext($context) */ protected function getParameter($name) { - return self::$contexts['MainContext']->getParameter($name); + return self::$contexts['ETNA\FeatureContext\MainContext']->getParameter($name); } protected static function setParameter($name, $value) { - self::$contexts['MainContext']->setParameter($name, $value); + self::$contexts['ETNA\FeatureContext\MainContext']->setParameter($name, $value); } /** diff --git a/src/contexts/CoverageContext.php b/src/CoverageContext.php similarity index 95% rename from src/contexts/CoverageContext.php rename to src/CoverageContext.php index 48b1cf8..b6b871b 100644 --- a/src/contexts/CoverageContext.php +++ b/src/CoverageContext.php @@ -1,5 +1,7 @@ getEnvironment(); $contexts_params = $environment->getContextClassesWithArguments(); - self::$_coverage_params = $contexts_params['CoverageContext']; + self::$_coverage_params = $contexts_params['ETNA\FeatureContext\CoverageContext']; } /** diff --git a/src/contexts/DoctrineContext.php b/src/DoctrineContext.php similarity index 98% rename from src/contexts/DoctrineContext.php rename to src/DoctrineContext.php index a6e8653..b8e8d74 100644 --- a/src/contexts/DoctrineContext.php +++ b/src/DoctrineContext.php @@ -1,5 +1,7 @@ getEnvironment()->getContextClassesWithArguments()['ServerContext']; + $params = $scope->getEnvironment()->getContextClassesWithArguments()['ETNA\FeatureContext\ServerContext']; $url = parse_url($params['url']); $port = !empty($url['port']) ? $url['port'] : 80; diff --git a/src/contexts/SvnContext.php b/src/SvnContext.php similarity index 96% rename from src/contexts/SvnContext.php rename to src/SvnContext.php index 65671d7..47800f3 100644 --- a/src/contexts/SvnContext.php +++ b/src/SvnContext.php @@ -1,5 +1,7 @@ getEnvironment()->hasContextClass("CoverageContext"); + $has_coverage = $scope->getEnvironment()->hasContextClass("ETNA\FeatureContext\CoverageContext"); if (true === $has_coverage) { return; }