-
Notifications
You must be signed in to change notification settings - Fork 206
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add integration test with a context stub
- Loading branch information
1 parent
6d4a7fa
commit e406483
Showing
2 changed files
with
101 additions
and
0 deletions.
There are no files selected for viewing
96 changes: 96 additions & 0 deletions
96
tests/Integration/Internal/Framework/Templating/Cache/MultiShopTemplateCacheServiceTest.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,96 @@ | ||
<?php | ||
|
||
/** | ||
* Copyright © OXID eSales AG. All rights reserved. | ||
* See LICENSE file for license details. | ||
*/ | ||
|
||
declare(strict_types=1); | ||
|
||
namespace OxidEsales\EshopCommunity\Tests\Integration\Internal\Framework\Templating\Cache; | ||
|
||
use OxidEsales\EshopCommunity\Internal\Framework\Templating\Cache\ShopTemplateCacheServiceInterface; | ||
use OxidEsales\EshopCommunity\Internal\Transition\Utility\ContextInterface; | ||
use OxidEsales\EshopCommunity\Tests\ContainerTrait; | ||
use OxidEsales\EshopCommunity\Tests\TestContainerFactory; | ||
use OxidEsales\EshopCommunity\Tests\Unit\Internal\ContextStub; | ||
use PHPUnit\Framework\TestCase; | ||
use Symfony\Component\Filesystem\Path; | ||
|
||
final class MultiShopTemplateCacheServiceTest extends TestCase | ||
{ | ||
use ContainerTrait; | ||
|
||
private string $testFixturesDirectory = __DIR__ . '/cache_fixtures'; | ||
private int $shopId1 = 123; | ||
private int $shopId2 = 456; | ||
private array $allShopIds = []; | ||
private array $cacheFixturesForShopId = []; | ||
|
||
public function setUp(): void | ||
{ | ||
parent::setUp(); | ||
|
||
$this->allShopIds = [ | ||
$this->shopId1, | ||
$this->shopId2, | ||
]; | ||
$this->stubContext(); | ||
$this->generateCacheFixtures(); | ||
} | ||
|
||
public function tearDown(): void | ||
{ | ||
$this->cleanupCache(); | ||
|
||
parent::tearDown(); | ||
} | ||
|
||
public function testInvalidateCacheWillKeepOtherShopsCacheFile(): void | ||
{ | ||
$this->get(ShopTemplateCacheServiceInterface::class)->invalidateCache($this->shopId1); | ||
|
||
$this->assertFileDoesNotExist($this->cacheFixturesForShopId[$this->shopId1]); | ||
$this->assertFileExists($this->cacheFixturesForShopId[$this->shopId2]); | ||
} | ||
|
||
public function testInvalidateAllShopsCacheWillRemoveAllCacheFiles(): void | ||
{ | ||
$this->get(ShopTemplateCacheServiceInterface::class)->invalidateAllShopsCache(); | ||
|
||
$this->assertFileDoesNotExist($this->cacheFixturesForShopId[$this->shopId1]); | ||
$this->assertFileDoesNotExist($this->cacheFixturesForShopId[$this->shopId2]); | ||
} | ||
|
||
private function stubContext(): void | ||
{ | ||
$context = new ContextStub(); | ||
$context->setCacheDirectory($this->testFixturesDirectory); | ||
$context->setAllShopIds($this->allShopIds); | ||
|
||
$this->container = (new TestContainerFactory())->create(); | ||
$this->container->set(ContextInterface::class, $context); | ||
$this->container->autowire(ContextInterface::class, ContextInterface::class); | ||
$this->container->compile(); | ||
} | ||
|
||
private function generateCacheFixtures(): void | ||
{ | ||
$filesystem = $this->get('oxid_esales.symfony.file_system'); | ||
|
||
foreach ($this->allShopIds as $shopId) { | ||
$templateCacheDirectory = $this->get(ShopTemplateCacheServiceInterface::class)->getCacheDirectory($shopId); | ||
$filesystem->mkdir($templateCacheDirectory); | ||
$this->cacheFixturesForShopId[$shopId] = Path::join($templateCacheDirectory, 'some-cache-file'); | ||
$filesystem->touch($this->cacheFixturesForShopId[$shopId]); | ||
} | ||
|
||
$this->assertFileExists($this->cacheFixturesForShopId[$this->shopId1]); | ||
$this->assertFileExists($this->cacheFixturesForShopId[$this->shopId2]); | ||
} | ||
|
||
private function cleanupCache(): void | ||
{ | ||
$this->get('oxid_esales.symfony.file_system')->remove($this->testFixturesDirectory); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters