Skip to content

Commit

Permalink
Fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Jamie Hannaford committed Mar 18, 2016
1 parent 5eea65b commit 4a4aec0
Show file tree
Hide file tree
Showing 9 changed files with 26 additions and 83 deletions.
10 changes: 5 additions & 5 deletions src/Common/Resource/HasWaiterTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ trait HasWaiterTrait
* or exceed this timeout, the blocking operation will immediately cease.
* @param int $sleepPeriod The amount of time to pause between each HTTP request.
*/
public function waitUntil(string $status, int $timeout = 60, int $sleepPeriod = 1)
public function waitUntil(string $status, $timeout = 60, int $sleepPeriod = 1)
{
$startTime = time();

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

Expand All @@ -78,7 +78,7 @@ public function waitWithCallback(callable $fn, int $timeout = 60, int $sleepPeri
*
* @return bool
*/
private function shouldHalt(int $timeout, int $startTime)
private function shouldHalt($timeout, int $startTime)
{
if ($timeout === false) {
return false;
Expand All @@ -95,12 +95,12 @@ private function shouldHalt(int $timeout, int $startTime)
* or exceed this timeout, the blocking operation will immediately cease. If FALSE
* is provided, the timeout will never be considered.
*/
public function waitUntilActive(bool $timeout = false)
public function waitUntilActive($timeout = false)
{
$this->waitUntil('ACTIVE', $timeout);
}

public function waitUntilDeleted(int $timeout = 60, int $sleepPeriod = 1)
public function waitUntilDeleted($timeout = 60, int $sleepPeriod = 1)
{
$startTime = time();

Expand Down
21 changes: 9 additions & 12 deletions src/Common/Service/Builder.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@
use GuzzleHttp\Client;
use GuzzleHttp\ClientInterface;
use GuzzleHttp\Middleware as GuzzleMiddleware;
use OpenCloud\Common\Auth\IdentityService;
use OpenCloud\Common\Auth\Token;
use OpenCloud\Common\Transport\HandlerStack;
use OpenCloud\Common\Transport\Middleware;
use OpenCloud\Common\Transport\Utils;
use OpenCloud\Identity\v3\Service;

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

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

$this->stockIdentityService($options);
$this->stockAuthHandler($options);
$this->stockHttpClient($options, $serviceName);

Expand Down Expand Up @@ -121,14 +120,6 @@ private function addDebugMiddleware(array $options, HandlerStack &$stack)
}
}

private function stockIdentityService(array &$options)
{
if (!isset($options['identityService'])) {
$httpClient = $this->httpClient($options['authUrl'], HandlerStack::create());
$options['identityService'] = Service::factory($httpClient);
}
}

/**
* @param array $options
*
Expand Down Expand Up @@ -166,6 +157,12 @@ private function mergeOptions(array $serviceOptions): array
throw new \InvalidArgumentException('"authUrl" is a required option');
}

if (!isset($options['identityService']) || !($options['identityService'] instanceof IdentityService)) {
throw new \InvalidArgumentException(sprintf(
'"identityService" must be specified and implement %s', IdentityService::class
));
}

return $options;
}
}
}
2 changes: 1 addition & 1 deletion tests/integration/DefaultLogger.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php

namespace OpenCloud\integration;
namespace OpenCloud\Integration;

use Psr\Log\AbstractLogger;

Expand Down
12 changes: 7 additions & 5 deletions tests/integration/Runner.php
Original file line number Diff line number Diff line change
@@ -1,16 +1,19 @@
<?php

namespace OpenCloud\integration;
namespace OpenCloud\Integration;

class Runner
{
private $basePath;
private $logger;
private $services = [];
private $namespace;

public function __construct($basePath)
public function __construct($basePath, $testNamespace)
{
$this->basePath = $basePath;
$this->namespace = $testNamespace;

$this->logger = new DefaultLogger();
$this->assembleServicesFromSamples();
}
Expand Down Expand Up @@ -73,15 +76,14 @@ private function getRunnableServices($service, $version)
*/
private function getTest($serviceName, $version, $verbosity)
{
$namespace = (new \ReflectionClass($this))->getNamespaceName();
$className = sprintf("%s\\%s\\%sTest", $namespace, Utils::toCamelCase($serviceName), ucfirst($version));
$className = sprintf("%s\\%s\\%sTest", $this->namespace, Utils::toCamelCase($serviceName), ucfirst($version));

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

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

if (!($class instanceof TestInterface)) {
Expand Down
2 changes: 1 addition & 1 deletion tests/integration/SampleManagerInterface.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php

namespace OpenCloud\integration;
namespace OpenCloud\Integration;

interface SampleManagerInterface
{
Expand Down
2 changes: 1 addition & 1 deletion tests/integration/TestCase.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php

namespace OpenCloud\integration;
namespace OpenCloud\Integration;

use Psr\Log\LoggerInterface;

Expand Down
2 changes: 1 addition & 1 deletion tests/integration/TestInterface.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php

namespace OpenCloud\integration;
namespace OpenCloud\Integration;

use Psr\Log\LoggerInterface;

Expand Down
48 changes: 1 addition & 47 deletions tests/integration/Utils.php
Original file line number Diff line number Diff line change
@@ -1,57 +1,11 @@
<?php

namespace OpenCloud\integration;
namespace OpenCloud\Integration;

use GuzzleHttp\Client;
use OpenCloud\Identity\v2\Api;
use OpenCloud\Identity\v2\Service;
use OpenCloud\Common\Transport\HandlerStack;
use OpenCloud\Common\Transport\Utils as CommonUtils;

class Utils
{
public static function getAuthOptsV3()
{
return [
'authUrl' => getenv('OS_AUTH_URL'),
'region' => getenv('OS_REGION_NAME'),
'user' => [
'id' => getenv('OS_USER_ID'),
'password' => getenv('OS_PASSWORD'),
],
'scope' => [
'project' => [
'id' => getenv('OS_PROJECT_ID'),
]
]
];
}

public static function getAuthOptsV2()
{
$httpClient = new Client([
'base_uri' => CommonUtils::normalizeUrl(getenv('OS_AUTH_URL')),
'handler' => HandlerStack::create(),
]);
return [
'authUrl' => getenv('OS_AUTH_URL'),
'region' => getenv('OS_REGION_NAME'),
'username' => getenv('OS_USERNAME'),
'password' => getenv('OS_PASSWORD'),
'tenantName' => getenv('OS_TENANT_NAME'),
'identityService' => new Service($httpClient, new Api),
];
}

public static function getAuthOpts(array $options = [])
{
$authOptions = getenv('OS_IDENTITY_API_VERSION') == '2.0'
? self::getAuthOptsV2()
: self::getAuthOptsV3();

return array_merge($authOptions, $options);
}

public static function toCamelCase($word, $separator = '_')
{
return str_replace($separator, '', ucwords($word, $separator));
Expand Down
10 changes: 0 additions & 10 deletions tests/integration/run.php

This file was deleted.

0 comments on commit 4a4aec0

Please sign in to comment.