Skip to content

Commit c6b124a

Browse files
committed
merged with 2.1
1 parent a41fd27 commit c6b124a

File tree

2 files changed

+241
-96
lines changed

2 files changed

+241
-96
lines changed

src/Codeception/Lib/Connector/Symfony.php

Lines changed: 54 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -3,63 +3,84 @@
33

44
class Symfony extends \Symfony\Component\HttpKernel\Client
55
{
6-
76
/**
87
* @var boolean
98
*/
10-
private static $hasPerformedRequest;
9+
private $rebootable = true;
10+
11+
/**
12+
* @var boolean
13+
*/
14+
private $hasPerformedRequest = false;
15+
16+
/**
17+
* @var \Symfony\Component\DependencyInjection\ContainerInterface
18+
*/
19+
private $container = null;
1120

1221
/**
1322
* @var array
1423
*/
1524
public $persistentServices = [];
1625

1726
/**
18-
* @param Request $request
27+
* Constructor.
28+
*
29+
* @param \Symfony\Component\HttpKernel\Kernel $kernel A booted HttpKernel instance
30+
* @param array $services An injected services
31+
* @param boolean $rebootable
1932
*/
20-
protected function doRequest($request)
33+
public function __construct(\Symfony\Component\HttpKernel\Kernel $kernel, array $services = [], $rebootable = true)
2134
{
22-
$services = [];
23-
if (self::$hasPerformedRequest) {
24-
$services = $this->persistServices();
25-
$this->kernel = clone $this->kernel;
26-
} else {
27-
self::$hasPerformedRequest = true;
28-
}
29-
$this->kernel->boot();
30-
31-
$container = $this->kernel->getContainer();
32-
if ($this->kernel->getContainer()->has('profiler')) {
33-
$container->get('profiler')->enable();
34-
}
35-
36-
$this->injectPersistedServices($services);
37-
38-
return parent::doRequest($request);
35+
parent::__construct($kernel);
36+
$this->followRedirects(true);
37+
$this->rebootable = (boolean)$rebootable;
38+
$this->persistentServices = $services;
39+
$this->rebootKernel();
3940
}
4041

4142
/**
42-
* @return array
43+
* @param \Symfony\Component\HttpFoundation\Request $request
4344
*/
44-
protected function persistServices()
45+
protected function doRequest($request)
4546
{
46-
$services = [];
47-
foreach ($this->persistentServices as $serviceName) {
48-
if (!$this->kernel->getContainer()->has($serviceName)) {
49-
continue;
47+
if ($this->rebootable) {
48+
if ($this->hasPerformedRequest) {
49+
$this->rebootKernel();
50+
} else {
51+
$this->hasPerformedRequest = true;
5052
}
51-
$services[$serviceName] = $this->kernel->getContainer()->get($serviceName);
5253
}
53-
return $services;
54+
return parent::doRequest($request);
5455
}
5556

5657
/**
57-
* @param array $services
58+
* Reboot kernel
59+
*
60+
* Services from the list of persistent services
61+
* are updated from service container before kernel shutdown
62+
* and injected into newly initialized container after kernel boot.
5863
*/
59-
protected function injectPersistedServices($services)
64+
public function rebootKernel()
6065
{
61-
foreach ($services as $serviceName => $service) {
62-
$this->kernel->getContainer()->set($serviceName, $service);
66+
if ($this->container) {
67+
foreach ($this->persistentServices as $serviceName => $service) {
68+
if ($this->container->has($serviceName)) {
69+
$this->persistentServices[$serviceName] = $this->container->get($serviceName);
70+
}
71+
}
72+
}
73+
74+
$this->kernel->shutdown();
75+
$this->kernel->boot();
76+
$this->container = $this->kernel->getContainer();
77+
78+
if ($this->container->has('profiler')) {
79+
$this->container->get('profiler')->enable();
80+
}
81+
82+
foreach ($this->persistentServices as $serviceName => $service) {
83+
$this->container->set($serviceName, $service);
6384
}
6485
}
6586
}

0 commit comments

Comments
 (0)