Skip to content

Commit

Permalink
Début du passage à Symfony
Browse files Browse the repository at this point in the history
  • Loading branch information
Guillaume DUBOST committed Jul 13, 2018
1 parent 669988d commit 7d300ea
Show file tree
Hide file tree
Showing 6 changed files with 29 additions and 74 deletions.
4 changes: 2 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@
"mcustiel/phiremock": "^1.7"
},
"require-dev": {
"phpunit/php-code-coverage": "~3.0",
"phpunit/phpcov": "~3.0"
"phpunit/php-code-coverage": "^6.0",
"phpunit/phpcov": "^5.0"
},
"autoload": {
"psr-4": {
Expand Down
6 changes: 4 additions & 2 deletions src/ApiContext.php
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ public function jeFaisUneRequetteHTTPAvecDuJSON($method, $url, $body)
$request->cookies->add($this->request["cookies"]);
$request->files->add($this->request["files"]);

$response = self::$silex_app->handle($request, HttpKernelInterface::MASTER_REQUEST, true);
$response = $this->getKernel()->handle($request, HttpKernelInterface::MASTER_REQUEST, true);

$result = [
"http_code" => $response->getStatusCode(),
Expand All @@ -98,7 +98,9 @@ function ($item) {
),
];

$this->getContext('ETNA\FeatureContext\DoctrineContext')->checkMaxQueries($method, $result);
if (isset(self::$contexts['ETNA\FeatureContext\DoctrineContext'])) {
self::$contexts['ETNA\FeatureContext\DoctrineContext']->checkMaxQueries($method, $result);
}

$this->response = $result;
}
Expand Down
11 changes: 7 additions & 4 deletions src/BaseContext.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,13 @@
use Behat\Behat\Context\Context;
use Behat\Behat\Hook\Scope\BeforeScenarioScope;

abstract class BaseContext implements Context
use Behat\Symfony2Extension\Context\KernelDictionary;
use Behat\Symfony2Extension\Context\KernelAwareContext;

abstract class BaseContext implements Context, KernelAwareContext
{
static protected $silex_app;
use KernelDictionary;

static protected $contexts;
protected $requests_path;
protected $results_path;
Expand All @@ -21,8 +25,7 @@ public function setUp(BeforeScenarioScope $scope)
$environment->getContexts()
);

self::$contexts = $contexts;
self::$silex_app = $contexts['ETNA\FeatureContext\MainContext']->getSilexApp();
self::$contexts = $contexts;
}

/**
Expand Down
24 changes: 13 additions & 11 deletions src/CoverageContext.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,15 @@
namespace ETNA\FeatureContext;

use Behat\Testwork\Hook\Scope\BeforeSuiteScope;
use PHP_CodeCoverage_Filter;
use PHP_CodeCoverage;
use PHP_CodeCoverage_Report_PHP;
use PHP_CodeCoverage_Report_HTML;
use PHP_CodeCoverage_Report_Clover;
use Behat\Behat\Context\Context;

class CoverageContext extends BaseContext
use SebastianBergmann\CodeCoverage\Filter;
use SebastianBergmann\CodeCoverage\CodeCoverage;
use SebastianBergmann\CodeCoverage\Report\PHP;
use SebastianBergmann\CodeCoverage\Report\Clover;
use SebastianBergmann\CodeCoverage\Report\Html\Facade;

class CoverageContext implements Context
{
static private $_coverage;
static private $_coverage_params;
Expand Down Expand Up @@ -45,7 +47,7 @@ public static function codeCoverageStart()
mkdir($coverage_path, 0777, true);
}

$filter = new PHP_CodeCoverage_Filter();
$filter = new Filter();
if (method_exists($filter, 'addDirectoryToBlacklist') && true === isset(self::$_coverage_params['blacklist']) && true === is_array(self::$_coverage_params['blacklist'])) {
foreach (self::$_coverage_params['blacklist'] as $blackElem) {
$filter->addDirectoryToBlacklist(getcwd() . "/{$blackElem}");
Expand All @@ -58,7 +60,7 @@ public static function codeCoverageStart()
}
}

self::$_coverage = new PHP_CodeCoverage(null, $filter);
self::$_coverage = new CodeCoverage(null, $filter);
self::$_coverage->start('Behat Test');
}

Expand All @@ -71,13 +73,13 @@ public static function codeCoverageStop()

$coverage_path = getcwd() . '/' . self::$_coverage_params['coverage_path'];

$writer = new PHP_CodeCoverage_Report_PHP;
$writer = new PHP;
$writer->process(self::$_coverage, "{$coverage_path}.php");

$writer = new PHP_CodeCoverage_Report_HTML;
$writer = new Facade;
$writer->process(self::$_coverage, $coverage_path);

$writer = new PHP_CodeCoverage_Report_Clover();
$writer = new Clover();
$writer->process(self::$_coverage, "{$coverage_path}.clover.xml");

exec("open {$coverage_path}/index.html");
Expand Down
3 changes: 3 additions & 0 deletions src/DoctrineContext.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ public function checkMaxQueries($method, $response)
*/
public function resetProfiler()
{
// Ouais
self::$query_count += self::$silex_app["orm.profiler"]->currentQuery;

self::$silex_app["orm.profiler"]->queries = [];
Expand Down Expand Up @@ -70,6 +71,7 @@ public function jaiLeDroitDeFaireRequetesSql($nb)
*/
public function beginTransaction()
{
//Ouais
self::$silex_app["db"]->beginTransaction();
self::$silex_app["orm.em"]->clear();
}
Expand All @@ -79,6 +81,7 @@ public function beginTransaction()
*/
public function rollback()
{
//Ouais
self::$silex_app["db"]->rollback();
}
}
55 changes: 0 additions & 55 deletions src/MainContext.php

This file was deleted.

0 comments on commit 7d300ea

Please sign in to comment.