Skip to content

Commit e5c20fc

Browse files
authored
Merge branch 'master' into sample-fix-create-large-object
2 parents f11a4f5 + 939a714 commit e5c20fc

File tree

7 files changed

+133
-17
lines changed

7 files changed

+133
-17
lines changed

samples/Identity/v3/credentials/delete.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,5 +13,5 @@
1313

1414
$identity = $openstack->identityV3();
1515

16-
$credential = $identity->getCredential('credentialId');
16+
$credential = $identity->getCredential('{credentialId}');
1717
$credential->delete();

src/Identity/v3/Api.php

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -692,9 +692,10 @@ public function headGroupUser(): array
692692
public function postCredentials(): array
693693
{
694694
return [
695-
'method' => 'POST',
696-
'path' => 'credentials',
697-
'params' => [
695+
'method' => 'POST',
696+
'path' => 'credentials',
697+
'jsonKey' => 'credential',
698+
'params' => [
698699
'blob' => $this->params->blob(),
699700
'projectId' => $this->params->projectId(),
700701
'type' => $this->params->type('credential'),
@@ -724,9 +725,10 @@ public function getCredential(): array
724725
public function patchCredential(): array
725726
{
726727
return [
727-
'method' => 'PATCH',
728-
'path' => 'credentials/{id}',
729-
'params' => ['id' => $this->params->idUrl('credential')] + $this->postCredentials()['params'],
728+
'method' => 'PATCH',
729+
'path' => 'credentials/{id}',
730+
'jsonKey' => 'credential',
731+
'params' => ['id' => $this->params->idUrl('credential')] + $this->postCredentials()['params'],
730732
];
731733
}
732734

src/Identity/v3/Models/Credential.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,9 @@ class Credential extends OperatorResource implements Creatable, Updateable, Retr
3939
'user_id' => 'userId',
4040
];
4141

42+
protected $resourceKey = 'credential';
43+
protected $resourcesKey = 'credentials';
44+
4245
public function create(array $userOptions): Creatable
4346
{
4447
$response = $this->execute($this->api->postCredentials(), $userOptions);
Lines changed: 107 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,107 @@
1+
<?php
2+
3+
namespace OpenStack\Sample\Identity\v3;
4+
5+
use OpenStack\Common\Error\BadResponseError;
6+
use OpenStack\Identity\v3\Models\Credential;
7+
8+
class CredentialTest extends TestCase
9+
{
10+
public function testCreate(): Credential
11+
{
12+
/** @var $credential \OpenStack\Identity\v3\Models\Role */
13+
require_once $this->sampleFile('credentials/create.php', [
14+
'{blob}' => '{"access":"181920","secret":"secretKey"}',
15+
'{type}' => 'ec2',
16+
]);
17+
$this->assertInstanceOf(Credential::class, $credential);
18+
19+
return $credential;
20+
}
21+
22+
/**
23+
* @depends testCreate
24+
*/
25+
public function testList(Credential $createdCredential): void
26+
{
27+
$found = false;
28+
require_once $this->sampleFile(
29+
'credentials/list.php',
30+
[
31+
'/** @var $credential \OpenStack\Identity\v3\Models\Credential */' => <<<'PHP'
32+
/** @var $credential \OpenStack\Identity\v3\Models\Credential */
33+
if ($credential->id === $createdCredential->id) {
34+
$found = true;
35+
}
36+
PHP
37+
,
38+
]
39+
);
40+
41+
$this->assertTrue($found);
42+
}
43+
44+
/**
45+
* @depends testCreate
46+
*/
47+
public function testRead(Credential $createdCredential)
48+
{
49+
/** @var $credential \OpenStack\Identity\v3\Models\Credential */
50+
require_once $this->sampleFile(
51+
'credentials/read.php',
52+
['{credentialId}' => $createdCredential->id]
53+
);
54+
55+
$this->assertInstanceOf(Credential::class, $credential);
56+
$this->assertEquals($createdCredential->blob, $credential->blob);
57+
$this->assertEquals($createdCredential->type, $credential->type);
58+
}
59+
60+
/**
61+
* @depends testCreate
62+
*/
63+
public function testUpdate(Credential $createdCredential)
64+
{
65+
$newBlob = '{"access":"181920","secret":"newSecretKey"}';
66+
67+
/** @var $credential \OpenStack\Identity\v3\Models\Credential */
68+
require_once $this->sampleFile(
69+
'credentials/update.php',
70+
[
71+
'{credentialId}' => $createdCredential->id,
72+
'{blob}' => $newBlob,
73+
'{type}' => 'ec3',
74+
]
75+
);
76+
77+
$this->assertInstanceOf(Credential::class, $credential);
78+
$this->assertEquals($newBlob, $credential->blob);
79+
$this->assertEquals('ec3', $credential->type);
80+
}
81+
82+
83+
/**
84+
* @depends testCreate
85+
*/
86+
public function testDelete(Credential $createdCredential): void
87+
{
88+
require_once $this->sampleFile(
89+
'credentials/delete.php',
90+
[
91+
'{credentialId}' => $createdCredential->id,
92+
]
93+
);
94+
95+
$found = false;
96+
foreach ($this->getService()->listCredentials() as $credential) {
97+
if ($credential->id === $createdCredential->id) {
98+
$found = true;
99+
}
100+
}
101+
102+
$this->assertFalse($found);
103+
104+
$this->expectException(BadResponseError::class);
105+
$createdCredential->retrieve();
106+
}
107+
}

tests/sample/Identity/v3/RoleTest.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
class RoleTest extends TestCase
88
{
9-
public function testCeate(): Role
9+
public function testCreate(): Role
1010
{
1111
/** @var $role \OpenStack\Identity\v3\Models\Role */
1212
require_once $this->sampleFile('roles/create.php', ['{name}' => $this->randomStr()]);
@@ -16,7 +16,7 @@ public function testCeate(): Role
1616
}
1717

1818
/**
19-
* @depends testCeate
19+
* @depends testCreate
2020
*/
2121
public function testList(Role $createdRole): void
2222
{
@@ -38,7 +38,7 @@ public function testList(Role $createdRole): void
3838
}
3939

4040
/**
41-
* @depends testCeate
41+
* @depends testCreate
4242
*/
4343
public function testListAssignments(Role $createdRole): void
4444
{

tests/unit/Identity/v3/Models/CredentialTest.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,10 @@ public function test_it_updates()
3434
$this->credential->projectId = 'bar';
3535

3636
$expectedJson = [
37-
'type' => 'foo',
38-
'project_id' => 'bar',
37+
'credential' => [
38+
'type' => 'foo',
39+
'project_id' => 'bar',
40+
]
3941
];
4042

4143
$this->mockRequest('PATCH', 'credentials/CRED_ID', 'cred', $expectedJson, []);

tests/unit/Identity/v3/ServiceTest.php

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -504,14 +504,16 @@ public function test_it_creates_credential()
504504
'blob' => "{\"access\":\"--access-key--\",\"secret\":\"--secret-key--\"}",
505505
'projectId' => 'project_id',
506506
'type' => 'ec2',
507-
'userId' => 'user_id'
507+
'userId' => 'user_id',
508508
];
509509

510510
$userJson = [
511-
'blob' => $userOptions['blob'],
512-
'project_id' => $userOptions['projectId'],
513-
'type' => $userOptions['type'],
514-
'user_id' => $userOptions['userId'],
511+
'credential' => [
512+
'blob' => $userOptions['blob'],
513+
'project_id' => $userOptions['projectId'],
514+
'type' => $userOptions['type'],
515+
'user_id' => $userOptions['userId'],
516+
],
515517
];
516518

517519
$this->mockRequest('POST', 'credentials', 'cred', $userJson);

0 commit comments

Comments
 (0)