Skip to content

Commit 2016520

Browse files
committed
Add Container module
1 parent 066098b commit 2016520

File tree

1 file changed

+69
-0
lines changed

1 file changed

+69
-0
lines changed

src/Module/Container.php

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
<?php
2+
3+
namespace Arachne\Codeception\Module;
4+
5+
use Codeception\Module;
6+
use Codeception\TestCase;
7+
use Nette\Configurator;
8+
use Nette\Utils\FileSystem;
9+
10+
class Container extends Module
11+
{
12+
protected $config = [
13+
'configFiles' => [],
14+
'logDir' => null,
15+
'debugMode' => null,
16+
'configurator' => Configurator::class,
17+
];
18+
19+
protected $requiredFields = [
20+
'tempDir',
21+
];
22+
23+
/**
24+
* @var string
25+
*/
26+
private $path;
27+
28+
public function _beforeSuite($settings = [])
29+
{
30+
$this->path = $settings['path'];
31+
}
32+
33+
public function _before(TestCase $test)
34+
{
35+
$tempDir = $this->path.'/'.$this->config['tempDir'];
36+
FileSystem::delete($tempDir);
37+
FileSystem::createDir($tempDir);
38+
}
39+
40+
public function _afterSuite()
41+
{
42+
FileSystem::delete($this->path.'/'.$this->config['tempDir']);
43+
}
44+
45+
public function createContainer(array $configFiles = null)
46+
{
47+
$configurator = new $this->config['configurator']();
48+
49+
if ($this->config['logDir']) {
50+
$configurator->enableDebugger($this->path.'/'.$this->config['logDir']);
51+
}
52+
53+
$tempDir = $this->path.'/'.$this->config['tempDir'];
54+
FileSystem::delete($tempDir);
55+
FileSystem::createDir($tempDir);
56+
$configurator->setTempDirectory($tempDir);
57+
58+
if ($this->config['debugMode'] !== null) {
59+
$configurator->setDebugMode($this->config['debugMode']);
60+
}
61+
62+
$configFiles = is_array($configFiles) ? $configFiles : $this->config['configFiles'];
63+
foreach ($configFiles as $file) {
64+
$configurator->addConfig($this->path.'/'.$file, false);
65+
}
66+
67+
return $configurator->createContainer();
68+
}
69+
}

0 commit comments

Comments
 (0)