diff options
| author | EoleDev <EoleDev@outlook.fr> | 2016-04-14 16:28:25 +0200 |
|---|---|---|
| committer | EoleDev <EoleDev@outlook.fr> | 2016-04-14 16:28:25 +0200 |
| commit | 31d2d0c158ad4daa3dde7a905f3c2e312c194f2e (patch) | |
| tree | 43d761d2aec8265a22c0fdedcc365bacc10dc814 /server/vendor/php-opencloud/common/tests/integration | |
| parent | 27730911d8c9253a4f5aa90450c57cdeca9d5d26 (diff) | |
| parent | b348dbc2266a3e8070a3951fb0bd8c19b852ec47 (diff) | |
Merge branch 'compute'
Conflicts:
server/core/LibOverride/genTokenOptions.php
Diffstat (limited to 'server/vendor/php-opencloud/common/tests/integration')
11 files changed, 0 insertions, 404 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 100755 index d367600..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 100755 index b1003a2..0000000 --- a/server/vendor/php-opencloud/common/tests/integration/Runner.php +++ /dev/null @@ -1,114 +0,0 @@ -<?php - -namespace OpenCloud\Integration; - -class Runner -{ - private $basePath; - private $logger; - private $services = []; - private $namespace; - - public function __construct($basePath, $testNamespace) - { - $this->basePath = $basePath; - $this->namespace = $testNamespace; - - $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) - { - $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", $this->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 100755 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 100755 index c4293ba..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 100755 index cb81381..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 100755 index 418b407..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 100755 index d24c1bb..0000000 --- a/server/vendor/php-opencloud/common/tests/integration/Utils.php +++ /dev/null @@ -1,13 +0,0 @@ -<?php - -namespace OpenCloud\Integration; - -use GuzzleHttp\Client; - -class Utils -{ - public static function toCamelCase($word, $separator = '_') - { - return str_replace($separator, '', ucwords($word, $separator)); - } -} 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 |
