Skip to content

Commit

Permalink
OXDEV-1284 Add invalidateModuleCache to ShopAdapterInterface
Browse files Browse the repository at this point in the history
  • Loading branch information
robertblank authored and godefroy-le-hardi committed Jan 7, 2019
1 parent 39f1050 commit d1bbf4d
Show file tree
Hide file tree
Showing 4 changed files with 68 additions and 0 deletions.
16 changes: 16 additions & 0 deletions source/Internal/Adapter/Exception/ModuleNotLoadableException.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<?php
declare(strict_types=1);

/**
* Copyright © OXID eSales AG. All rights reserved.
* See LICENSE file for license details.
*/

namespace OxidEsales\EshopCommunity\Internal\Common\Exception;

/**
* @internal
*/
class ModuleNotLoadableException extends \Exception
{
}
21 changes: 21 additions & 0 deletions source/Internal/Adapter/ShopAdapter.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,10 @@

use OxidEsales\Eshop\Core\MailValidator;
use OxidEsales\Eshop\Core\Module\ModuleList;
use OxidEsales\Eshop\Core\Module\Module;
use OxidEsales\Eshop\Core\Module\ModuleCache;
use OxidEsales\Eshop\Core\Registry;
use OxidEsales\EshopCommunity\Internal\Common\Exception\ModuleNotLoadableException;

/**
* @internal
Expand All @@ -17,6 +20,7 @@ class ShopAdapter implements ShopAdapterInterface
{
/**
* @param string $email
*
* @return bool
*/
public function isValidEmail($email)
Expand All @@ -28,6 +32,7 @@ public function isValidEmail($email)

/**
* @param string $string
*
* @return string
*/
public function translateString($string)
Expand All @@ -37,6 +42,22 @@ public function translateString($string)
return $lang->translateString($string);
}

/**
* @param string $moduleId
*
* @throws ModuleNotLoadableException
*/
public function invalidateModuleCache(string $moduleId)
{
$module = oxNew(Module::class);
if (!$module->load($moduleId)) {
throw new ModuleNotLoadableException('The following module could not be loaded. ModuleId: ' . $moduleId);
}

$moduleCache = oxNew(ModuleCache::class, $module);
$moduleCache->resetCache();
}

/**
* @return array
*/
Expand Down
5 changes: 5 additions & 0 deletions source/Internal/Adapter/ShopAdapterInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,11 @@ public function isValidEmail($email);
*/
public function translateString($string);

/**
* @param string $moduleId
*/
public function invalidateModuleCache(string $moduleId);

/**
* @return array
*/
Expand Down
26 changes: 26 additions & 0 deletions tests/Unit/Internal/Adapter/ShopAdapterTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<?php
declare(strict_types=1);

/**
* Copyright © OXID eSales AG. All rights reserved.
* See LICENSE file for license details.
*/


namespace OxidEsales\EshopCommunity\Tests\Unit\Internal\Adapter;


use OxidEsales\EshopCommunity\Internal\Adapter\ShopAdapter;
use PHPUnit\Framework\TestCase;

class ShopAdapterTest extends TestCase
{
/**
* @expectedException \OxidEsales\EshopCommunity\Internal\Common\Exception\ModuleNotLoadableException
*/
public function testInvalidateCacheThrowsExceptionOnNonExistentModuleId()
{
$shopAdapter = new ShopAdapter();
$shopAdapter->invalidateModuleCache(uniqid('test', false));
}
}

0 comments on commit d1bbf4d

Please sign in to comment.