Skip to content

Commit 4a4aec0

Browse files
author
Jamie Hannaford
committed
Fix tests
1 parent 5eea65b commit 4a4aec0

File tree

9 files changed

+26
-83
lines changed

9 files changed

+26
-83
lines changed

src/Common/Resource/HasWaiterTrait.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ trait HasWaiterTrait
2424
* or exceed this timeout, the blocking operation will immediately cease.
2525
* @param int $sleepPeriod The amount of time to pause between each HTTP request.
2626
*/
27-
public function waitUntil(string $status, int $timeout = 60, int $sleepPeriod = 1)
27+
public function waitUntil(string $status, $timeout = 60, int $sleepPeriod = 1)
2828
{
2929
$startTime = time();
3030

@@ -53,7 +53,7 @@ public function waitUntil(string $status, int $timeout = 60, int $sleepPeriod =
5353
* is provided, the timeout will never be considered.
5454
* @param int $sleepPeriod The amount of time to pause between each HTTP request.
5555
*/
56-
public function waitWithCallback(callable $fn, int $timeout = 60, int $sleepPeriod = 1)
56+
public function waitWithCallback(callable $fn, $timeout = 60, int $sleepPeriod = 1)
5757
{
5858
$startTime = time();
5959

@@ -78,7 +78,7 @@ public function waitWithCallback(callable $fn, int $timeout = 60, int $sleepPeri
7878
*
7979
* @return bool
8080
*/
81-
private function shouldHalt(int $timeout, int $startTime)
81+
private function shouldHalt($timeout, int $startTime)
8282
{
8383
if ($timeout === false) {
8484
return false;
@@ -95,12 +95,12 @@ private function shouldHalt(int $timeout, int $startTime)
9595
* or exceed this timeout, the blocking operation will immediately cease. If FALSE
9696
* is provided, the timeout will never be considered.
9797
*/
98-
public function waitUntilActive(bool $timeout = false)
98+
public function waitUntilActive($timeout = false)
9999
{
100100
$this->waitUntil('ACTIVE', $timeout);
101101
}
102102

103-
public function waitUntilDeleted(int $timeout = 60, int $sleepPeriod = 1)
103+
public function waitUntilDeleted($timeout = 60, int $sleepPeriod = 1)
104104
{
105105
$startTime = time();
106106

src/Common/Service/Builder.php

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,11 @@
55
use GuzzleHttp\Client;
66
use GuzzleHttp\ClientInterface;
77
use GuzzleHttp\Middleware as GuzzleMiddleware;
8+
use OpenCloud\Common\Auth\IdentityService;
89
use OpenCloud\Common\Auth\Token;
910
use OpenCloud\Common\Transport\HandlerStack;
1011
use OpenCloud\Common\Transport\Middleware;
1112
use OpenCloud\Common\Transport\Utils;
12-
use OpenCloud\Identity\v3\Service;
1313

1414
/**
1515
* A Builder for easily creating OpenCloud services.
@@ -54,7 +54,7 @@ public function __construct(array $globalOptions = [], $rootNamespace = 'OpenClo
5454
*
5555
* @return array
5656
*/
57-
private function getClasses(string $serviceName, string $serviceVersion)
57+
private function getClasses(string $serviceName, int $serviceVersion)
5858
{
5959
$rootNamespace = sprintf("%s\\%s\\v%d", $this->rootNamespace, $serviceName, $serviceVersion);
6060

@@ -82,7 +82,6 @@ public function createService(string $serviceName, int $serviceVersion, array $s
8282
{
8383
$options = $this->mergeOptions($serviceOptions);
8484

85-
$this->stockIdentityService($options);
8685
$this->stockAuthHandler($options);
8786
$this->stockHttpClient($options, $serviceName);
8887

@@ -121,14 +120,6 @@ private function addDebugMiddleware(array $options, HandlerStack &$stack)
121120
}
122121
}
123122

124-
private function stockIdentityService(array &$options)
125-
{
126-
if (!isset($options['identityService'])) {
127-
$httpClient = $this->httpClient($options['authUrl'], HandlerStack::create());
128-
$options['identityService'] = Service::factory($httpClient);
129-
}
130-
}
131-
132123
/**
133124
* @param array $options
134125
*
@@ -166,6 +157,12 @@ private function mergeOptions(array $serviceOptions): array
166157
throw new \InvalidArgumentException('"authUrl" is a required option');
167158
}
168159

160+
if (!isset($options['identityService']) || !($options['identityService'] instanceof IdentityService)) {
161+
throw new \InvalidArgumentException(sprintf(
162+
'"identityService" must be specified and implement %s', IdentityService::class
163+
));
164+
}
165+
169166
return $options;
170167
}
171-
}
168+
}

tests/integration/DefaultLogger.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<?php
22

3-
namespace OpenCloud\integration;
3+
namespace OpenCloud\Integration;
44

55
use Psr\Log\AbstractLogger;
66

tests/integration/Runner.php

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,19 @@
11
<?php
22

3-
namespace OpenCloud\integration;
3+
namespace OpenCloud\Integration;
44

55
class Runner
66
{
77
private $basePath;
88
private $logger;
99
private $services = [];
10+
private $namespace;
1011

11-
public function __construct($basePath)
12+
public function __construct($basePath, $testNamespace)
1213
{
1314
$this->basePath = $basePath;
15+
$this->namespace = $testNamespace;
16+
1417
$this->logger = new DefaultLogger();
1518
$this->assembleServicesFromSamples();
1619
}
@@ -73,15 +76,14 @@ private function getRunnableServices($service, $version)
7376
*/
7477
private function getTest($serviceName, $version, $verbosity)
7578
{
76-
$namespace = (new \ReflectionClass($this))->getNamespaceName();
77-
$className = sprintf("%s\\%s\\%sTest", $namespace, Utils::toCamelCase($serviceName), ucfirst($version));
79+
$className = sprintf("%s\\%s\\%sTest", $this->namespace, Utils::toCamelCase($serviceName), ucfirst($version));
7880

7981
if (!class_exists($className)) {
8082
throw new \RuntimeException(sprintf("%s does not exist", $className));
8183
}
8284

8385
$basePath = $this->basePath . DIRECTORY_SEPARATOR . $serviceName . DIRECTORY_SEPARATOR . $version;
84-
$smClass = sprintf("%s\\SampleManager", $namespace);
86+
$smClass = sprintf("%s\\SampleManager", $this->namespace);
8587
$class = new $className($this->logger, new $smClass($basePath, $verbosity));
8688

8789
if (!($class instanceof TestInterface)) {

tests/integration/SampleManagerInterface.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<?php
22

3-
namespace OpenCloud\integration;
3+
namespace OpenCloud\Integration;
44

55
interface SampleManagerInterface
66
{

tests/integration/TestCase.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<?php
22

3-
namespace OpenCloud\integration;
3+
namespace OpenCloud\Integration;
44

55
use Psr\Log\LoggerInterface;
66

tests/integration/TestInterface.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<?php
22

3-
namespace OpenCloud\integration;
3+
namespace OpenCloud\Integration;
44

55
use Psr\Log\LoggerInterface;
66

tests/integration/Utils.php

Lines changed: 1 addition & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -1,57 +1,11 @@
11
<?php
22

3-
namespace OpenCloud\integration;
3+
namespace OpenCloud\Integration;
44

55
use GuzzleHttp\Client;
6-
use OpenCloud\Identity\v2\Api;
7-
use OpenCloud\Identity\v2\Service;
8-
use OpenCloud\Common\Transport\HandlerStack;
9-
use OpenCloud\Common\Transport\Utils as CommonUtils;
106

117
class Utils
128
{
13-
public static function getAuthOptsV3()
14-
{
15-
return [
16-
'authUrl' => getenv('OS_AUTH_URL'),
17-
'region' => getenv('OS_REGION_NAME'),
18-
'user' => [
19-
'id' => getenv('OS_USER_ID'),
20-
'password' => getenv('OS_PASSWORD'),
21-
],
22-
'scope' => [
23-
'project' => [
24-
'id' => getenv('OS_PROJECT_ID'),
25-
]
26-
]
27-
];
28-
}
29-
30-
public static function getAuthOptsV2()
31-
{
32-
$httpClient = new Client([
33-
'base_uri' => CommonUtils::normalizeUrl(getenv('OS_AUTH_URL')),
34-
'handler' => HandlerStack::create(),
35-
]);
36-
return [
37-
'authUrl' => getenv('OS_AUTH_URL'),
38-
'region' => getenv('OS_REGION_NAME'),
39-
'username' => getenv('OS_USERNAME'),
40-
'password' => getenv('OS_PASSWORD'),
41-
'tenantName' => getenv('OS_TENANT_NAME'),
42-
'identityService' => new Service($httpClient, new Api),
43-
];
44-
}
45-
46-
public static function getAuthOpts(array $options = [])
47-
{
48-
$authOptions = getenv('OS_IDENTITY_API_VERSION') == '2.0'
49-
? self::getAuthOptsV2()
50-
: self::getAuthOptsV3();
51-
52-
return array_merge($authOptions, $options);
53-
}
54-
559
public static function toCamelCase($word, $separator = '_')
5610
{
5711
return str_replace($separator, '', ucwords($word, $separator));

tests/integration/run.php

Lines changed: 0 additions & 10 deletions
This file was deleted.

0 commit comments

Comments
 (0)