Skip to content

Commit

Permalink
OXDEV-9043 Stop using VFS in tests container
Browse files Browse the repository at this point in the history
  • Loading branch information
liulka-oxid committed Jan 14, 2025
1 parent c921874 commit a4c1a92
Show file tree
Hide file tree
Showing 52 changed files with 141 additions and 320 deletions.
1 change: 0 additions & 1 deletion tests/ContainerTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,6 @@ private function createContainer(): void
private function compileContainer(): void
{
$this->container->compile(true);
$this->get('oxid_esales.module.install.service.launched_shop_project_configuration_generator')->generate();
}

private function loadYamlFixture(string $fixtureDir): void
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,23 +20,14 @@ final class BasketComponentSessionTest extends IntegrationTestCase
{
private string $articleId = '1000';

private bool $configBlUseStock;

public function setUp(): void
{
parent::setUp();
$this->configBlUseStock = Registry::getConfig()->getConfigParam('blUseStock');
Registry::getConfig()->setConfigParam('blUseStock', false);
Registry::getSession()->setVariable('aLastcall', []);
$this->createTestProduct();
}

public function tearDown(): void
{
Registry::getConfig()->setConfigParam('blUseStock', $this->configBlUseStock);
parent::tearDown();
}

public function testChangingBasketWhenSessionChallengeValidationNotPassed(): void
{
$this->actAsSearchEngine(false);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@ final class ModuleConfigurationTest extends IntegrationTestCase

public function setUp(): void
{
$this->installTestModule();
parent::setUp();
$this->installTestModule();
}

public function tearDown(): void
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,30 +17,14 @@
use OxidEsales\EshopCommunity\Internal\Framework\Module\Configuration\DataObject\ModuleConfiguration;
use OxidEsales\EshopCommunity\Internal\Framework\Module\Setting\Setting;
use OxidEsales\EshopCommunity\Tests\ContainerTrait;
use OxidEsales\EshopCommunity\Tests\FilesystemTrait;
use OxidEsales\EshopCommunity\Tests\Integration\IntegrationTestCase;

final class ShopConfigurationTest extends IntegrationTestCase
{
use ContainerTrait;
use FilesystemTrait;

private string $testModuleId = 'testShopModuleId';

public function setUp(): void
{
parent::setUp();

$this->backupVarDirectory();
}

public function tearDown(): void
{
$this->restoreVarDirectory();

parent::tearDown();
}

public function testSaveConfVars(): void
{
$this->prepareTestModuleConfiguration();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,9 @@ public function setUp(): void

public function tearDown(): void
{
parent::setUp();

Registry::getConfig()->setAdminMode(false);

parent::tearDown();
}

public function testGetFields(): void
Expand Down
66 changes: 40 additions & 26 deletions tests/Integration/Core/LanguageTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,46 +17,60 @@
use Symfony\Contracts\Cache\ItemInterface;
use Symfony\Contracts\Cache\TagAwareCacheInterface;

class LanguageTest extends IntegrationTestCase
use function sprintf;

final class LanguageTest extends IntegrationTestCase
{
public function testTranslateCachedString(): void
public function setUp(): void
{
parent::setUp();

ContainerFacade::get(TagAwareCacheInterface::class)->invalidateTags(['oxid_esales.cache.language']);
}

public function tearDown(): void
{
$stringToTranslate = uniqid();
$cache = ContainerFacade::get(TagAwareCacheInterface::class);
ContainerFacade::get(TagAwareCacheInterface::class)->invalidateTags(['oxid_esales.cache.language']);

parent::tearDown();
}

public function testTranslateStringWithMissingTranslation(): void
{
$translationKey = uniqid('some-key-', true);
$language = new Language();
$logger = $this->createMock(LoggerInterface::class);
Registry::set('logger', $logger);

$config = Registry::getConfig();

$logger->expects($this->once())
->method('warning')
->with(sprintf('translation for %s not found', $stringToTranslate), $this->anything());

$language = new Language();
$translatedString = $language->translateString($stringToTranslate, $language->getBaseLanguage());
->with(sprintf('translation for %s not found', $translationKey), $this->anything());

$this->assertEquals($stringToTranslate, $translatedString);
$translation = $language->translateString($translationKey, $language->getBaseLanguage());

$cache->invalidateTags(['oxid_esales.cache.language']);
$this->assertEquals($translationKey, $translation);
}

$langCacheName = sprintf(
public function testTranslateStringWithTranslationInCache(): void
{
$translationKey = uniqid('some-key-', true);
$cachedTranslation = 'some-translation';
$language = new Language();
$cacheKey = sprintf(
'langcache_%d_%s_%d_%s_default',
$config->isAdmin(),
Registry::getConfig()->isAdmin(),
$language->getBaseLanguage(),
$config->getShopId(),
$config->getConfigParam('sTheme')
Registry::getConfig()->getShopId(),
Registry::getConfig()->getConfigParam('sTheme')
);
ContainerFacade::get(TagAwareCacheInterface::class)
->get($cacheKey, function (ItemInterface $item) use ($translationKey, $cachedTranslation) {
$item->tag('oxid_esales.cache.language');
return [$translationKey => $cachedTranslation];
});

$cache->get($langCacheName, function (ItemInterface $item) use ($stringToTranslate) {
$item->tag('oxid_esales.cache.language');
return [$stringToTranslate => 'translated value'];
});

$language = new Language();
$translatedString = $language->translateString($stringToTranslate, $language->getBaseLanguage());

$this->assertEquals('translated value', $translatedString);
$translation = $language->translateString($translationKey, $language->getBaseLanguage());

$cache->invalidateTags(['oxid_esales.cache.language']);
$this->assertEquals($cachedTranslation, $translation);
}
}
4 changes: 4 additions & 0 deletions tests/Integration/IntegrationTestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,23 +11,27 @@

use OxidEsales\EshopCommunity\Tests\ContainerTrait;
use OxidEsales\EshopCommunity\Tests\DatabaseTrait;
use OxidEsales\EshopCommunity\Tests\FilesystemTrait;
use PHPUnit\Framework\TestCase;

class IntegrationTestCase extends TestCase
{
use ContainerTrait;
use DatabaseTrait;
use FilesystemTrait;

public function setUp(): void
{
parent::setUp();

$this->backupVarDirectory();
$this->beginTransaction();
}

public function tearDown(): void
{
$this->rollBackTransaction();
$this->restoreVarDirectory();

parent::tearDown();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,34 +13,17 @@
use Composer\Package\Package;
use OxidEsales\ComposerPlugin\Installer\Package\ComponentInstaller;
use OxidEsales\EshopCommunity\Internal\Container\BootstrapContainerFactory;
use OxidEsales\EshopCommunity\Internal\Framework\DIContainer\Service\ProjectYamlImportServiceInterface;
use OxidEsales\EshopCommunity\Internal\Framework\FileSystem\ProjectRootLocator;
use OxidEsales\EshopCommunity\Internal\Transition\Utility\BasicContextInterface;
use OxidEsales\EshopCommunity\Tests\ContainerTrait;
use OxidEsales\EshopCommunity\Tests\FilesystemTrait;
use PHPUnit\Framework\TestCase;
use OxidEsales\EshopCommunity\Tests\Integration\IntegrationTestCase;

final class ComponentInstallerTest extends TestCase
final class ComponentInstallerTest extends IntegrationTestCase
{
use ContainerTrait;
use FilesystemTrait;

private string $servicesFilePath = 'Fixtures/services.yaml';

public function setUp(): void
{
parent::setUp();

$this->backupVarDirectory();
}

public function tearDown(): void
{
parent::tearDown();

$this->restoreVarDirectory();
}

public function testInstall(): void
{
$installer = $this->createInstaller();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,32 +19,16 @@
use OxidEsales\EshopCommunity\Internal\Transition\Utility\BasicContextInterface;
use OxidEsales\EshopCommunity\Internal\Transition\Utility\ContextInterface;
use OxidEsales\EshopCommunity\Tests\ContainerTrait;
use OxidEsales\EshopCommunity\Tests\FilesystemTrait;
use PHPUnit\Framework\TestCase;
use OxidEsales\EshopCommunity\Tests\Integration\IntegrationTestCase;

final class ModulePackageInstallerTest extends TestCase
final class ModulePackageInstallerTest extends IntegrationTestCase
{
use ContainerTrait;
use FilesystemTrait;

private $modulePackagePath = __DIR__ . '/Fixtures/test-module-package-installation';
private string $modulePackagePath = __DIR__ . '/Fixtures/test-module-package-installation';
private string $packageName = 'test-module-package-installation';
private string $moduleId = 'testModule';

public function setUp(): void
{
parent::setUp();

$this->backupVarDirectory();
}

public function tearDown(): void
{
$this->restoreVarDirectory();

parent::tearDown();
}

public function testModuleNotInstalledByDefault(): void
{
$installer = $this->getPackageInstaller($this->packageName);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,28 +12,12 @@
use OxidEsales\EshopCommunity\Core\Di\ContainerFacade;
use OxidEsales\EshopCommunity\Internal\Framework\DIContainer\Dao\ParameterDaoInterface;
use OxidEsales\EshopCommunity\Tests\ContainerTrait;
use OxidEsales\EshopCommunity\Tests\FilesystemTrait;
use PHPUnit\Framework\TestCase;
use OxidEsales\EshopCommunity\Tests\Integration\IntegrationTestCase;
use Symfony\Component\DependencyInjection\Exception\ParameterNotFoundException;

final class ParameterDaoTest extends TestCase
final class ParameterDaoTest extends IntegrationTestCase
{
use ContainerTrait;
use FilesystemTrait;

public function setUp(): void
{
parent::setUp();

$this->backupVarDirectory();
}

public function tearDown(): void
{
parent::tearDown();

$this->restoreVarDirectory();
}

public function testAddWithMultipleParameters(): void
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,9 @@ public function setup(): void

public function tearDown(): void
{
parent::tearDown();

(new Filesystem())->remove($this->tmpFixture);

parent::tearDown();
}

public function testLadProjectConfigFileWillWorkWithEmptyFile(): void
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ final class FilesystemContainerCacheTest extends TestCase
public function tearDown(): void
{
$this->get(ContainerCacheInterface::class)->invalidate(2);

parent::tearDown();
}

public function testContainerCacheInvalidation(): void
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ final class ConnectionFactoryTest extends TestCase

public function tearDown(): void
{
parent::tearDown();
unlink($this->logFile);
parent::tearDown();
}

public function testSqlLoggerWritesExpectedValueToTheLog(): void
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,9 @@ protected function setUp(): void

public function tearDown(): void
{
parent::tearDown();

$this->filesystem->remove($this->filename);

parent::tearDown();
}

public function testGenerateIfDataExists(): void
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,12 @@
use OxidEsales\EshopCommunity\Core\Di\ContainerFacade;
use OxidEsales\EshopCommunity\Internal\Framework\Module\Install\DataObject\OxidEshopPackage;
use OxidEsales\EshopCommunity\Internal\Framework\Module\Install\Service\ModuleInstallerInterface;
use PHPUnit\Framework\TestCase;
use OxidEsales\EshopCommunity\Tests\Integration\IntegrationTestCase;
use Symfony\Component\Console\Application;
use Symfony\Component\Console\Tester\CommandTester;
use Symfony\Component\Filesystem\Path;

class ModuleCommandsTestCase extends TestCase
class ModuleCommandsTestCase extends IntegrationTestCase
{
protected string $modulesPath = __DIR__ . '/Fixtures/modules/';

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@
use OxidEsales\EshopCommunity\Internal\Framework\Module\Install\Service\ModuleConfigurationInstallerInterface;
use OxidEsales\EshopCommunity\Internal\Framework\Module\Configuration\Bridge\ModuleSettingBridgeInterface;
use OxidEsales\EshopCommunity\Tests\ContainerTrait;
use PHPUnit\Framework\TestCase;
use OxidEsales\EshopCommunity\Tests\Integration\IntegrationTestCase;

final class ModuleSettingBridgeTest extends TestCase
final class ModuleSettingBridgeTest extends IntegrationTestCase
{
use ContainerTrait;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@
use OxidEsales\EshopCommunity\Internal\Framework\Module\Configuration\DataObject\ModuleConfiguration;
use OxidEsales\EshopCommunity\Internal\Framework\Module\Configuration\DataObject\ShopConfiguration;
use OxidEsales\EshopCommunity\Tests\ContainerTrait;
use PHPUnit\Framework\TestCase;
use OxidEsales\EshopCommunity\Tests\Integration\IntegrationTestCase;

final class ShopConfigurationDaoBridgeTest extends TestCase
final class ShopConfigurationDaoBridgeTest extends IntegrationTestCase
{
use ContainerTrait;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@
use OxidEsales\EshopCommunity\Internal\Framework\Module\Configuration\Dao\Chain\ClassExtensionsChainDaoInterface;
use OxidEsales\EshopCommunity\Internal\Framework\Module\Configuration\DataObject\ClassExtensionsChain;
use OxidEsales\EshopCommunity\Tests\ContainerTrait;
use PHPUnit\Framework\TestCase;
use OxidEsales\EshopCommunity\Tests\Integration\IntegrationTestCase;

final class ClassExtensionsChainDaoTest extends TestCase
final class ClassExtensionsChainDaoTest extends IntegrationTestCase
{
use ContainerTrait;

Expand Down
Loading

0 comments on commit a4c1a92

Please sign in to comment.