Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use snake case for item attribute names (ease migration from Yii 2) #227

Merged
merged 3 commits into from
Jan 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@
- Bug #221: Exclude items with base names when getting children (@arogachev)
- Bug #222: Adjust hierarchy when removing item (@arogachev)
- Bug #223: Handle empty assignments in `Manager::getPermissionsByUserId()` (@arogachev)
- Enh #227: Use snake case for item attribute names (ease migration from Yii 2) (@arogachev)

## 1.0.2 April 20, 2023

Expand Down
12 changes: 6 additions & 6 deletions src/Item.php
Original file line number Diff line number Diff line change
Expand Up @@ -139,21 +139,21 @@ final public function hasUpdatedAt(): bool
* @psalm-return array{
* name:string,
* description:string,
* ruleName:string|null,
* rule_name:string|null,
* type:string,
* updatedAt:int|null,
* createdAt:int|null,
* updated_at:int|null,
* created_at:int|null,
* }
*/
final public function getAttributes(): array
{
return [
'name' => $this->getName(),
'description' => $this->getDescription(),
'ruleName' => $this->getRuleName(),
'rule_name' => $this->getRuleName(),
'type' => $this->getType(),
'updatedAt' => $this->getUpdatedAt(),
'createdAt' => $this->getCreatedAt(),
'updated_at' => $this->getUpdatedAt(),
'created_at' => $this->getCreatedAt(),
];
}
}
28 changes: 14 additions & 14 deletions tests/Common/AssignmentsStorageTestTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -270,25 +270,25 @@ protected function getFixtures(): array
];
$items = array_map(
static function (array $item) use ($time): array {
$item['createdAt'] = $time;
$item['updatedAt'] = $time;
$item['created_at'] = $time;
$item['updated_at'] = $time;

return $item;
},
$items,
);
$assignments = [
['itemName' => 'Researcher', 'userId' => 'john'],
['itemName' => 'Accountant', 'userId' => 'john'],
['itemName' => 'Quality control specialist', 'userId' => 'john'],
['itemName' => 'Operator', 'userId' => 'jack'],
['itemName' => 'Manager', 'userId' => 'jack'],
['itemName' => 'Support specialist', 'userId' => 'jack'],
['itemName' => 'Operator', 'userId' => 'jeff'],
['item_name' => 'Researcher', 'user_id' => 'john'],
['item_name' => 'Accountant', 'user_id' => 'john'],
['item_name' => 'Quality control specialist', 'user_id' => 'john'],
['item_name' => 'Operator', 'user_id' => 'jack'],
['item_name' => 'Manager', 'user_id' => 'jack'],
['item_name' => 'Support specialist', 'user_id' => 'jack'],
['item_name' => 'Operator', 'user_id' => 'jeff'],
];
$assignments = array_map(
static function (array $item) use ($time): array {
$item['createdAt'] = $time;
$item['created_at'] = $time;

return $item;
},
Expand All @@ -304,8 +304,8 @@ protected function populateItemsStorage(): void
$name = $itemData['name'];
$item = $itemData['type'] === Item::TYPE_PERMISSION ? new Permission($name) : new Role($name);
$item = $item
->withCreatedAt($itemData['createdAt'])
->withUpdatedAt($itemData['updatedAt']);
->withCreatedAt($itemData['created_at'])
->withUpdatedAt($itemData['updated_at']);
$this->getItemsStorage()->add($item);
}
}
Expand All @@ -315,8 +315,8 @@ protected function populateAssignmentsStorage(): void
foreach ($this->getFixtures()['assignments'] as $assignmentData) {
$this->getAssignmentsStorage()->add(
new Assignment(
userId: $assignmentData['userId'],
itemName: $assignmentData['itemName'],
userId: $assignmentData['user_id'],
itemName: $assignmentData['item_name'],
createdAt: time(),
),
);
Expand Down
8 changes: 4 additions & 4 deletions tests/Common/ItemsStorageTestTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -601,8 +601,8 @@ protected function getFixtures(): array
$items[] = [
'name' => $name,
'type' => $type,
'createdAt' => $time,
'updatedAt' => $time,
'created_at' => $time,
'updated_at' => $time,
];
$type === Item::TYPE_ROLE ? $this->initialRolesCount++ : $this->initialPermissionsCount++;
}
Expand Down Expand Up @@ -652,8 +652,8 @@ protected function populateItemsStorage(): void
$name = $itemData['name'];
$item = $itemData['type'] === Item::TYPE_PERMISSION ? new Permission($name) : new Role($name);
$item = $item
->withCreatedAt($itemData['createdAt'])
->withUpdatedAt($itemData['updatedAt']);
->withCreatedAt($itemData['created_at'])
->withUpdatedAt($itemData['updated_at']);
$storage->add($item);
}

Expand Down
12 changes: 6 additions & 6 deletions tests/Common/ManagerLogicTestTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -631,10 +631,10 @@ public function testAddRole(): void
[
'name' => 'new role',
'description' => 'new role description',
'ruleName' => EasyRule::class,
'rule_name' => EasyRule::class,
'type' => 'role',
'updatedAt' => 1_642_026_148,
'createdAt' => 1_642_026_147,
'updated_at' => 1_642_026_148,
'created_at' => 1_642_026_147,
],
$storedRole->getAttributes()
);
Expand Down Expand Up @@ -696,10 +696,10 @@ public function testAddPermission(): void
[
'name' => 'edit post',
'description' => 'edit a post',
'ruleName' => null,
'rule_name' => null,
'type' => 'permission',
'updatedAt' => 1_642_026_148,
'createdAt' => 1_642_026_147,
'updated_at' => 1_642_026_148,
'created_at' => 1_642_026_147,
],
$storedPermission->getAttributes()
);
Expand Down
6 changes: 3 additions & 3 deletions tests/PermissionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,10 @@ public function testDefaultAttributes(): void
$this->assertSame([
'name' => 'test',
'description' => '',
'ruleName' => null,
'rule_name' => null,
'type' => Item::TYPE_PERMISSION,
'updatedAt' => null,
'createdAt' => null,
'updated_at' => null,
'created_at' => null,
], $permission->getAttributes());
}
}
6 changes: 3 additions & 3 deletions tests/RoleTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,10 @@ public function testDefaultAttributes(): void
$this->assertSame([
'name' => 'test',
'description' => '',
'ruleName' => null,
'rule_name' => null,
'type' => Item::TYPE_ROLE,
'updatedAt' => null,
'createdAt' => null,
'updated_at' => null,
'created_at' => null,
], $permission->getAttributes());
}
}
Loading