Skip to content

Commit

Permalink
IBX-4000: Changed the method name creation for logCall in callable fu…
Browse files Browse the repository at this point in the history
…nction (#410)

For more details see https://issues.ibexa.co/browse/IBX-4000 and #410

Key changes:

* Fixed caller method name for logCall in callable function in `Persistence\Cache\ObjectStateHandler`

* [Tests] Changed tests to better cover logCall function
  • Loading branch information
mateuszdebinski committed Aug 1, 2024
1 parent e7d917c commit 8a676dc
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 9 deletions.
14 changes: 7 additions & 7 deletions src/lib/Persistence/Cache/ObjectStateHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ public function loadGroup($groupId)
(int) $groupId,
$this->cacheIdentifierGenerator->generateKey(self::STATE_GROUP_IDENTIFIER, [], true) . '-',
function (int $groupId): Group {
$this->logger->logCall(__METHOD__, ['groupId' => (int) $groupId]);
$this->logger->logCall(__CLASS__ . '::loadGroup', ['groupId' => (int) $groupId]);

return $this->persistenceHandler->objectStateHandler()->loadGroup($groupId);
},
Expand Down Expand Up @@ -79,7 +79,7 @@ public function loadGroupByIdentifier($identifier)
$identifier,
$this->cacheIdentifierGenerator->generateKey(self::STATE_GROUP_IDENTIFIER, [], true) . '-',
function (string $identifier): Group {
$this->logger->logCall(__METHOD__, ['groupId' => $identifier]);
$this->logger->logCall(__CLASS__ . '::loadGroupByIdentifier', ['groupId' => $identifier]);

return $this->persistenceHandler->objectStateHandler()->loadGroupByIdentifier($identifier);
},
Expand All @@ -106,7 +106,7 @@ public function loadAllGroups($offset = 0, $limit = -1)
$stateGroups = $this->getListCacheValue(
$this->cacheIdentifierGenerator->generateKey(self::STATE_GROUP_ALL_IDENTIFIER, [], true),
function () use ($offset, $limit): array {
$this->logger->logCall(__METHOD__, ['offset' => (int) $offset, 'limit' => (int) $limit]);
$this->logger->logCall(__CLASS__ . '::loadAllGroups', ['offset' => (int) $offset, 'limit' => (int) $limit]);

return $this->persistenceHandler->objectStateHandler()->loadAllGroups(0, -1);
},
Expand Down Expand Up @@ -135,7 +135,7 @@ public function loadObjectStates($groupId)
$groupId,
$this->cacheIdentifierGenerator->generateKey(self::STATE_LIST_BY_GROUP_IDENTIFIER, [], true) . '-',
function (int $groupId): array {
$this->logger->logCall(__METHOD__, ['groupId' => (int) $groupId]);
$this->logger->logCall(__CLASS__ . '::loadObjectStates', ['groupId' => (int) $groupId]);

return $this->persistenceHandler->objectStateHandler()->loadObjectStates($groupId);
},
Expand Down Expand Up @@ -210,7 +210,7 @@ public function load($stateId)
(int) $stateId,
$this->cacheIdentifierGenerator->generateKey(self::STATE_IDENTIFIER, [], true) . '-',
function (int $stateId): ObjectState {
$this->logger->logCall(__METHOD__, ['stateId' => $stateId]);
$this->logger->logCall(__CLASS__ . '::load', ['stateId' => $stateId]);

return $this->persistenceHandler->objectStateHandler()->load($stateId);
},
Expand Down Expand Up @@ -239,7 +239,7 @@ public function loadByIdentifier($identifier, $groupId)
$identifier,
$this->cacheIdentifierGenerator->generateKey(self::STATE_ID_IDENTIFIER, [], true) . '-',
function (string $identifier) use ($groupId): ObjectState {
$this->logger->logCall(__METHOD__, ['identifier' => $identifier, 'groupId' => (int) $groupId]);
$this->logger->logCall(__CLASS__ . '::loadByIdentifier', ['identifier' => $identifier, 'groupId' => (int) $groupId]);

return $this->persistenceHandler->objectStateHandler()->loadByIdentifier($identifier, (int) $groupId);
},
Expand Down Expand Up @@ -335,7 +335,7 @@ public function getContentState($contentId, $stateGroupId)
(int) $stateGroupId,
$this->cacheIdentifierGenerator->generateKey(self::STATE_BY_GROUP_IDENTIFIER, [], true) . '-',
function (int $stateGroupId) use ($contentId): ObjectState {
$this->logger->logCall(__METHOD__, ['contentId' => (int) $contentId, 'stateGroupId' => $stateGroupId]);
$this->logger->logCall(__CLASS__ . '::getContentState', ['contentId' => (int) $contentId, 'stateGroupId' => $stateGroupId]);

return $this->persistenceHandler->objectStateHandler()->getContentState((int) $contentId, $stateGroupId);
},
Expand Down
7 changes: 5 additions & 2 deletions tests/lib/Persistence/Cache/AbstractCacheHandlerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,11 @@ final public function testLoadMethodsCacheMiss(
$cacheItem = $this->getCacheItem($key, null);
$handlerMethodName = $this->getHandlerMethodName();

$this->loggerMock->expects($this->once())->method('logCall');
$handler = $this->persistenceCacheHandler->$handlerMethodName();
$this->loggerMock
->expects(self::once())
->method('logCall')
->with(get_class($handler) . '::' . $method, self::isType('array'));

if ($tagGeneratingArguments) {
$this->cacheIdentifierGeneratorMock
Expand Down Expand Up @@ -281,7 +285,6 @@ final public function testLoadMethodsCacheMiss(
->method('save')
->with($cacheItem);

$handler = $this->persistenceCacheHandler->$handlerMethodName();
$return = call_user_func_array([$handler, $method], $arguments);

$this->assertEquals($data, $return);
Expand Down

0 comments on commit 8a676dc

Please sign in to comment.