public function testAccessors() { $node = new Node(); $node->setName("test_node_name"); $this->assertEquals("test_node_name", $node->getName()); $this->assertEquals("test_node_name", $node->getHostOrDefault()); $node->setHost("test.node.exsample.com"); $this->assertEquals("test.node.exsample.com", $node->getHost()); $this->assertEquals("test.node.exsample.com", $node->getHostOrDefault()); $this->assertEquals(22, $node->getPortOrDefault()); $node->setPort(2022); $this->assertEquals(2022, $node->getPort()); $this->assertEquals(2022, $node->getPortOrDefault()); $node->setDefaultKey("/path/to/default/private_key"); $this->assertEquals("/path/to/default/private_key", $node->getDefaultKey()); $this->assertEquals("/path/to/default/private_key", $node->getKeyOrDefault()); $node->setKey("/path/to/private_key"); $this->assertEquals("/path/to/private_key", $node->getKey()); $this->assertEquals("/path/to/private_key", $node->getKeyOrDefault()); $node->setDefaultUsername("default_ssh_connection_user"); $this->assertEquals("default_ssh_connection_user", $node->getDefaultUsername()); $this->assertEquals("default_ssh_connection_user", $node->getUsernameOrDefault()); $node->setUsername("ssh_connection_user"); $this->assertEquals("ssh_connection_user", $node->getUsername()); $this->assertEquals("ssh_connection_user", $node->getUsernameOrDefault()); try { $node->setOptions("aaa"); $this->assertEquals(fales, true); } catch (\RuntimeException $e) { $this->assertEquals(true, true); } }
/** * Set node */ public function node() { $args = func_get_args(); if (count($args) < 1) { throw new \RuntimeException("Missing argument. Must 1 arguments at minimum."); } $node = new Node(); if (count($args) === 1) { // When it's passed 1 argument, register node with name only. $node->setName($args[0]); } elseif (count($args) === 2) { // When it's passed 2 arguments, register node with roles and some options. $node->setName($args[0]); if (is_string($args[1]) || Arr::isVector($args[1])) { $node->setReferenceRoles($args[1]); } else { if (isset($args[1]['roles'])) { $node->setReferenceRoles($args[1]['roles']); unset($args[1]['roles']); } $node->setOptions($args[1]); } } else { // When it's passed more than 3 arguments, register node with roles and some options. $node->setName($args[0]); $node->setOptions($args[1]); $node->setReferenceRoles($args[2]); } $this->container->set("nodes/" . $node->getName(), $node); $roles = $node->getReferenceRoles(); if ($roles) { if (is_string($roles)) { $this->role($roles, $node->getName()); } else { if (is_array($roles)) { foreach ($roles as $role) { $this->role($role, $node->getName()); } } } } return $node; }