diff options
| author | Eole <EoleDev@outlook.fr> | 2016-04-27 16:42:28 +0200 |
|---|---|---|
| committer | Eole <EoleDev@outlook.fr> | 2016-04-27 16:42:28 +0200 |
| commit | 49f416dc5061032e0514ea0cfeceaca37d13e432 (patch) | |
| tree | 1202ac2a6fa860b8929afdc886c94fc50bd0a1de /server/vendor/php-opencloud/common/tests/integration | |
| parent | c7edd70b5e5b0f5159c78ce3d924d4e7f60db816 (diff) | |
| parent | c9202d9113210981ae47df40511645da2ee140df (diff) | |
Merge branch 'develop' into Eole_Graph
Conflicts:
client/index.html
client/js/controllers/home/home.js
client/partials/home/home.html
Diffstat (limited to 'server/vendor/php-opencloud/common/tests/integration')
12 files changed, 0 insertions, 458 deletions
diff --git a/server/vendor/php-opencloud/common/tests/integration/DefaultLogger.php b/server/vendor/php-opencloud/common/tests/integration/DefaultLogger.php deleted file mode 100644 index a546c70..0000000 --- a/server/vendor/php-opencloud/common/tests/integration/DefaultLogger.php +++ /dev/null @@ -1,20 +0,0 @@ -<?php - -namespace OpenCloud\integration; - -use Psr\Log\AbstractLogger; - -class DefaultLogger extends AbstractLogger -{ - public function log($level, $message, array $context = []) - { - echo $this->format($level, $message, $context); - } - - private function format($level, $message, $context) - { - $msg = strtr($message, $context); - - return sprintf("%s: %s\n", strtoupper($level), $msg); - } -} diff --git a/server/vendor/php-opencloud/common/tests/integration/Runner.php b/server/vendor/php-opencloud/common/tests/integration/Runner.php deleted file mode 100644 index 98d094c..0000000 --- a/server/vendor/php-opencloud/common/tests/integration/Runner.php +++ /dev/null @@ -1,112 +0,0 @@ -<?php - -namespace OpenCloud\integration; - -class Runner -{ - private $basePath; - private $logger; - private $services = []; - - public function __construct($basePath) - { - $this->basePath = $basePath; - $this->logger = new DefaultLogger(); - $this->assembleServicesFromSamples(); - } - - private function traverse($path) - { - return new \RecursiveDirectoryIterator($path, \FilesystemIterator::SKIP_DOTS); - } - - private function assembleServicesFromSamples() - { - foreach ($this->traverse($this->basePath) as $servicePath) { - if ($servicePath->isDir()) { - foreach ($this->traverse($servicePath) as $versionPath) { - $this->services[$servicePath->getBasename()][] = $versionPath->getBasename(); - } - } - } - } - - private function getOpts() - { - $opts = getopt('s:v:t:', ['service:', 'version:', 'test::', 'debug::', 'help::']); - - $getOpt = function (array $keys, $default) use ($opts) { - foreach ($keys as $key) { - if (isset($opts[$key])) { - return $opts[$key]; - } - } - return $default; - }; - - return [ - $getOpt(['s', 'service'], 'all'), - $getOpt(['n', 'version'], 'all'), - $getOpt(['t', 'test'], ''), - isset($opts['debug']) ? (int) $opts['debug'] : 0, - ]; - } - - private function getRunnableServices($service, $version) - { - $services = $this->services; - - if ($service != 'all') { - if (!isset($this->services[$service])) { - throw new \InvalidArgumentException(sprintf("%s service does not exist", $service)); - } - - $versions = ($version == 'all') ? $this->services[$service] : [$version]; - $services = [$service => $versions]; - } - - return $services; - } - - /** - * @return TestInterface - */ - private function getTest($serviceName, $version, $verbosity) - { - $namespace = (new \ReflectionClass($this))->getNamespaceName(); - $className = sprintf("%s\\%s\\%sTest", $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); - $class = new $className($this->logger, new $smClass($basePath, $verbosity)); - - if (!($class instanceof TestInterface)) { - throw new \RuntimeException(sprintf("%s does not implement TestInterface", $className)); - } - - return $class; - } - - public function runServices() - { - list($serviceOpt, $versionOpt, $testMethodOpt, $verbosityOpt) = $this->getOpts(); - - foreach ($this->getRunnableServices($serviceOpt, $versionOpt) as $serviceName => $versions) { - foreach ($versions as $version) { - $testRunner = $this->getTest($serviceName, $version, $verbosityOpt); - - if ($testMethodOpt) { - $testRunner->runOneTest($testMethodOpt); - } else { - $testRunner->runTests(); - } - - $testRunner->teardown(); - } - } - } -} diff --git a/server/vendor/php-opencloud/common/tests/integration/SampleManager.php b/server/vendor/php-opencloud/common/tests/integration/SampleManager.php deleted file mode 100644 index 4bd8b9a..0000000 --- a/server/vendor/php-opencloud/common/tests/integration/SampleManager.php +++ /dev/null @@ -1,104 +0,0 @@ -<?php - -namespace OpenCloud\integration; - -class SampleManager implements SampleManagerInterface -{ - protected $basePath; - protected $paths = []; - protected $verbosity; - - public function __construct($basePath, $verbosity) - { - $this->basePath = $basePath; - $this->verbosity = $verbosity; - } - - public function deletePaths() - { - if (!empty($this->paths)) { - foreach ($this->paths as $path) { - unlink($path); - } - } - } - - protected function getGlobalReplacements() - { - return [ - '{userId}' => getenv('OS_USER_ID'), - '{username}' => getenv('OS_USERNAME'), - '{password}' => getenv('OS_PASSWORD'), - '{domainId}' => getenv('OS_DOMAIN_ID'), - '{authUrl}' => getenv('OS_AUTH_URL'), - '{tenantId}' => getenv('OS_TENANT_ID'), - '{region}' => getenv('OS_REGION'), - '{projectId}' => getenv('OS_PROJECT_ID'), - '{projectName}' => getenv('OS_PROJECT_NAME'), - ]; - } - - protected function getConnectionTemplate() - { - if ($this->verbosity === 1) { - $subst = <<<'EOL' -use OpenCloud\Integration\DefaultLogger; -use OpenCloud\Integration\Utils; -use GuzzleHttp\MessageFormatter; - -$options = [ - 'debugLog' => true, - 'logger' => new DefaultLogger(), - 'messageFormatter' => new MessageFormatter(), -]; -$openstack = new OpenCloud\OpenCloud(Utils::getAuthOpts($options)); -EOL; - } elseif ($this->verbosity === 2) { - $subst = <<<'EOL' -use OpenCloud\Integration\DefaultLogger; -use OpenCloud\Integration\Utils; -use GuzzleHttp\MessageFormatter; - -$options = [ - 'debugLog' => true, - 'logger' => new DefaultLogger(), - 'messageFormatter' => new MessageFormatter(MessageFormatter::DEBUG), -]; -$openstack = new OpenCloud\OpenCloud(Utils::getAuthOpts($options)); -EOL; - } else { - $subst = <<<'EOL' -use OpenCloud\Integration\Utils; - -$openstack = new OpenCloud\OpenCloud(Utils::getAuthOpts()); -EOL; - } - - return $subst; - } - - public function write($path, array $replacements) - { - $replacements = array_merge($this->getGlobalReplacements(), $replacements); - - $sampleFile = rtrim($this->basePath, DIRECTORY_SEPARATOR) . DIRECTORY_SEPARATOR . $path; - - if (!file_exists($sampleFile) || !is_readable($sampleFile)) { - throw new \RuntimeException(sprintf("%s either does not exist or is not readable", $sampleFile)); - } - - $content = strtr(file_get_contents($sampleFile), $replacements); - $content = str_replace("'vendor/'", "'" . dirname(dirname(__DIR__)) . DIRECTORY_SEPARATOR . "vendor'", $content); - - $subst = $this->getConnectionTemplate(); - $content = preg_replace('/\([^)]+\)/', '', $content, 1); - $content = str_replace('$openstack = new OpenCloud\OpenCloud;', $subst, $content); - - $tmp = tempnam(sys_get_temp_dir(), 'openstack'); - file_put_contents($tmp, $content); - - $this->paths[] = $tmp; - - return $tmp; - } -} diff --git a/server/vendor/php-opencloud/common/tests/integration/SampleManagerInterface.php b/server/vendor/php-opencloud/common/tests/integration/SampleManagerInterface.php deleted file mode 100644 index f0fe848..0000000 --- a/server/vendor/php-opencloud/common/tests/integration/SampleManagerInterface.php +++ /dev/null @@ -1,10 +0,0 @@ -<?php - -namespace OpenCloud\integration; - -interface SampleManagerInterface -{ - public function write($path, array $replacements); - - public function deletePaths(); -} diff --git a/server/vendor/php-opencloud/common/tests/integration/TestCase.php b/server/vendor/php-opencloud/common/tests/integration/TestCase.php deleted file mode 100644 index 687760a..0000000 --- a/server/vendor/php-opencloud/common/tests/integration/TestCase.php +++ /dev/null @@ -1,115 +0,0 @@ -<?php - -namespace OpenCloud\integration; - -use Psr\Log\LoggerInterface; - -abstract class TestCase extends \PHPUnit_Framework_TestCase implements TestInterface -{ - private $logger; - private $startPoint; - private $lastPoint; - private $sampleManager; - - public function __construct(LoggerInterface $logger, SampleManagerInterface $sampleManager) - { - $this->logger = $logger; - $this->sampleManager = $sampleManager; - } - - public function teardown() - { - $this->sampleManager->deletePaths(); - } - - public function runOneTest($name) - { - if (!method_exists($this, $name)) { - throw new \InvalidArgumentException(sprintf("%s method does not exist", $name)); - } - - $this->startTimer(); - $this->$name(); - $this->outputTimeTaken(); - } - - protected function startTimer() - { - $this->startPoint = $this->lastPoint = microtime(true); - } - - private function wrapColor($message, $colorPrefix) - { - return sprintf("%s%s", $colorPrefix, $message) . "\033[0m\033[1;0m"; - } - - protected function logStep($message, array $context = []) - { - $duration = microtime(true) - $this->lastPoint; - - $stepTimeTaken = sprintf('(%s)', $this->formatSecDifference($duration)); - - if ($duration >= 10) { - $color = "\033[0m\033[1;31m"; // red - } elseif ($duration >= 2) { - $color = "\033[0m\033[1;33m"; // yellow - } else { - $color = "\033[0m\033[1;32m"; // green - } - - $message = '{timeTaken} ' . $message; - $context['{timeTaken}'] = $this->wrapColor($stepTimeTaken, $color); - - $this->logger->info($message, $context); - - $this->lastPoint = microtime(true); - } - - protected function randomStr($length = 5) - { - $chars = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ'; - $charsLen = strlen($chars); - - $randomString = ''; - for ($i = 0; $i < $length; $i++) { - $randomString .= $chars[rand(0, $charsLen - 1)]; - } - - return 'phptest_' . $randomString; - } - - private function formatMinDifference($duration) - { - $output = ''; - - if (($minutes = floor($duration / 60)) > 0) { - $output .= $minutes . 'min' . (($minutes > 1) ? 's' : ''); - } - - if (($seconds = number_format(fmod($duration, 60), 2)) > 0) { - if ($minutes > 0) { - $output .= ' '; - } - $output .= $seconds . 's'; - } - - return $output; - } - - private function formatSecDifference($duration) - { - return number_format($duration, 2) . 's'; - } - - protected function outputTimeTaken() - { - $output = $this->formatMinDifference(microtime(true) - $this->startPoint); - - $this->logger->info('Finished all tests! Time taken: {output}.', ['{output}' => $output]); - } - - protected function sampleFile(array $replacements, $path) - { - return $this->sampleManager->write($path, $replacements); - } -} diff --git a/server/vendor/php-opencloud/common/tests/integration/TestInterface.php b/server/vendor/php-opencloud/common/tests/integration/TestInterface.php deleted file mode 100644 index a89e8af..0000000 --- a/server/vendor/php-opencloud/common/tests/integration/TestInterface.php +++ /dev/null @@ -1,16 +0,0 @@ -<?php - -namespace OpenCloud\integration; - -use Psr\Log\LoggerInterface; - -interface TestInterface -{ - public function __construct(LoggerInterface $logger, SampleManagerInterface $sampleManager); - - public function runTests(); - - public function runOneTest($name); - - public function teardown(); -} diff --git a/server/vendor/php-opencloud/common/tests/integration/Utils.php b/server/vendor/php-opencloud/common/tests/integration/Utils.php deleted file mode 100644 index daa1426..0000000 --- a/server/vendor/php-opencloud/common/tests/integration/Utils.php +++ /dev/null @@ -1,59 +0,0 @@ -<?php - -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)); - } -} diff --git a/server/vendor/php-opencloud/common/tests/integration/run.php b/server/vendor/php-opencloud/common/tests/integration/run.php deleted file mode 100644 index 5bc5548..0000000 --- a/server/vendor/php-opencloud/common/tests/integration/run.php +++ /dev/null @@ -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(); diff --git a/server/vendor/php-opencloud/common/tests/integration/script/compute_v2 b/server/vendor/php-opencloud/common/tests/integration/script/compute_v2 deleted file mode 100755 index 5e90b05..0000000 --- a/server/vendor/php-opencloud/common/tests/integration/script/compute_v2 +++ /dev/null @@ -1,3 +0,0 @@ -#!/bin/bash - -php tests/integration/Runner.php -s compute -v v2 diff --git a/server/vendor/php-opencloud/common/tests/integration/script/identity_v3 b/server/vendor/php-opencloud/common/tests/integration/script/identity_v3 deleted file mode 100755 index cd175b5..0000000 --- a/server/vendor/php-opencloud/common/tests/integration/script/identity_v3 +++ /dev/null @@ -1,3 +0,0 @@ -#!/bin/bash - -php tests/integration/Runner.php -s identity -v v3 diff --git a/server/vendor/php-opencloud/common/tests/integration/script/networking_v2 b/server/vendor/php-opencloud/common/tests/integration/script/networking_v2 deleted file mode 100755 index 9583f68..0000000 --- a/server/vendor/php-opencloud/common/tests/integration/script/networking_v2 +++ /dev/null @@ -1,3 +0,0 @@ -#!/bin/bash - -php tests/integration/Runner.php -s networking -v v2 diff --git a/server/vendor/php-opencloud/common/tests/integration/script/objectstore_v2 b/server/vendor/php-opencloud/common/tests/integration/script/objectstore_v2 deleted file mode 100755 index 3fb893a..0000000 --- a/server/vendor/php-opencloud/common/tests/integration/script/objectstore_v2 +++ /dev/null @@ -1,3 +0,0 @@ -#!/bin/bash - -php tests/integration/Runner.php -s objectstore -v v2 |
