summaryrefslogtreecommitdiff
path: root/server/vendor/php-opencloud/common/tests/unit/Common/Api/ParameterTest.php
diff options
context:
space:
mode:
authorEoleDev <EoleDev@outlook.fr>2016-04-14 16:24:44 +0200
committerEoleDev <EoleDev@outlook.fr>2016-04-14 16:24:44 +0200
commit24bb5fefbdf93ce0969b7f56cc46c459ebb82a95 (patch)
tree531fc8b774c035040774234efba780a3d4fe9242 /server/vendor/php-opencloud/common/tests/unit/Common/Api/ParameterTest.php
parent646af6fd4d14c5b5edb1372e5f68ed9bdc35b3d2 (diff)
Mise a jour et nettoyage depot
Diffstat (limited to 'server/vendor/php-opencloud/common/tests/unit/Common/Api/ParameterTest.php')
-rw-r--r--server/vendor/php-opencloud/common/tests/unit/Common/Api/ParameterTest.php203
1 files changed, 0 insertions, 203 deletions
diff --git a/server/vendor/php-opencloud/common/tests/unit/Common/Api/ParameterTest.php b/server/vendor/php-opencloud/common/tests/unit/Common/Api/ParameterTest.php
deleted file mode 100644
index 65d4760..0000000
--- a/server/vendor/php-opencloud/common/tests/unit/Common/Api/ParameterTest.php
+++ /dev/null
@@ -1,203 +0,0 @@
-<?php
-
-namespace OpenCloud\Test\Common\Api;
-
-use OpenCloud\Common\Api\Parameter;
-use OpenCloud\Test\Fixtures\ComputeV2Api;
-
-class ParameterTest extends \PHPUnit_Framework_TestCase
-{
- const PARAMETER_CLASS = 'OpenCloud\Common\Api\Parameter';
-
- private $param;
- private $data;
- private $api;
-
- public function setUp()
- {
- $this->api = new ComputeV2Api();
-
- $this->data = $this->api->postServer()['params']['name'] + ['name' => 'name'];
- $this->param = new Parameter($this->data);
- }
-
- /**
- * @expectedException \RuntimeException
- */
- public function test_exception_is_thrown_for_invalid_locations()
- {
- $data = $this->data;
- $data['location'] = 'foo';
- new Parameter($data);
- }
-
- public function test_it_should_provide_access_to_a_name()
- {
- $this->assertEquals($this->data['name'], $this->param->getName());
- }
-
- public function test_it_should_use_sentAs_alias_for_name_if_one_is_set()
- {
- $data = $this->data + ['sentAs' => 'foo'];
- $param = new Parameter($data);
-
- $this->assertEquals($data['sentAs'], $param->getName());
- }
-
- public function test_it_indicates_whether_it_is_required_or_not()
- {
- $this->assertTrue($this->param->isRequired());
- }
-
- public function test_it_indicates_its_item_schema()
- {
- $data = $this->api->postServer()['params']['networks'] + ['name' => 'networks'];
- $param = new Parameter($data);
-
- $this->assertInstanceOf(self::PARAMETER_CLASS, $param->getItemSchema());
- }
-
- public function test_it_allows_property_retrieval()
- {
- $definition = $this->api->postServer()['params']['networks']['items'] + ['name' => 'network'];
- $param = new Parameter($definition);
-
- $this->assertInstanceOf(self::PARAMETER_CLASS, $param->getProperty('uuid'));
- }
-
- public function test_it_indicates_its_path()
- {
- $path = 'foo.bar.baz';
- $param = new Parameter($this->data + ['path' => $path]);
-
- $this->assertEquals($path, $param->getPath());
- }
-
- public function test_it_verifies_a_given_location_with_a_boolean()
- {
- $this->assertFalse($this->param->hasLocation('foo'));
- $this->assertTrue($this->param->hasLocation('json'));
- }
-
- public function test_it_should_return_true_when_required_attributes_are_provided_and_match_their_definitions()
- {
- $this->assertTrue($this->param->validate('TestName'));
- }
-
- /**
- * @expectedException \Exception
- */
- public function test_it_throws_exception_when_values_do_not_match_their_definition_types()
- {
- $data = $this->api->postServer()['params']['networks'] + ['name' => 'networks'];
- $param = new Parameter($data);
-
- $param->validate('a_network!'); // should be an array
- }
-
- /**
- * @expectedException \Exception
- */
- public function test_it_throws_exception_when_deeply_nested_values_have_wrong_types()
- {
- $data = $this->api->postServer()['params']['networks'] + ['name' => 'networks'];
-
- $param = new Parameter($data);
- $param->validate(['name' => false]); // value should be a string, not bool
- }
-
- public function test_metadata_properties_are_handled_differently()
- {
- $params = [
- 'name' => 'metadata',
- 'type' => 'object',
- 'properties' => [
- 'type' => 'string',
- ],
- ];
-
- $userValues = ['some' => 'value'];
-
- $param = new Parameter($params);
- $this->assertTrue($param->validate($userValues));
- }
-
- public function test_it_passes_validation_when_array_values_pass()
- {
- $params = [
- 'name' => 'foo',
- 'type' => 'array',
- 'items' => ['type' => 'string'],
- ];
-
- $userVals = ['1', '2', '3'];
-
- $param = new Parameter($params);
- $this->assertTrue($param->validate($userVals));
- }
-
- /**
- * @expectedException \Exception
- */
- public function test_an_exception_is_thrown_when_an_undefined_property_is_provided()
- {
- $params = ['type' => 'object', 'properties' => ['foo' => ['type' => 'string']]];
- $userVals = ['bar' => 'baz'];
-
- $param = new Parameter($params);
- $param->validate($userVals);
- }
-
- public function test_it_passes_validation_when_all_subproperties_pass()
- {
- $params = ['type' => 'object', 'properties' => ['foo' => ['type' => 'string']]];
- $userVals = ['foo' => 'baz'];
-
- $param = new Parameter($params);
- $this->assertTrue($param->validate($userVals));
- }
-
- public function test_it_sets_name()
- {
- $this->param->setName('foo');
- $this->assertEquals($this->param->getName(), 'foo');
- }
-
- public function test_it_gets_property()
- {
- $property = new Parameter([
- 'name' => 'metadata',
- 'properties' => [
- 'type' => 'string',
- 'prefix' => 'foo',
- ],
- ]);
-
- $prop = $property->getProperty('metadata');
-
- $this->assertInstanceOf(Parameter::class, $prop);
- $this->assertEquals('foo', $prop->getPrefix());
- }
-
- public function test_it_gets_prefixed_name()
- {
- $property = new Parameter([
- 'name' => 'metadata',
- 'prefix' => 'foo-',
- ]);
-
- $this->assertEquals('foo-metadata', $property->getPrefixedName());
- }
-
- /**
- * @expectedException \Exception
- */
- public function test_exception_is_thrown_when_value_is_not_in_enum_list()
- {
- $data = $this->data;
- $data['enum'] = ['foo'];
-
- $param = new Parameter($data);
- $param->validate('blah');
- }
-}