-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy pathSandboxPrepare.php
40 lines (30 loc) · 1.07 KB
/
SandboxPrepare.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
<?php
namespace PHPChunkit\Test\Listener;
use PHPChunkit\Configuration;
use PHPChunkit\ListenerInterface;
class SandboxPrepare implements ListenerInterface
{
/**
* @var Configuration
*/
private $configuration;
public function __construct(Configuration $configuration)
{
$this->configuration = $configuration;
}
public function execute()
{
$configDir = sprintf('%s/bin/config', $this->configuration->getRootDir());
$configFilePath = sprintf('%s/databases_test.ini', $configDir);
$configFileBackupPath = sprintf('%s/databases_test.ini.bak', $configDir);
copy($configFilePath, $configFileBackupPath);
$configContent = file_get_contents($configFilePath);
$databaseSandbox = $this->configuration->getDatabaseSandbox();
$modifiedConfigContent = str_replace(
$databaseSandbox->getTestDatabaseNames(),
$databaseSandbox->getSandboxedDatabaseNames(),
$configContent
);
file_put_contents($configFilePath, $modifiedConfigContent);
}
}