diff --git a/src/Pdk/Audit/Repository/WcPdkAuditRepository.php b/src/Pdk/Audit/Repository/WcPdkAuditRepository.php index 8b7fa926d..04dc2e251 100644 --- a/src/Pdk/Audit/Repository/WcPdkAuditRepository.php +++ b/src/Pdk/Audit/Repository/WcPdkAuditRepository.php @@ -13,7 +13,10 @@ use MyParcelNL\Pdk\Storage\Contract\StorageInterface; use MyParcelNL\WooCommerce\Database\Contract\WpDatabaseServiceInterface; -final class WcPdkAuditRepository extends Repository implements PdkAuditRepositoryInterface +/** + * @final + */ +class WcPdkAuditRepository extends Repository implements PdkAuditRepositoryInterface { /** * @var \MyParcelNL\WooCommerce\Database\Contract\WpDatabaseServiceInterface @@ -36,19 +39,21 @@ public function __construct(StorageInterface $storage, WpDatabaseServiceInterfac */ public function all(): AuditCollection { - $audits = $this->wpDatabaseService->getAll(Pdk::get('tableNameAudits')); + return $this->retrieve('audits', function () { + $audits = $this->wpDatabaseService->getAll(Pdk::get('tableNameAudits')); - return new AuditCollection($audits->map(static function (array $audit): Audit { - return new Audit([ - 'id' => $audit['auditId'], - 'arguments' => json_decode($audit['arguments'], true), - 'action' => $audit['action'], - 'model' => $audit['model'], - 'modelIdentifier' => $audit['modelIdentifier'], - 'created' => new DateTime($audit['created']), - 'type' => $audit['type'], - ]); - })); + return new AuditCollection($audits->map(static function (array $audit): Audit { + return new Audit([ + 'id' => $audit['auditId'], + 'arguments' => json_decode($audit['arguments'], true), + 'action' => $audit['action'], + 'model' => $audit['model'], + 'modelIdentifier' => $audit['modelIdentifier'], + 'created' => new DateTime($audit['created']), + 'type' => $audit['type'], + ]); + })); + }); } /** diff --git a/tests/Mock/MockWcPdkAuditRepository.php b/tests/Mock/MockWcPdkAuditRepository.php new file mode 100644 index 000000000..6b47199f4 --- /dev/null +++ b/tests/Mock/MockWcPdkAuditRepository.php @@ -0,0 +1,16 @@ +storage->delete('audits'); + } +} diff --git a/tests/Mock/MockWcPdkBootstrapper.php b/tests/Mock/MockWcPdkBootstrapper.php index 678e89e21..1afa029f0 100644 --- a/tests/Mock/MockWcPdkBootstrapper.php +++ b/tests/Mock/MockWcPdkBootstrapper.php @@ -6,6 +6,7 @@ use MyParcelNL\Pdk\Base\Concern\PdkInterface; use MyParcelNL\WooCommerce\Database\Contract\WpDatabaseServiceInterface; +use MyParcelNL\WooCommerce\Pdk\Audit\Repository\WcPdkAuditRepository; use MyParcelNL\WooCommerce\Pdk\WcPdkBootstrapper; use function DI\get; @@ -98,6 +99,7 @@ protected function getAdditionalConfig( self::$config, [ WpDatabaseServiceInterface::class => get(MockWpDatabaseService::class), + WcPdkAuditRepository::class => get(MockWcPdkAuditRepository::class), ] ); } diff --git a/tests/Unit/Pdk/Plugin/Repository/WcPdkAuditRepositoryTest.php b/tests/Unit/Pdk/Plugin/Repository/WcPdkAuditRepositoryTest.php index e7904cfdf..72f98462d 100644 --- a/tests/Unit/Pdk/Plugin/Repository/WcPdkAuditRepositoryTest.php +++ b/tests/Unit/Pdk/Plugin/Repository/WcPdkAuditRepositoryTest.php @@ -37,9 +37,12 @@ 'orderIds' => [$wcOrder->get_id()], ]); - /** @var \MyParcelNL\Pdk\Audit\Contract\PdkAuditRepositoryInterface $auditRepository */ + /** @var \MyParcelNL\WooCommerce\Tests\Mock\MockWcPdkAuditRepository $auditRepository */ $auditRepository = Pdk::get(PdkAuditRepositoryInterface::class); + // Clear the cache of retrieved audits + $auditRepository->reset(); + $audit = $auditRepository->all() ->first();