Skip to content

Commit

Permalink
Remove Deprecated prepareLegacyRequest method.
Browse files Browse the repository at this point in the history
  • Loading branch information
guncha25 committed Sep 17, 2020
1 parent 0eadec9 commit 57e39cc
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 24 deletions.
4 changes: 1 addition & 3 deletions src/Codeception/Module/DrupalBootstrap.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
use Codeception\Module;
use Codeception\TestDrupalKernel;
use Symfony\Component\HttpFoundation\Request;
use Drupal\Core\DrupalKernel;
use DrupalFinder\DrupalFinder;


Expand Down Expand Up @@ -70,8 +69,7 @@ public function __construct(ModuleContainer $container, $config = NULL) {
$request = Request::createFromGlobals();
$autoloader = require $this->_getConfig('root') . '/autoload.php';
$kernel = new TestDrupalKernel('prod', $autoloader, $this->_getConfig('root'));
$kernel->bootTestEnvironment($this->_getConfig('site_path'));
$kernel->prepareLegacyRequest($request);
$kernel->bootTestEnvironment($this->_getConfig('site_path'), $request);
}

}
55 changes: 34 additions & 21 deletions src/Codeception/TestDrupalKernel.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,33 +2,46 @@

namespace Codeception;

use Drupal\Core\DependencyInjection\Container;
use Drupal\Core\DrupalKernel;
use Drupal\Core\Site\Settings;
use Symfony\Cmf\Component\Routing\RouteObjectInterface;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\Routing\Route;

class TestDrupalKernel extends DrupalKernel{

/**
* TestDrupalKernel constructor.
*/
public function __construct($env, $class_loader, $root){
$this->root = $root;
parent::__construct($env, $class_loader);
/**
* TestDrupalKernel constructor.
*/
public function __construct($env, $class_loader, $root){
$this->root = $root;
parent::__construct($env, $class_loader);
}

/**
* Boots test environment.
*
* @param \Symfony\Component\HttpFoundation\Request $request
* The current request.
* @param string $sitePath
* The current site path.
*
* @throws \Exception
*/
public function bootTestEnvironment($sitePath, Request $request){
static::bootEnvironment();
$this->setSitePath($sitePath);
$this->loadLegacyIncludes();
Settings::initialize($this->root, $sitePath, $this->classLoader);
$this->boot();
$this->preHandle($request);
if (PHP_SAPI !== 'cli') {
$request->setSession($this->container->get('session'));
}

/**
* Boots test environment.
*
* @var string $sitePath
* Site path.
*/
public function bootTestEnvironment($sitePath){
static::bootEnvironment();
$this->setSitePath($sitePath);
$this->loadLegacyIncludes();
Settings::initialize($this->root, $sitePath, $this->classLoader);
$this->boot();
}
$request->attributes->set(RouteObjectInterface::ROUTE_OBJECT, new Route('<none>'));
$request->attributes->set(RouteObjectInterface::ROUTE_NAME, '<none>');
$this->container->get('request_stack')->push($request);
$this->container->get('router.request_context')->fromRequest($request);
}

}

0 comments on commit 57e39cc

Please sign in to comment.