Skip to content

Commit 2b0a7ee

Browse files
authored
IBX-9511: Fixed incorrect object type in PolicyValueResolver (#1442)
* Fixed incorrect object type in PolicyValueResolver * [Tests] Aligned PolicyValueResolverTest with the changes
1 parent 983fb73 commit 2b0a7ee

File tree

2 files changed

+18
-13
lines changed

2 files changed

+18
-13
lines changed

src/bundle/ValueResolver/PolicyValueResolver.php

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -43,15 +43,18 @@ protected function validateValue(string $value): bool
4343
return is_numeric($value);
4444
}
4545

46+
/**
47+
* @throws \Ibexa\Contracts\Core\Repository\Exceptions\NotFoundException
48+
* @throws \Ibexa\Contracts\Core\Repository\Exceptions\UnauthorizedException
49+
*/
4650
protected function load(array $key): object
4751
{
4852
$roleId = (int)$key[self::ATTRIBUTE_ROLE_ID];
4953
$policyId = (int)$key[self::ATTRIBUTE_POLICY_ID];
5054

51-
$roleDraft = $this->roleService->loadRole($roleId);
52-
foreach ($roleDraft->getPolicies() as $policy) {
53-
/** @var \Ibexa\Contracts\Core\Repository\Values\User\PolicyDraft $policy */
54-
if ($policy->originalId === $policyId) {
55+
$role = $this->roleService->loadRole($roleId);
56+
foreach ($role->getPolicies() as $policy) {
57+
if ($policy->id === $policyId) {
5558
return $policy;
5659
}
5760
}

tests/bundle/ValueResolver/PolicyValueResolverTest.php

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,9 @@
1010

1111
use Ibexa\Bundle\AdminUi\ValueResolver\PolicyValueResolver;
1212
use Ibexa\Contracts\Core\Repository\RoleService;
13+
use Ibexa\Contracts\Core\Repository\Values\User\Policy;
1314
use Ibexa\Contracts\Core\Repository\Values\User\PolicyDraft;
15+
use Ibexa\Contracts\Core\Repository\Values\User\Role;
1416
use Ibexa\Contracts\Core\Repository\Values\User\RoleDraft;
1517
use PHPUnit\Framework\MockObject\MockObject;
1618
use PHPUnit\Framework\TestCase;
@@ -32,16 +34,16 @@ protected function setUp(): void
3234

3335
public function testResolve(): void
3436
{
35-
$policyDraft = $this->createMock(PolicyDraft::class);
36-
$policyDraft
37+
$policy = $this->createMock(Policy::class);
38+
$policy
3739
->method('__get')
38-
->with('originalId')
40+
->with('id')
3941
->willReturn(123);
4042

41-
$roleDraft = $this->createMock(RoleDraft::class);
42-
$roleDraft
43+
$role = $this->createMock(Role::class);
44+
$role
4345
->method('getPolicies')
44-
->willReturn([$policyDraft]);
46+
->willReturn([$policy]);
4547

4648
$attributes = [
4749
'roleId' => '456',
@@ -51,18 +53,18 @@ public function testResolve(): void
5153
$this->roleService->expects(self::once())
5254
->method('loadRole')
5355
->with(456)
54-
->willReturn($roleDraft);
56+
->willReturn($role);
5557

5658
$argumentMetadata = $this->createMock(ArgumentMetadata::class);
57-
$argumentMetadata->method('getType')->willReturn(PolicyDraft::class);
59+
$argumentMetadata->method('getType')->willReturn(Policy::class);
5860
$argumentMetadata->method('getName')->willReturn('policy');
5961

6062
$request = new Request([], [], $attributes);
6163

6264
$result = iterator_to_array($this->resolver->resolve($request, $argumentMetadata));
6365

6466
self::assertCount(1, $result);
65-
self::assertSame($policyDraft, $result[0]);
67+
self::assertSame($policy, $result[0]);
6668
}
6769

6870
public function testResolvePolicyNotFound(): void

0 commit comments

Comments
 (0)