Skip to content

Commit 4f4a32c

Browse files
committed
add integration tests for Credential
1 parent 46bc05b commit 4f4a32c

File tree

5 files changed

+116
-4
lines changed

5 files changed

+116
-4
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: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -694,6 +694,7 @@ public function postCredentials(): array
694694
return [
695695
'method' => 'POST',
696696
'path' => 'credentials',
697+
'jsonKey' => 'credential',
697698
'params' => [
698699
'blob' => $this->params->blob(),
699700
'projectId' => $this->params->projectId(),
@@ -726,6 +727,7 @@ public function patchCredential(): array
726727
return [
727728
'method' => 'PATCH',
728729
'path' => 'credentials/{id}',
730+
'jsonKey' => 'credential',
729731
'params' => ['id' => $this->params->idUrl('credential')] + $this->postCredentials()['params'],
730732
];
731733
}

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
{

0 commit comments

Comments
 (0)