/** * cloud_pricing service test * * @test */ public function testCloudPricing() { $task = new CloudPricing(); $config = $task->config(); $databag = 'scalr.crontab.services.cloud_pricing'; $expected = $this->config->defined($databag) ? (object) $this->config->get($databag) : null; if (isset($config->cronExpression)) { //This option is added runtime $this->assertInstanceOf('Scalr\\Util\\Cron\\CronExpression', $config->cronExpression); unset($config->cronExpression); } $this->assertEquals($expected, $config); }
/** * @return array * @throws \Scalr\System\Config\Exception\YamlException */ protected function getDataFixtures() { $fixtures = $this->getFixturesDirectory() . '/Api/V2'; $paths = []; foreach (new DirectoryIterator($fixtures) as $fileInfo) { if ($fileInfo->isFile()) { $pathInfo = Yaml::load($fileInfo->getPathname()); $paths[$fileInfo->getBasename('.yaml')] = $this->resolvePathInfo($pathInfo->get('paths')); } } return $paths; }
/** * SpecManager constructor. * * @param string $version Api version * @param string $service spec file service * @throws FileNotFoundException */ public function __construct($version, $service) { if (!(preg_match("/^" . Describer::VERSION_NAME_REGEXP . "\$/", $version) && preg_match("/^" . Describer::SERVICE_NAME_REGEXP . "\$/", $service))) { throw new FileNotFoundException("{$service}.{$version}"); } $file = "{$version}/{$service}-autogenerated.yaml"; $this->specFile = realpath(APPPATH . "/../api/{$file}"); if (!$this->specFile) { throw new FileNotFoundException("{$service}.{$version}", "Api {$version} specification not found for service '{$service}'"); } $this->definition = Yaml::load($this->specFile)->toArray(); }
/** * @test */ public function testLoad() { $config = Yaml::load($this->getFixture('test-config.yml')); $this->assertInstanceOf(self::CONFIG_CLASS, $config); $this->assertInternalType('array', $config->toArray()); $this->assertEquals($config->toArray(), json_decode($config->toJson(), true)); $this->assertNotEmpty($config->getModified()); $this->assertNotEmpty($config->getPath()); $this->assertNotEmpty($config->getImports()); $serialized = serialize($config); $unserialized = unserialize($serialized); $this->assertEquals($config, $unserialized); $this->assertEquals($config->getModified(), $unserialized->getModified()); $this->assertEquals($config->getPath(), $unserialized->getPath()); unset($serialized); unset($unserialized); $this->assertInternalType('array', $config->get('scalr')); $this->assertInternalType('array', $config['scalr']); $this->assertEquals($config['scalr'], $config->get('scalr')); $imports = $config->getImports(); $this->assertInternalType('array', $imports); $this->assertNotEmpty($imports); foreach (array('test-parameters.ini', 'Subpath/child.yml', 'Subpath/to-override.yml') as $fxt) { $path = realpath($this->getFixture($fxt)); $this->assertContains($path, array_keys($imports)); //Checks modification time of the imported document $this->assertNotEmpty($imports[$path]); } $this->assertEquals(3, count($imports)); $this->assertEquals(false, $config('scalr.auditlog.enabled')); $this->assertEquals('scalr', $config('scalr.auditlog.mysql.name')); $this->assertEquals('localhost', $config->get('scalr.auditlog.mysql.host')); $this->assertEquals('', $config->get('scalr.auditlog.mysql.port')); $this->assertEquals('mysql', $config->get('scalr.auditlog.mysql.driver')); $this->assertEquals('scalruser', $config->get('scalr.auditlog.mysql.user')); $this->assertEquals('scalrpassword', $config->get('scalr.auditlog.mysql.pass')); $this->assertEquals('scalr', $config->get('scalr.connections.mysql.name')); $this->assertEquals('localhost', $config->get('scalr.connections.mysql.host')); $this->assertEquals('', $config->get('scalr.connections.mysql.port')); $this->assertEquals('mysqli', $config->get('scalr.connections.mysql.driver')); $this->assertEquals('scalruser', $config->get('scalr.connections.mysql.user')); $this->assertEquals('scalrpassword', $config->get('scalr.connections.mysql.pass')); $this->assertEquals(true, $config->get('scalr.phpunit.skip_functional_tests')); $this->assertEquals(100001, $config->get('scalr.phpunit.test_userid')); $this->assertEquals(200002, $config->get('scalr.phpunit.test_envid')); $this->assertEquals("this is\nmultiline\nstring\n", $config->get('scalr.inherit.multiline')); $this->assertEquals("foo-value", $config->get('scalr.inherit.foo')); $this->assertEquals("genius", $config->get('scalr.inherit.ado')); $this->assertEquals("f7eba2160a5f8ab30e8299502d04d38a", md5($config->get('scalr.inherit.longstring'))); $this->assertEquals("foo-value", $config->get('parameters.foo')); $this->assertEquals("en_US", $config->get('parameters.locale')); }
/** * Describes api spec * * @param \Scalr_UI_Response $response Response object */ public function describe(\Scalr_UI_Response $response) { $cacheChanged = is_readable($this->cacheFile) ? filemtime($this->cacheFile) : null; $specChanged = filemtime($this->specFile); $configChanged = filemtime($this->config->getPath()); if ($cacheChanged < $configChanged || $cacheChanged < $specChanged) { $this->spec = yaml_parse_file($this->specFile); foreach ($this->mutators as $mutator) { $mutator->apply($this->config, $this->version); } $data = yaml_emit($this->spec, YAML_UTF8_ENCODING); if (!file_put_contents($this->cacheFile, $data)) { $response->sendFile($this->specFile, ['Content-Type' => 'text/plain;charset=utf-8'], null, $data); return; } } $response->sendFile($this->cacheFile, ['Content-Type' => 'text/plain;charset=utf-8']); }
/** * Data provider for testIsImposedRestriction() * * @return array */ protected function providerIsImposedRestriction() { $me = $this; $this->data = array(); $list = Yaml::load($this->getFixturesDirectory() . '/' . self::TEST_DATA_FILE); $testUserId = $this->getUser()->getId(); $testEnvironmentId = $this->getEnvironment()->id; foreach ($list->get(null) as $resource => $d) { if (!$d) { continue; } if (array_key_exists('self', $d)) { foreach ($d as $perm => $arrayUri) { if (!$arrayUri || $perm == 'self') { continue; } array_walk($arrayUri, array($this, 'cb'), array($resource, $perm)); } $d = $d['self']; } if (is_array($d)) { array_walk($d, array($this, 'cb'), array($resource, null)); } } return $this->data; }
/** * Generate data for ApiTestCaseV2 * * @param string $fixtures patch to fixtures directory * @return array * @throws \Scalr\System\Config\Exception\YamlException */ public static function dataFixtures($fixtures) { // set config static::$testUserId = \Scalr::config('scalr.phpunit.userid'); static::$user = User::findPk(static::$testUserId); static::$testEnvId = \Scalr::config('scalr.phpunit.envid'); static::$env = Environment::findPk(static::$testEnvId); $data = []; foreach (new DirectoryIterator($fixtures) as $fileInfo) { if ($fileInfo->isFile()) { $class = __NAMESPACE__ . '\\' . ucfirst($fileInfo->getBasename('.yaml')); if (class_exists($class)) { /* @var $object TestDataFixtures */ $object = new $class(Yaml::load($fileInfo->getPathname())->toArray()); $object->prepareTestData(); $data = array_merge($data, $object->preparePathInfo()); } } } return $data; }
/** * Generate data for ApiTest * * @param string $fixtures patch to fixtures directory * @param string $type api specifications type * @return array * @throws \Scalr\System\Config\Exception\YamlException */ public static function loadData($fixtures, $type) { // set config static::$testUserId = \Scalr::config('scalr.phpunit.apiv2.userid'); static::$user = User::findPk(static::$testUserId); static::$testEnvId = \Scalr::config('scalr.phpunit.apiv2.envid'); static::$env = Environment::findPk(static::$testEnvId); $data = []; foreach (new ApiFixtureIterator(new DirectoryIterator($fixtures), $type) as $fileInfo) { $class = __NAMESPACE__ . '\\' . ucfirst($fileInfo->getBasename('.yaml')); try { /* @var $object ApiFixture */ $object = new $class(Yaml::load($fileInfo->getPathname())->toArray(), $type); $object->prepareTestData(); $pathInfo = $object->preparePathInfo(); } catch (Exception $e) { $pathInfo = [array_merge([$class, $e, null, null, null], static::$defaultOperation)]; } $data = array_merge($data, $pathInfo); } return $data; }