From 3cbaf4550bc9e7b62607f61ef48c82ca0e019a70 Mon Sep 17 00:00:00 2001 From: Francesco Giovannini Date: Thu, 27 Mar 2025 12:13:49 +0100 Subject: [PATCH 1/2] fix: Fix generateIdentitiesCacheKey --- .github/workflows/pull-requests.yml | 2 +- src/Utils/IdentitiesGenerator.php | 2 +- .../Unit/Utils/IdentitiesGeneratorTest.php | 30 +++++++++++++++++++ 3 files changed, 32 insertions(+), 2 deletions(-) create mode 100644 tests/Engine/Unit/Utils/IdentitiesGeneratorTest.php diff --git a/.github/workflows/pull-requests.yml b/.github/workflows/pull-requests.yml index 8c8349a..c3d21b6 100644 --- a/.github/workflows/pull-requests.yml +++ b/.github/workflows/pull-requests.yml @@ -35,7 +35,7 @@ jobs: run: echo "dir=$(composer config cache-files-dir)" >> $GITHUB_OUTPUT - name: Cache dependencies - uses: actions/cache@v2 + uses: actions/cache@v3 with: path: ${{ steps.composer-cache.outputs.dir }} key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.json') }} diff --git a/src/Utils/IdentitiesGenerator.php b/src/Utils/IdentitiesGenerator.php index f81b54e..2d5f240 100644 --- a/src/Utils/IdentitiesGenerator.php +++ b/src/Utils/IdentitiesGenerator.php @@ -37,6 +37,6 @@ public static function generateIdentitiesCacheKey(string $identifier, ?object $t { $hashedTraits = $traits !== null ? '.'.sha1(serialize($traits)) : ''; $hashedIdentifier = sha1($identifier); - return 'Identity.'.$transient ? 'Transient' : ''.$hashedIdentifier.$hashedTraits; + return 'Identity.'.($transient ? 'Transient' : '').$hashedIdentifier.$hashedTraits; } } diff --git a/tests/Engine/Unit/Utils/IdentitiesGeneratorTest.php b/tests/Engine/Unit/Utils/IdentitiesGeneratorTest.php new file mode 100644 index 0000000..e3c2ae4 --- /dev/null +++ b/tests/Engine/Unit/Utils/IdentitiesGeneratorTest.php @@ -0,0 +1,30 @@ + 'value']; + $cacheKey = IdentitiesGenerator::generateIdentitiesCacheKey($identityId, $traits, null); + + $this->assertStringContainsString('Identity.', $cacheKey); + $this->assertStringContainsString(sha1($identityId), $cacheKey); + } + + public function testGenerateIdentitiesTransientCacheKey(): void + { + $identityId = 'test-identity-id'; + $traits = (object) ['key' => 'value']; + $cacheKey = IdentitiesGenerator::generateIdentitiesCacheKey($identityId, $traits, true); + + $this->assertStringContainsString('Identity.Transient', $cacheKey); + $this->assertStringContainsString(sha1($identityId), $cacheKey); + } +} \ No newline at end of file From 5572945f58a25448044f376db4b360dd6913a3b2 Mon Sep 17 00:00:00 2001 From: Francesco Giovannini Date: Fri, 28 Mar 2025 11:39:33 +0100 Subject: [PATCH 2/2] chore: EOL and other lint fix --- tests/Engine/Unit/Utils/IdentitiesGeneratorTest.php | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/tests/Engine/Unit/Utils/IdentitiesGeneratorTest.php b/tests/Engine/Unit/Utils/IdentitiesGeneratorTest.php index e3c2ae4..a650fa3 100644 --- a/tests/Engine/Unit/Utils/IdentitiesGeneratorTest.php +++ b/tests/Engine/Unit/Utils/IdentitiesGeneratorTest.php @@ -1,4 +1,6 @@ -assertStringContainsString('Identity.Transient', $cacheKey); $this->assertStringContainsString(sha1($identityId), $cacheKey); } -} \ No newline at end of file +}