diff --git a/tests/Common/ItemsStorageTestTrait.php b/tests/Common/ItemsStorageTestTrait.php index 350de4d0..7c79d460 100644 --- a/tests/Common/ItemsStorageTestTrait.php +++ b/tests/Common/ItemsStorageTestTrait.php @@ -397,8 +397,10 @@ public function testGetRole(): void public function testAdd(): void { + $time = time(); + $newItem = (new Permission('Delete post'))->withCreatedAt($time)->withUpdatedAt($time); + $storage = $this->getItemsStorage(); - $newItem = new Permission('Delete post'); $storage->add($newItem); $this->assertInstanceOf(Permission::class, $storage->get('Delete post')); diff --git a/tests/Common/ManagerLogicTestTrait.php b/tests/Common/ManagerLogicTestTrait.php index d321b6b6..a098d0c2 100644 --- a/tests/Common/ManagerLogicTestTrait.php +++ b/tests/Common/ManagerLogicTestTrait.php @@ -301,9 +301,7 @@ public function testCanAddChildPermissionToRole(): void public function testCanAddChildToNonExistingItem(): void { $itemsStorage = $this->createItemsStorage(); - $itemsStorage->add(new Role('author')); - - $manager = $this->createManager($itemsStorage); + $manager = $this->createManager($itemsStorage)->addRole(new Role('author')); $this->assertFalse($manager->canAddChild('admin', 'author')); } @@ -311,9 +309,7 @@ public function testCanAddChildToNonExistingItem(): void public function testCanAddNonExistingChild(): void { $itemsStorage = $this->createItemsStorage(); - $itemsStorage->add(new Role('author')); - - $manager = $this->createManager($itemsStorage); + $manager = $this->createManager($itemsStorage)->addRole(new Role('author')); $this->assertFalse($manager->canAddChild('author', 'reader')); } @@ -449,21 +445,15 @@ public function testHasChild(): void public function testAssign(): void { $itemsStorage = $this->createItemsStorage(); - $itemsStorage->add(new Role('author')); - $itemsStorage->add(new Role('reader')); - $itemsStorage->add(new Role('writer')); - $itemsStorage->add(new Role('default-role')); - $assignmentsStorage = $this->createAssignmentsStorage(); - - $manager = $this->createManager($itemsStorage, $assignmentsStorage); - $manager->setDefaultRoleNames(['default-role']); - - $manager->assign('reader', 'readingAuthor'); - $readerAssignment = $assignmentsStorage->get('reader', 'readingAuthor'); - - $manager->assign('author', 'readingAuthor'); - $authorAssignment = $assignmentsStorage->get('author', 'readingAuthor'); + $manager = $this->createManager($itemsStorage, $assignmentsStorage) + ->addRole(new Role('author')) + ->addRole(new Role('reader')) + ->addRole(new Role('writer')) + ->addRole(new Role('default-role')) + ->setDefaultRoleNames(['default-role']) + ->assign('reader', 'readingAuthor') + ->assign('author', 'readingAuthor'); $this->assertEqualsCanonicalizing( [ @@ -475,11 +465,14 @@ public function testAssign(): void ); $createdAt = 1_683_707_079; + $readerAssignment = $assignmentsStorage->get('reader', 'readingAuthor'); $this->assertSame('readingAuthor', $readerAssignment->getUserId()); $this->assertSame('reader', $readerAssignment->getItemName()); $this->assertSame($createdAt, $readerAssignment->getCreatedAt()); + $authorAssignment = $assignmentsStorage->get('author', 'readingAuthor'); + $this->assertSame('readingAuthor', $authorAssignment->getUserId()); $this->assertSame('author', $authorAssignment->getItemName()); $this->assertSame($createdAt, $authorAssignment->getCreatedAt());