Skip to content

Commit 45bd478

Browse files
authored
Refactor tests (#384)
use `include_once $this->sampleFile(` instead of `$path = $this->sampleFile(..); include_once $path`
1 parent 2804874 commit 45bd478

File tree

11 files changed

+239
-346
lines changed

11 files changed

+239
-346
lines changed

src/Common/Resource/HasWaiterTrait.php

+4-4
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,10 @@ trait HasWaiterTrait
1919
* will enter a loop, requesting feedback from the remote API until it sends back an appropriate
2020
* status.
2121
*
22-
* @param string $status The state to be reached
23-
* @param int $timeout The maximum timeout. If the total time taken by the waiter has reached
24-
* or exceed this timeout, the blocking operation will immediately cease.
25-
* @param int $sleepPeriod the amount of time to pause between each HTTP request
22+
* @param string $status The state to be reached
23+
* @param bool|int $timeout The maximum timeout. If the total time taken by the waiter has reached
24+
* or exceed this timeout, the blocking operation will immediately cease.
25+
* @param int $sleepPeriod the amount of time to pause between each HTTP request
2626
*/
2727
public function waitUntil(string $status, $timeout = 60, int $sleepPeriod = 1)
2828
{

tests/integration/BlockStorage/v2/CoreTest.php

+3-3
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,13 @@ protected function getService() : Service
1717
return $this->service;
1818
}
1919

20-
protected function sampleFile(array $replacements, $path)
20+
protected function sampleFile($path, array $replacements = [])
2121
{
2222
return parent::sampleFile(
23+
'../v3/' . $path,
2324
array_merge(
2425
$replacements,
2526
['$openstack->blockStorageV3()' => '$openstack->blockStorageV2()']
26-
),
27-
'../v3/' . $path);
27+
));
2828
}
2929
}

tests/integration/BlockStorage/v3/CoreV2Test.php

+22-22
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ public function volumes()
5454

5555
$this->logStep('Creating volume');
5656
/** @var Volume $volume */
57-
require_once $this->sampleFile($replacements, 'volumes/create.php');
57+
require_once $this->sampleFile('volumes/create.php', $replacements);
5858
self::assertInstanceOf(Volume::class, $volume);
5959
self::assertEquals($replacements['{name}'], $volume->name);
6060
self::assertEquals(1, $volume->size);
@@ -65,7 +65,7 @@ public function volumes()
6565

6666
$this->logStep('Getting volume');
6767
/** @var Volume $volume */
68-
require_once $this->sampleFile($replacements, 'volumes/get.php');
68+
require_once $this->sampleFile('volumes/get.php', $replacements);
6969
self::assertInstanceOf(Volume::class, $volume);
7070

7171
$replacements += [
@@ -75,18 +75,18 @@ public function volumes()
7575

7676
$this->logStep('Updating volume');
7777
/** @var Volume $volume */
78-
require_once $this->sampleFile($replacements, 'volumes/update.php');
78+
require_once $this->sampleFile('volumes/update.php', $replacements);
7979
self::assertInstanceOf(Volume::class, $volume);
8080

8181
$this->logStep('Listing volumes');
8282
/** @var \Generator $volumes */
83-
require_once $this->sampleFile($replacements, 'volumes/list.php');
83+
require_once $this->sampleFile('volumes/list.php', $replacements);
8484

8585
$volume = $this->getService()->getVolume($volumeId);
8686
$volume->waitUntil('available');
8787

8888
$this->logStep('Deleting volume');
89-
require_once $this->sampleFile($replacements, 'volumes/delete.php');
89+
require_once $this->sampleFile('volumes/delete.php', $replacements);
9090

9191
$volume = $this->getService()->getVolume($volumeId);
9292
$volume->waitUntilDeleted();
@@ -103,30 +103,30 @@ public function volumeTypes()
103103

104104
$this->logStep('Creating volume type');
105105
/** @var VolumeType $volumeType */
106-
require_once $this->sampleFile($replacements, 'volume_types/create.php');
106+
require_once $this->sampleFile('volume_types/create.php', $replacements);
107107
self::assertInstanceOf(VolumeType::class, $volumeType);
108108
self::assertEquals($replacements['{name}'], $volumeType->name);
109109

110110
$replacements = ['{volumeTypeId}' => $volumeType->id];
111111

112112
$this->logStep('Getting volume type');
113113
/** @var VolumeType $volumeType */
114-
require_once $this->sampleFile($replacements, 'volume_types/get.php');
114+
require_once $this->sampleFile('volume_types/get.php', $replacements);
115115
self::assertInstanceOf(VolumeType::class, $volumeType);
116116

117117
$replacements += ['{newName}' => $this->randomStr()];
118118

119119
$this->logStep('Updating volume type');
120120
/** @var VolumeType $volumeType */
121-
require_once $this->sampleFile($replacements, 'volume_types/update.php');
121+
require_once $this->sampleFile('volume_types/update.php', $replacements);
122122
self::assertInstanceOf(VolumeType::class, $volumeType);
123123

124124
$this->logStep('Listing volume types');
125125
/** @var \Generator $volumeTypes */
126-
require_once $this->sampleFile($replacements, 'volume_types/list.php');
126+
require_once $this->sampleFile('volume_types/list.php', $replacements);
127127

128128
$this->logStep('Deleting volume type');
129-
require_once $this->sampleFile($replacements, 'volume_types/delete.php');
129+
require_once $this->sampleFile('volume_types/delete.php', $replacements);
130130
}
131131

