From 7078d71e778da3ec0faef690dbbe3c3c66648eb0 Mon Sep 17 00:00:00 2001 From: Oleh Khalin Date: Thu, 30 Oct 2025 11:26:03 +0100 Subject: [PATCH 1/4] fix: testing suite --- src/Testing/FakeOpenFga.php | 10 ++++++++-- src/Testing/FakesOpenFga.php | 22 +++++++++++++++++----- 2 files changed, 25 insertions(+), 7 deletions(-) diff --git a/src/Testing/FakeOpenFga.php b/src/Testing/FakeOpenFga.php index 7d9bc02..acdff1d 100644 --- a/src/Testing/FakeOpenFga.php +++ b/src/Testing/FakeOpenFga.php @@ -398,10 +398,13 @@ public function getWrites(): array * @param string $user * @param string $relation * @param string $object + * @return bool */ - public function grant(string $user, string $relation, string $object): void + public function grant(string $user, string $relation, string $object): bool { $this->tuples[] = ['user' => $user, 'relation' => $relation, 'object' => $object]; + + return true; } /** @@ -548,10 +551,13 @@ public function resetChecks(): self * @param string $user * @param string $relation * @param string $object + * @return bool */ - public function revoke(string $user, string $relation, string $object): void + public function revoke(string $user, string $relation, string $object): bool { $this->tuples = array_filter($this->tuples, static fn ($tuple): bool => ! ($tuple['user'] === $user && $tuple['relation'] === $relation && $tuple['object'] === $object)); + + return true; } /** diff --git a/src/Testing/FakesOpenFga.php b/src/Testing/FakesOpenFga.php index 0a3edc1..6383464 100644 --- a/src/Testing/FakesOpenFga.php +++ b/src/Testing/FakesOpenFga.php @@ -4,7 +4,9 @@ namespace OpenFGA\Laravel\Testing; +use OpenFGA\Laravel\Contracts\ManagerInterface; use OpenFGA\Laravel\OpenFgaManager; +use OpenFGA\Models\Collections\TupleKeysInterface; /** * Trait for faking OpenFGA in tests. @@ -119,7 +121,7 @@ protected function fakeOpenFga(): FakeOpenFga $this->fakeOpenFga = new FakeOpenFga; // Create a wrapper manager that delegates to our fake - $fakeManager = new readonly class($this->fakeOpenFga) { + $fakeManager = new readonly class($this->fakeOpenFga) implements ManagerInterface { public function __construct(private FakeOpenFga $fake) { } @@ -129,14 +131,14 @@ public function check(string $user, string $relation, string $object, array $con return $this->fake->check($user, $relation, $object); } - public function grant(string $user, string $relation, string $object, ?string $connection = null): void + public function grant(string|array $user, string $relation, string $object, ?string $connection = null): bool { - $this->fake->grant($user, $relation, $object); + return $this->fake->grant($user, $relation, $object); } - public function revoke(string $user, string $relation, string $object, ?string $connection = null): void + public function revoke(string|array $user, string $relation, string $object, ?string $connection = null): bool { - $this->fake->revoke($user, $relation, $object); + return $this->fake->revoke($user, $relation, $object); } public function listObjects(string $user, string $relation, string $type, array $contextualTuples = [], array $context = [], ?string $connection = null): array @@ -209,6 +211,16 @@ public function check(): bool } }; } + + public function listRelations(string $user, string $object, array $relations = [], array $contextualTuples = [], array $context = [], ?string $connection = null,): array + { + // TODO: Implement listRelations() method. + } + + public function write(?TupleKeysInterface $writes = null, ?TupleKeysInterface $deletes = null, ?string $connection = null,): bool + { + // TODO: Implement write() method. + } }; // Replace the manager in the container From af037faf664c52fddee549c161523e03040c5394 Mon Sep 17 00:00:00 2001 From: Oleh Khalin Date: Thu, 30 Oct 2025 11:26:14 +0100 Subject: [PATCH 2/4] fix: delete unexistent laravel event --- src/Traits/HasAuthorization.php | 7 ------- 1 file changed, 7 deletions(-) diff --git a/src/Traits/HasAuthorization.php b/src/Traits/HasAuthorization.php index 664d0cf..1a15ec0 100644 --- a/src/Traits/HasAuthorization.php +++ b/src/Traits/HasAuthorization.php @@ -210,13 +210,6 @@ public function initializeHasAuthorization(): void $model->revokeAllPermissions(); } }); - - // Add model event to replicate permissions on duplication - static::replicated(function (Model $original, Model $replica): void { - if ($this->shouldReplicatePermissions()) { - $original->replicatePermissionsTo($replica); - } - }); } /** From aa707d5c7b3d001ff3983ab6176bade156f63b59 Mon Sep 17 00:00:00 2001 From: Oleh Khalin Date: Thu, 30 Oct 2025 11:33:02 +0100 Subject: [PATCH 3/4] lint: affected files --- src/Testing/FakeOpenFga.php | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/Testing/FakeOpenFga.php b/src/Testing/FakeOpenFga.php index acdff1d..731161b 100644 --- a/src/Testing/FakeOpenFga.php +++ b/src/Testing/FakeOpenFga.php @@ -551,11 +551,10 @@ public function resetChecks(): self * @param string $user * @param string $relation * @param string $object - * @return bool */ public function revoke(string $user, string $relation, string $object): bool { - $this->tuples = array_filter($this->tuples, static fn ($tuple): bool => ! ($tuple['user'] === $user && $tuple['relation'] === $relation && $tuple['object'] === $object)); + $this->tuples = array_filter($this->tuples, static fn (array $tuple): bool => ! ($tuple['user'] === $user && $tuple['relation'] === $relation && $tuple['object'] === $object)); return true; } @@ -627,7 +626,7 @@ public function writeBatch(array $writes = [], array $deletes = []): void // Apply deletes foreach ($deletes as $delete) { - $this->tuples = array_filter($this->tuples, static fn ($tuple): bool => ! ($tuple['user'] === $delete['user'] + $this->tuples = array_filter($this->tuples, static fn (array $tuple): bool => ! ($tuple['user'] === $delete['user'] && $tuple['relation'] === $delete['relation'] && $tuple['object'] === $delete['object'])); } From 5b2e2d6a07ccb9617687eed98eb1877e224ef0ae Mon Sep 17 00:00:00 2001 From: Oleh Khalin Date: Thu, 30 Oct 2025 11:37:13 +0100 Subject: [PATCH 4/4] chore: throw exception for not implemented methods --- src/Testing/FakesOpenFga.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Testing/FakesOpenFga.php b/src/Testing/FakesOpenFga.php index 6383464..1151028 100644 --- a/src/Testing/FakesOpenFga.php +++ b/src/Testing/FakesOpenFga.php @@ -214,12 +214,12 @@ public function check(): bool public function listRelations(string $user, string $object, array $relations = [], array $contextualTuples = [], array $context = [], ?string $connection = null,): array { - // TODO: Implement listRelations() method. + throw new \RuntimeException('listRelations() is not yet implemented in the fake.'); } public function write(?TupleKeysInterface $writes = null, ?TupleKeysInterface $deletes = null, ?string $connection = null,): bool { - // TODO: Implement write() method. + throw new \RuntimeException('write() is not yet implemented in the fake.'); } };