Skip to content

Commit 3563de1

Browse files
committed
Refactor DoctrineModule
1 parent abacfee commit 3563de1

File tree

1 file changed

+24
-11
lines changed

1 file changed

+24
-11
lines changed

src/Module/DoctrineModule.php

Lines changed: 24 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -18,24 +18,37 @@
1818

1919
class DoctrineModule extends Module
2020
{
21+
/**
22+
* @var string
23+
*/
24+
private $path;
25+
26+
public function _beforeSuite($settings = [])
27+
{
28+
$this->path = $settings['path'];
29+
}
30+
2131
public function _before(TestInterface $test)
2232
{
23-
if ($this->config['dump']) {
33+
if ($this->config['loadFiles']) {
2434
$em = $this->getModule(NetteDIModule::class)->grabService(EntityManagerInterface::class);
2535
$connection = $em->getConnection();
26-
$generator = $this->load(file_get_contents($this->config['dump']));
2736

28-
try {
29-
foreach ($generator as $command) {
30-
$stmt = $connection->prepare($command);
31-
if (!$stmt->execute()) {
32-
$error = $stmt->errorInfo();
33-
throw new ModuleConfigException(__CLASS__, $error[2]);
37+
foreach ((array) $this->config['loadFiles'] as $file) {
38+
$generator = $this->load(file_get_contents($this->path.'/'.$file));
39+
40+
try {
41+
foreach ($generator as $command) {
42+
$stmt = $connection->prepare($command);
43+
if (!$stmt->execute()) {
44+
$error = $stmt->errorInfo();
45+
throw new ModuleConfigException(__CLASS__, $error[2]);
46+
}
47+
$stmt->closeCursor();
3448
}
35-
$stmt->closeCursor();
49+
} catch (PDOException $e) {
50+
throw new ModuleConfigException(__CLASS__, $e->getMessage(), $e);
3651
}
37-
} catch (PDOException $e) {
38-
throw new ModuleConfigException(__CLASS__, $e->getMessage(), $e);
3952
}
4053
}
4154
}

0 commit comments

Comments
 (0)