This commit is contained in:
manzerbredes 2016-03-28 12:17:43 +02:00
commit 53f65de9d4
88 changed files with 3596 additions and 694 deletions

View file

@ -1,6 +1,6 @@
<?php
namespace OpenCloud\integration;
namespace OpenCloud\Integration;
use Psr\Log\AbstractLogger;

View file

@ -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();
}
@ -73,15 +76,14 @@ class Runner
*/
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)) {

View file

@ -1,6 +1,6 @@
<?php
namespace OpenCloud\integration;
namespace OpenCloud\Integration;
interface SampleManagerInterface
{

View file

@ -1,6 +1,6 @@
<?php
namespace OpenCloud\integration;
namespace OpenCloud\Integration;
use Psr\Log\LoggerInterface;

View file

@ -1,6 +1,6 @@
<?php
namespace OpenCloud\integration;
namespace OpenCloud\Integration;
use Psr\Log\LoggerInterface;

View file

@ -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));

View file

@ -1,10 +0,0 @@
<?php
$rootDir = dirname(dirname(__DIR__));
require_once $rootDir . '/vendor/autoload.php';
$basePath = $rootDir . '/samples';
$runner = new \OpenCloud\Integration\Runner($basePath);
$runner->runServices();

View file

@ -10,7 +10,6 @@ use GuzzleHttp\Psr7\Uri;
use OpenCloud\Common\Api\Operator;
use OpenCloud\Common\Resource\AbstractResource;
use OpenCloud\Common\Resource\ResourceInterface;
use OpenCloud\Compute\v2\Models\Server;
use OpenCloud\Test\Fixtures\ComputeV2Api;
use OpenCloud\Test\TestCase;
use Prophecy\Argument;
@ -45,7 +44,7 @@ class OperatorTest extends TestCase
public function test_it_sends_a_request_when_operations_are_executed()
{
$this->client->request('GET', 'test', ['headers' => []])->willReturn(new Request('GET', 'test'));
$this->client->request('GET', 'test', ['headers' => []])->willReturn(new Response());
$this->operator->execute($this->def, []);
}

View file

@ -53,7 +53,11 @@ class AuthHandlerTest extends TestCase
}
}
class FakeToken implements Token {
public function getId() {}
public function hasExpired() {}
class FakeToken implements Token
{
public function getId(): string
{}
public function hasExpired(): bool
{}
}

View file

@ -95,8 +95,8 @@ class SchemaTest extends TestCase
public function test_it_checks_validity()
{
$this->validator->isValid()->shouldBeCalled();
$this->validator->isValid()->shouldBeCalled()->willReturn(true);
$this->schema->isValid();
}
}
}

View file

@ -47,8 +47,8 @@ class JsonSerializerTest extends \PHPUnit_Framework_TestCase
$itemSchema = $this->prophesize(Parameter::class);
$itemSchema->isArray()->shouldBeCalled()->willReturn(false);
$itemSchema->isObject()->shouldBeCalled()->willReturn(false);
$itemSchema->getName()->shouldBeCalled()->willReturn(null);
$itemSchema->getPath()->shouldBeCalled()->willReturn(null);
$itemSchema->getName()->shouldBeCalled()->willReturn('');
$itemSchema->getPath()->shouldBeCalled()->willReturn('');
$param->getItemSchema()->shouldBeCalled()->willReturn($itemSchema);
@ -67,7 +67,7 @@ class JsonSerializerTest extends \PHPUnit_Framework_TestCase
$prop->isArray()->shouldBeCalled()->willReturn(false);
$prop->isObject()->shouldBeCalled()->willReturn(false);
$prop->getName()->shouldBeCalled()->willReturn('foo');
$prop->getPath()->shouldBeCalled()->willReturn(null);
$prop->getPath()->shouldBeCalled()->willReturn('');
$param = $this->prophesize(Parameter::class);
$param->isArray()->shouldBeCalled()->willReturn(false);
@ -78,7 +78,7 @@ class JsonSerializerTest extends \PHPUnit_Framework_TestCase
$expected = ['topLevel' => ['foo' => true]];
$json = $this->serializer->stockJson($param->reveal(), ['foo' => true], []);
$json = $this->serializer->stockJson($param->reveal(), (object) ['foo' => true], []);
$this->assertEquals($expected, $json);
}

View file

@ -53,7 +53,17 @@ class ComputeV2Api implements ApiInterface
]
],
'name' => ['type' => 'string', 'required' => true],
'metadata' => ['type' => 'object', 'location' => 'json'],
'metadata' => [
'type' => 'object',
'location' => 'json',
'description' => 'An arbitrary key/value pairing that will be used for metadata.',
'properties' => [
'type' => 'string',
'description' => <<<TYPEOTHER
The value being set for your key. Bear in mind that "key" is just an example, you can name it anything.
TYPEOTHER
]
],
'personality' => ['type' => 'string'],
'blockDeviceMapping' => [
'type' => 'array',