From d4e394f3736fe506c359a7cc50547871258b7e2d Mon Sep 17 00:00:00 2001 From: Alexey Rogachev Date: Fri, 15 Sep 2023 12:45:03 +0600 Subject: [PATCH] Naming (review) --- tests/Common/AssignmentsStorageTestTrait.php | 42 ++++++------ tests/Common/ItemsStorageTestTrait.php | 70 ++++++++++---------- 2 files changed, 56 insertions(+), 56 deletions(-) diff --git a/tests/Common/AssignmentsStorageTestTrait.php b/tests/Common/AssignmentsStorageTestTrait.php index 7958c5b0..f655e43b 100644 --- a/tests/Common/AssignmentsStorageTestTrait.php +++ b/tests/Common/AssignmentsStorageTestTrait.php @@ -21,25 +21,25 @@ trait AssignmentsStorageTestTrait protected function setUp(): void { $this->populateItemsStorage(); - $this->populateStorage(); + $this->populateAssignmentsStorage(); } protected function tearDown(): void { $this->getItemsStorage()->clear(); - $this->getStorage()->clear(); + $this->getAssignmentsStorage()->clear(); } public function testHasItem(): void { - $storage = $this->getStorage(); + $storage = $this->getAssignmentsStorage(); $this->assertTrue($storage->hasItem('Accountant')); } public function testRenameItem(): void { - $storage = $this->getStorage(); + $storage = $this->getAssignmentsStorage(); $storage->renameItem('Accountant', 'Senior accountant'); $this->assertFalse($storage->hasItem('Accountant')); @@ -48,7 +48,7 @@ public function testRenameItem(): void public function testGetAll(): void { - $storage = $this->getStorage(); + $storage = $this->getAssignmentsStorage(); $all = $storage->getAll(); $this->assertCount(3, $all); @@ -62,7 +62,7 @@ public function testGetAll(): void public function testRemoveByItemName(): void { - $storage = $this->getStorage(); + $storage = $this->getAssignmentsStorage(); $storage->removeByItemName('Manager'); $this->assertFalse($storage->hasItem('Manager')); @@ -72,7 +72,7 @@ public function testRemoveByItemName(): void public function testGetByUserId(): void { - $storage = $this->getStorage(); + $storage = $this->getAssignmentsStorage(); $assignments = $storage->getByUserId('john'); $this->assertCount(3, $assignments); @@ -99,7 +99,7 @@ public function dataGetByItemNames(): array */ public function testGetByItemNames(array $itemNames, array $expectedAssignments): void { - $assignments = $this->getStorage()->getByItemNames($itemNames); + $assignments = $this->getAssignmentsStorage()->getByItemNames($itemNames); $this->assertCount(count($expectedAssignments), $assignments); $assignmentFound = false; @@ -121,7 +121,7 @@ public function testGetByItemNames(array $itemNames, array $expectedAssignments) public function testRemoveByUserId(): void { - $storage = $this->getStorage(); + $storage = $this->getAssignmentsStorage(); $storage->removeByUserId('jack'); $this->assertEmpty($storage->getByUserId('jack')); @@ -130,7 +130,7 @@ public function testRemoveByUserId(): void public function testRemove(): void { - $storage = $this->getStorage(); + $storage = $this->getAssignmentsStorage(); $storage->remove('Accountant', 'john'); $this->assertEmpty($storage->get('Accountant', 'john')); @@ -139,7 +139,7 @@ public function testRemove(): void public function testClear(): void { - $storage = $this->getStorage(); + $storage = $this->getAssignmentsStorage(); $storage->clear(); $this->assertEmpty($storage->getAll()); @@ -147,7 +147,7 @@ public function testClear(): void public function testGet(): void { - $storage = $this->getStorage(); + $storage = $this->getAssignmentsStorage(); $assignment = $storage->get('Manager', 'jack'); $this->assertSame('Manager', $assignment->getItemName()); @@ -157,7 +157,7 @@ public function testGet(): void public function testGetNonExisting(): void { - $this->assertNull($this->getStorage()->get('Researcher', 'jeff')); + $this->assertNull($this->getAssignmentsStorage()->get('Researcher', 'jeff')); } public function dataExists(): array @@ -176,7 +176,7 @@ public function dataExists(): array */ public function testExists(string $itemName, string $userId, bool $expectedExists): void { - $this->assertSame($expectedExists, $this->getStorage()->exists($itemName, $userId)); + $this->assertSame($expectedExists, $this->getAssignmentsStorage()->exists($itemName, $userId)); } public function dataUserHasItem(): array @@ -196,12 +196,12 @@ public function dataUserHasItem(): array */ public function testUserHasItem(string $userId, array $itemNames, bool $expectedUserHasItem): void { - $this->assertSame($expectedUserHasItem, $this->getStorage()->userHasItem($userId, $itemNames)); + $this->assertSame($expectedUserHasItem, $this->getAssignmentsStorage()->userHasItem($userId, $itemNames)); } public function testAdd(): void { - $storage = $this->getStorage(); + $storage = $this->getAssignmentsStorage(); $storage->add('Operator', 'john'); $this->assertInstanceOf(Assignment::class, $storage->get('Operator', 'john')); @@ -261,10 +261,10 @@ protected function populateItemsStorage(): void } } - protected function populateStorage(): void + protected function populateAssignmentsStorage(): void { foreach ($this->getFixtures()['assignments'] as $assignmentData) { - $this->getStorage()->add($assignmentData['itemName'], $assignmentData['userId']); + $this->getAssignmentsStorage()->add($assignmentData['itemName'], $assignmentData['userId']); } } @@ -277,10 +277,10 @@ protected function getItemsStorage(): ItemsStorageInterface return $this->itemsStorage; } - protected function getStorage(): AssignmentsStorageInterface + protected function getAssignmentsStorage(): AssignmentsStorageInterface { if ($this->storage === null) { - $this->storage = $this->createStorage(); + $this->storage = $this->createAssignmentsStorage(); } return $this->storage; @@ -291,7 +291,7 @@ protected function createItemsStorage(): ItemsStorageInterface return new FakeItemsStorage(); } - protected function createStorage(): AssignmentsStorageInterface + protected function createAssignmentsStorage(): AssignmentsStorageInterface { return new FakeAssignmentsStorage(); } diff --git a/tests/Common/ItemsStorageTestTrait.php b/tests/Common/ItemsStorageTestTrait.php index 769d237b..f50c56f1 100644 --- a/tests/Common/ItemsStorageTestTrait.php +++ b/tests/Common/ItemsStorageTestTrait.php @@ -22,12 +22,12 @@ trait ItemsStorageTestTrait protected function setUp(): void { - $this->populateStorage(); + $this->populateItemsStorage(); } protected function tearDown(): void { - $this->getStorage()->clear(); + $this->getItemsStorage()->clear(); } public function dataUpdate(): array @@ -44,7 +44,7 @@ public function dataUpdate(): array */ public function testUpdate(string $itemName, string $parentNameForChildrenCheck, bool $expectedHasChildren): void { - $storage = $this->getStorage(); + $storage = $this->getItemsStorage(); $item = $storage->get($itemName); $this->assertNull($item->getRuleName()); @@ -67,7 +67,7 @@ public function testUpdate(string $itemName, string $parentNameForChildrenCheck, public function testGet(): void { - $storage = $this->getStorage(); + $storage = $this->getItemsStorage(); $item = $storage->get('Parent 3'); $this->assertInstanceOf(Permission::class, $item); @@ -77,7 +77,7 @@ public function testGet(): void public function testGetWithNonExistingName(): void { - $storage = $this->getStorage(); + $storage = $this->getItemsStorage(); $this->assertNull($storage->get('Non-existing name')); } @@ -99,7 +99,7 @@ public function existsProvider(): array */ public function testExists(string $name, bool $expectedExists): void { - $storage = $this->getStorage(); + $storage = $this->getItemsStorage(); $this->assertSame($expectedExists, $storage->exists($name)); } @@ -117,12 +117,12 @@ public function dataRoleExists(): array */ public function testRoleExists(string $name, bool $expectedRoleExists): void { - $this->assertSame($expectedRoleExists, $this->getStorage()->roleExists($name)); + $this->assertSame($expectedRoleExists, $this->getItemsStorage()->roleExists($name)); } public function testGetPermission(): void { - $storage = $this->getStorage(); + $storage = $this->getItemsStorage(); $permission = $storage->getPermission('Child 1'); $this->assertInstanceOf(Permission::class, $permission); @@ -131,7 +131,7 @@ public function testGetPermission(): void public function testAddChild(): void { - $storage = $this->getStorage(); + $storage = $this->getItemsStorage(); $storage->addChild('Parent 2', 'Child 1'); $children = $storage->getAllChildren('Parent 2'); @@ -144,7 +144,7 @@ public function testAddChild(): void public function testClear(): void { - $storage = $this->getStorage(); + $storage = $this->getItemsStorage(); $storage->clear(); $this->assertEmpty($storage->getAll()); @@ -171,7 +171,7 @@ public function dataGetDirectChildren(): array */ public function testGetDirectChildren(string $parentName, array $expectedChildren): void { - $children = $this->getStorage()->getDirectChildren($parentName); + $children = $this->getItemsStorage()->getDirectChildren($parentName); $this->assertChildren($children, $expectedChildren); } @@ -199,7 +199,7 @@ public function dataGetAllChildren(): array */ public function testGetAllChildren(string $parentName, array $expectedChildren): void { - $children = $this->getStorage()->getAllChildren($parentName); + $children = $this->getItemsStorage()->getAllChildren($parentName); $this->assertChildren($children, $expectedChildren); } @@ -224,7 +224,7 @@ public function dataGetAllChildPermissions(): array */ public function testGetAllChildPermissions(string $parentName, array $expectedChildren): void { - $children = $this->getStorage()->getAllChildPermissions($parentName); + $children = $this->getItemsStorage()->getAllChildPermissions($parentName); $this->assertChildren($children, $expectedChildren); } @@ -249,13 +249,13 @@ public function dataGetAllChildRoles(): array */ public function testGetAllChildRoles(string $parentName, array $expectedChildren): void { - $children = $this->getStorage()->getAllChildRoles($parentName); + $children = $this->getItemsStorage()->getAllChildRoles($parentName); $this->assertChildren($children, $expectedChildren); } public function testGetRoles(): void { - $storage = $this->getStorage(); + $storage = $this->getItemsStorage(); $roles = $storage->getRoles(); $this->assertCount($this->initialRolesCount, $roles); @@ -279,7 +279,7 @@ public function dataGetRolesByNames(): array */ public function testGetRolesByNames(array $names, array $expectedRoleNames): void { - $roles = $this->getStorage()->getRolesByNames($names); + $roles = $this->getItemsStorage()->getRolesByNames($names); $this->assertCount(count($expectedRoleNames), $roles); foreach ($roles as $roleName => $role) { @@ -290,7 +290,7 @@ public function testGetRolesByNames(array $names, array $expectedRoleNames): voi public function testGetPermissions(): void { - $storage = $this->getStorage(); + $storage = $this->getItemsStorage(); $permissions = $storage->getPermissions(); $this->assertCount($this->initialPermissionsCount, $permissions); @@ -314,7 +314,7 @@ public function dataGetPermissionsByNames(): array */ public function testGetPermissionsByNames(array $names, array $expectedPermissionNames): void { - $permissions = $this->getStorage()->getPermissionsByNames($names); + $permissions = $this->getItemsStorage()->getPermissionsByNames($names); $this->assertCount(count($expectedPermissionNames), $permissions); foreach ($permissions as $permissionName => $permission) { @@ -325,7 +325,7 @@ public function testGetPermissionsByNames(array $names, array $expectedPermissio public function testRemove(): void { - $storage = $this->getStorage(); + $storage = $this->getItemsStorage(); $storage->remove('Parent 2'); $this->assertNull($storage->get('Parent 2')); @@ -354,7 +354,7 @@ public function getParentsProvider(): array */ public function testGetParents(string $childName, array $expectedParents): void { - $storage = $this->getStorage(); + $storage = $this->getItemsStorage(); $parents = $storage->getParents($childName); $this->assertCount(count($expectedParents), $parents); @@ -366,7 +366,7 @@ public function testGetParents(string $childName, array $expectedParents): void public function testRemoveChildren(): void { - $storage = $this->getStorage(); + $storage = $this->getItemsStorage(); $storage->removeChildren('Parent 2'); $this->assertFalse($storage->hasChildren('Parent 2')); @@ -375,7 +375,7 @@ public function testRemoveChildren(): void public function testGetRole(): void { - $storage = $this->getStorage(); + $storage = $this->getItemsStorage(); $role = $storage->getRole('Parent 1'); $this->assertNotEmpty($role); @@ -385,7 +385,7 @@ public function testGetRole(): void public function testAdd(): void { - $storage = $this->getStorage(); + $storage = $this->getItemsStorage(); $newItem = new Permission('Delete post'); $storage->add($newItem); @@ -394,7 +394,7 @@ public function testAdd(): void public function testRemoveChild(): void { - $storage = $this->getStorage(); + $storage = $this->getItemsStorage(); $storage->addChild('Parent 2', 'Child 1'); $storage->removeChild('Parent 2', 'Child 1'); @@ -407,13 +407,13 @@ public function testRemoveChild(): void public function testGetAll(): void { - $storage = $this->getStorage(); + $storage = $this->getItemsStorage(); $this->assertCount($this->getItemsCount(), $storage->getAll()); } public function testHasChildren(): void { - $storage = $this->getStorage(); + $storage = $this->getItemsStorage(); $this->assertTrue($storage->hasChildren('Parent 1')); $this->assertFalse($storage->hasChildren('Parent 3')); @@ -451,7 +451,7 @@ public function dataHasChild(): array */ public function testHasChild(string $parentName, string $childName, bool $expectedHasChild): void { - $this->assertSame($expectedHasChild, $this->getStorage()->hasChild($parentName, $childName)); + $this->assertSame($expectedHasChild, $this->getItemsStorage()->hasChild($parentName, $childName)); } public function dataHasDirectChild(): array @@ -486,12 +486,12 @@ public function dataHasDirectChild(): array */ public function testHasDirectChild(string $parentName, string $childName, bool $expectedHasDirectChild): void { - $this->assertSame($expectedHasDirectChild, $this->getStorage()->hasDirectChild($parentName, $childName)); + $this->assertSame($expectedHasDirectChild, $this->getItemsStorage()->hasDirectChild($parentName, $childName)); } public function testClearPermissions(): void { - $storage = $this->getStorage(); + $storage = $this->getItemsStorage(); $storage->clearPermissions(); $all = $storage->getAll(); @@ -501,7 +501,7 @@ public function testClearPermissions(): void public function testClearRoles(): void { - $storage = $this->getStorage(); + $storage = $this->getItemsStorage(); $storage->clearRoles(); $all = $storage->getAll(); @@ -511,16 +511,16 @@ public function testClearRoles(): void $this->assertTrue($storage->hasChildren('Parent 5')); } - protected function getStorage(): ItemsStorageInterface + protected function getItemsStorage(): ItemsStorageInterface { if ($this->storage === null) { - $this->storage = $this->createStorage(); + $this->storage = $this->createItemsStorage(); } return $this->storage; } - protected function createStorage(): ItemsStorageInterface + protected function createItemsStorage(): ItemsStorageInterface { return new FakeItemsStorage(); } @@ -604,9 +604,9 @@ protected function getFixtures(): array return ['items' => $items, 'itemsChildren' => $itemsChildren]; } - protected function populateStorage(): void + protected function populateItemsStorage(): void { - $storage = $this->getStorage(); + $storage = $this->getItemsStorage(); $fixtures = $this->getFixtures(); foreach ($fixtures['items'] as $itemData) { $name = $itemData['name'];