Skip to content

Commit 28854fd

Browse files
committed
Fix problem with SQLiteJournal
1 parent b39a4e2 commit 28854fd

File tree

3 files changed

+40
-16
lines changed

3 files changed

+40
-16
lines changed

src/Module/Container.php

Lines changed: 39 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,14 @@
1111
namespace Arachne\Codeception\Module;
1212

1313
use Codeception\Module;
14-
use Codeception\TestCase;
14+
use Codeception\TestInterface;
15+
use Nette\Caching\Storages\IJournal;
16+
use Nette\Caching\Storages\SQLiteJournal;
1517
use Nette\Configurator;
18+
use Nette\DI\MissingServiceException;
19+
use Nette\Http\Session;
1620
use Nette\Utils\FileSystem;
21+
use ReflectionProperty;
1722

1823
class Container extends Module
1924
{
@@ -33,25 +38,52 @@ class Container extends Module
3338
*/
3439
private $path;
3540

41+
/**
42+
* @var Container
43+
*/
44+
private $container;
45+
3646
public function _beforeSuite($settings = [])
3747
{
3848
$this->path = $settings['path'];
3949
}
4050

41-
public function _before(TestCase $test)
51+
public function _before(TestInterface $test)
4252
{
4353
$tempDir = $this->path.'/'.$this->config['tempDir'];
4454
FileSystem::delete($tempDir);
4555
FileSystem::createDir($tempDir);
56+
$this->container = null;
4657
}
4758

48-
public function _afterSuite()
59+
public function _after(TestInterface $test)
4960
{
50-
FileSystem::delete($this->path.'/'.$this->config['tempDir']);
61+
if ($this->container) {
62+
try {
63+
$this->container->getByType(Session::class)->close();
64+
} catch (MissingServiceException $e) {
65+
}
66+
67+
try {
68+
$journal = $this->container->getByType(IJournal::class);
69+
if ($journal instanceof SQLiteJournal) {
70+
$property = new ReflectionProperty(SQLiteJournal::class, 'pdo');
71+
$property->setAccessible(true);
72+
$property->setValue($journal, null);
73+
}
74+
} catch (MissingServiceException $e) {
75+
}
76+
77+
FileSystem::delete($this->container->getParameters()['tempDir']);
78+
}
5179
}
5280

5381
public function createContainer(array $configFiles = null)
5482
{
83+
if ($this->container) {
84+
$this->fail('Can\'t create more than one container.');
85+
}
86+
5587
$configurator = new $this->config['configurator']();
5688

5789
if ($this->config['logDir']) {
@@ -72,6 +104,8 @@ public function createContainer(array $configFiles = null)
72104
$configurator->addConfig($this->path.'/'.$file, false);
73105
}
74106

75-
return $configurator->createContainer();
107+
$this->container = $configurator->createContainer();
108+
109+
return $this->container;
76110
}
77111
}

src/Module/Nette.php

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616
use Codeception\TestCase;
1717
use Nette\DI\Container;
1818
use Nette\DI\MissingServiceException;
19-
use Nette\Utils\FileSystem;
2019

2120
/**
2221
* @author Jáchym Toušek <enumag@gmail.com>
@@ -83,15 +82,6 @@ public function _after(TestCase $test)
8382
{
8483
parent::_after($test);
8584

86-
if ($this->container) {
87-
try {
88-
$this->container->getByType('Nette\Http\Session')->close();
89-
} catch (MissingServiceException $e) {
90-
}
91-
92-
FileSystem::delete($this->container->getParameters()['tempDir']);
93-
}
94-
9585
$_SESSION = [];
9686
$_GET = [];
9787
$_POST = [];

tests/integration.suite.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ modules:
77
- Arachne\Codeception\Module\Nette:
88
followRedirects: false
99
- Arachne\Codeception\Module\Container:
10-
configurator: Arachne\Bootstrap\Configurator
1110
tempDir: ../_temp/integration
11+
configurator: Arachne\Bootstrap\Configurator
1212
configFiles:
1313
- config/config.neon

0 commit comments

Comments
 (0)