Skip to content

Commit 9adc8d6

Browse files
committed
OXDEV-9129 Use other var directory for testing
1 parent 1f80067 commit 9adc8d6

File tree

7 files changed

+42
-24
lines changed

7 files changed

+42
-24
lines changed

.env.dist

+1
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,4 @@ OXID_DEBUG_MODE=false
55
OXID_DB_URL=mysql://root:root@mysql:3306/example?charset=utf8&driverOptions[1002]="SET @@SESSION.sql_mode=\"\""
66
OXID_BUILD_DIRECTORY=/var/www/var/cache/
77
OXID_SHOP_BASE_URL=http://localhost.local/
8+
OXID_VAR_DIRECTORY=var

phpunit.xml

+3
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,9 @@
1414
displayDetailsOnTestsThatTriggerWarnings="true"
1515
displayDetailsOnTestsThatTriggerErrors="true"
1616
>
17+
<php>
18+
<env name="OXID_VAR_DIRECTORY" value="var-test" />
19+
</php>
1720
<testsuites>
1821
<testsuite name="Unit">
1922
<directory>tests/Unit</directory>

source/Internal/Transition/Utility/BasicContext.php

+17-2
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,11 @@ public function getContainerCacheFilePath(int $shopId): string
3636

3737
public function getGeneratedServicesFilePath(): string
3838
{
39-
return Path::join($this->getShopRootPath(), 'var', 'generated', 'generated_services.yaml');
39+
return Path::join(
40+
$this->getVarDirectory(),
41+
'generated',
42+
'generated_services.yaml'
43+
);
4044
}
4145

4246
public function getActiveModuleServicesFilePath(int $shopId): string
@@ -86,7 +90,10 @@ public function getBackwardsCompatibilityClassMap(): array
8690

8791
public function getProjectConfigurationDirectory(): string
8892
{
89-
return Path::join($this->getShopRootPath(), 'var', 'configuration');
93+
return Path::join(
94+
$this->getVarDirectory(),
95+
'configuration'
96+
);
9097
}
9198

9299
public function getShopConfigurationDirectory(int $shopId): string
@@ -143,4 +150,12 @@ public function getShopBaseUrl(): string
143150
{
144151
return getenv('OXID_SHOP_BASE_URL');
145152
}
153+
154+
private function getVarDirectory(): string
155+
{
156+
return Path::join(
157+
$this->getShopRootPath(),
158+
getenv('OXID_VAR_DIRECTORY') ?: 'var'
159+
);
160+
}
146161
}

tests/FilesystemTrait.php

+9-19
Original file line numberDiff line numberDiff line change
@@ -16,30 +16,20 @@
1616
trait FilesystemTrait
1717
{
1818
private Filesystem $filesystem;
19-
private string $varPath = '';
20-
private string $varBackupPath = '';
19+
private string $varTestPath = '';
2120

22-
public function backupVarDirectory(): void
21+
public function createTestVarDirectory(): void
2322
{
24-
$this->init();
25-
$this->filesystem->mirror($this->varPath, $this->varBackupPath);
26-
}
23+
$shopRootPath = (new ProjectRootLocator())->getProjectRoot();
24+
$this->filesystem = new Filesystem();
25+
$varPath = Path::join($shopRootPath, 'var');
26+
$this->varTestPath = Path::join($shopRootPath, getenv('OXID_VAR_DIRECTORY'));
2727

28-
public function restoreVarDirectory(): void
29-
{
30-
$this->filesystem->remove($this->varPath);
31-
$this->filesystem->mirror($this->varBackupPath, $this->varPath);
32-
$this->filesystem->remove($this->varBackupPath);
28+
$this->filesystem->mirror($varPath, $this->varTestPath);
3329
}
3430

35-
private function init(): void
31+
public function deleteTestVarDirectory(): void
3632
{
37-
$shopRootPath = (new ProjectRootLocator())->getProjectRoot();
38-
$this->filesystem = new Filesystem();
39-
$this->varPath = Path::join($shopRootPath, 'var');
40-
$this->varBackupPath = Path::join(
41-
$shopRootPath,
42-
uniqid('var.backup.', true)
43-
);
33+
$this->filesystem->remove($this->varTestPath);
4434
}
4535
}

tests/Integration/IntegrationTestCase.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@
99

1010
namespace OxidEsales\EshopCommunity\Tests\Integration;
1111

12+
use OxidEsales\EshopCommunity\Core\Di\ContainerFacade;
13+
use OxidEsales\EshopCommunity\Internal\Framework\Cache\ShopCacheCleanerInterface;
1214
use OxidEsales\EshopCommunity\Tests\ContainerTrait;
1315
use OxidEsales\EshopCommunity\Tests\DatabaseTrait;
1416
use OxidEsales\EshopCommunity\Tests\FilesystemTrait;
@@ -24,14 +26,12 @@ public function setUp(): void
2426
{
2527
parent::setUp();
2628

27-
$this->backupVarDirectory();
2829
$this->beginTransaction();
2930
}
3031

3132
public function tearDown(): void
3233
{
3334
$this->rollBackTransaction();
34-
$this->restoreVarDirectory();
3535

3636
parent::tearDown();
3737
}

tests/bootstrap.php

+9
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
use OxidEsales\EshopCommunity\Core\Autoload\ModuleAutoload;
1212
use OxidEsales\EshopCommunity\Internal\Framework\Env\DotenvLoader;
1313
use OxidEsales\EshopCommunity\Internal\Framework\FileSystem\ProjectRootLocator;
14+
use Symfony\Component\Filesystem\Filesystem;
1415
use Symfony\Component\Filesystem\Path;
1516

1617
define('INSTALLATION_ROOT_PATH', (new ProjectRootLocator())->getProjectRoot());
@@ -25,3 +26,11 @@
2526
require_once Path::join(OX_BASE_PATH, 'overridablefunctions.php');
2627

2728
(new DotenvLoader(INSTALLATION_ROOT_PATH))->loadEnvironmentVariables();
29+
30+
$filesystem = new Filesystem();
31+
$varPath = Path::join(INSTALLATION_ROOT_PATH, 'var');
32+
$varTestPath = Path::join(INSTALLATION_ROOT_PATH, getenv('OXID_VAR_DIRECTORY'));
33+
34+
$filesystem->remove($varTestPath);
35+
$filesystem->mirror($varPath, $varTestPath);
36+
$filesystem->remove(Path::join($varTestPath, 'cache'));

tests/scripts/integration.sh

+1-1
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ function init() {
4343
fi
4444
fi
4545

46-
BOOTSTRAP="/var/www/source/bootstrap.php"
46+
BOOTSTRAP="/var/www/tests/bootstrap.php"
4747
if [ ! -f "${BOOTSTRAP}" ]; then
4848
BOOTSTRAP="/var/www/vendor/oxid-esales/oxideshop-ce/tests/bootstrap.php"
4949
if [ ! -f "${BOOTSTRAP}" ]; then

0 commit comments

Comments
 (0)