132132
public function snapshots()
@@ -143,7 +143,7 @@ public function snapshots()
143143

144144
$this->logStep('Creating snapshot');
145145
/** @var Snapshot $snapshot */
146-
require_once $this->sampleFile($replacements, 'snapshots/create.php');
146+
require_once $this->sampleFile('snapshots/create.php', $replacements);
147147
self::assertInstanceOf(Snapshot::class, $snapshot);
148148
self::assertEquals($replacements['{name}'], $snapshot->name);
149149
$volume->waitUntil('available', 60);
@@ -153,7 +153,7 @@ public function snapshots()
153153

154154
$this->logStep('Getting snapshot');
155155
/** @var Snapshot $snapshot */
156-
require_once $this->sampleFile($replacements, 'snapshots/get.php');
156+
require_once $this->sampleFile('snapshots/get.php', $replacements);
157157
self::assertInstanceOf(Snapshot::class, $snapshot);
158158

159159
$this->getService()
@@ -162,33 +162,33 @@ public function snapshots()
162162

163163
$replacements += ['{key}' => 'key2', '{val}' => 'val2'];
164164
$this->logStep('Adding metadata');
165-
require_once $this->sampleFile($replacements, 'snapshots/merge_metadata.php');
165+
require_once $this->sampleFile('snapshots/merge_metadata.php', $replacements);
166166

167167
$this->logStep('Retrieving metadata');
168168
/** @var array $metadata */
169-
require_once $this->sampleFile($replacements, 'snapshots/get_metadata.php');
169+
require_once $this->sampleFile('snapshots/get_metadata.php', $replacements);
170170
self::assertEquals(['key1' => 'val1', 'key2' => 'val2'], $metadata);
171171

172172
$replacements = ['{snapshotId}' => $snapshot->id, '{key}' => 'key3', '{val}' => 'val3'];
173173
$this->logStep('Resetting metadata');
174-
require_once $this->sampleFile($replacements, 'snapshots/reset_metadata.php');
174+
require_once $this->sampleFile('snapshots/reset_metadata.php', $replacements);
175175

176176
$this->logStep('Retrieving metadata');
177177
/** @var array $metadata */
178-
require_once $this->sampleFile($replacements, 'snapshots/get_metadata.php');
178+
require_once $this->sampleFile('snapshots/get_metadata.php', $replacements);
179179
self::assertEquals(['key3' => 'val3'], $metadata);
180180

181181
$replacements += ['{newName}' => $this->randomStr(), '{newDescription}' => $this->randomStr()];
182182
$this->logStep('Updating snapshot');
183-
require_once $this->sampleFile($replacements, 'snapshots/update.php');
183+
require_once $this->sampleFile('snapshots/update.php', $replacements);
184184

185185
$snapshot->waitUntil('available', 60);
186186

187187
$this->logStep('Listing snapshots');
188-
require_once $this->sampleFile($replacements, 'snapshots/list.php');
188+
require_once $this->sampleFile('snapshots/list.php', $replacements);
189189

190190
$this->logStep('Deleting snapshot');
191-
require_once $this->sampleFile($replacements, 'snapshots/delete.php');
191+
require_once $this->sampleFile('snapshots/delete.php', $replacements);
192192
$snapshot->waitUntilDeleted();
193193

194194
$this->logStep('Deleting volume');
@@ -223,18 +223,18 @@ public function snapshotList()
223223
];
224224

225225
$this->logStep('Listing snapshots');
226-
require_once $this->sampleFile($replacements, 'snapshots/list.php');
226+
require_once $this->sampleFile('snapshots/list.php', $replacements);
227227

228228
$this->logStep('Listing snapshots sorted asc');
229229
/** @var Snapshot $snapshot */
230-
require_once $this->sampleFile($replacements, 'snapshots/list_sorted.php');
230+
require_once $this->sampleFile('snapshots/list_sorted.php', $replacements);
231231
self::assertInstanceOf(Snapshot::class, $snapshot);
232232
self::assertEquals($names[2], $snapshot->name);
233233

234234
$this->logStep('Listing snapshots sorted desc');
235235
$replacements['{sortDir}'] = 'desc';
236236
/** @var Snapshot $snapshot */
237-
require_once $this->sampleFile($replacements, 'snapshots/list_sorted.php');
237+
require_once $this->sampleFile('snapshots/list_sorted.php', $replacements);
238238
self::assertInstanceOf(Snapshot::class, $snapshot);
239239
self::assertEquals($names[1], $snapshot->name);
240240
} finally {

0 commit comments

Comments
 (0)