/** * Creates a new child configuration node with the passed name and value * and adds it as child to this node. * * @param string $nodeName The child's node name * @param string $value The child's node value * * @return void */ public function addChildWithNameAndValue($nodeName, $value) { $node = new Configuration(); $node->setNodeName($nodeName); $node->setValue($value); $this->addChild($node); }
/** * Test the server's start method. * * @return void */ public function testStart() { // initialize the configuration $configuration = $this->getAppserverConfiguration(); // replace the base directory $appserverConfiguration = new Configuration(); $appserverConfiguration->setNodeName('appserver'); $baseDirectoryConfiguration = new Configuration(); $baseDirectoryConfiguration->setNodeName('baseDirectory'); $baseDirectoryConfiguration->setValue(__DIR__); $appserverConfiguration->addChild($baseDirectoryConfiguration); $configuration->merge($appserverConfiguration); // create a new mock server implementation $server = $this->getMock('TechDivision\\ApplicationServer\\Server', array('startContainers'), array($configuration)); // mock the servers start method $server->expects($this->once())->method('startContainers'); // start the server instance $server->start(); // check that we found the configured container $this->assertCount(1, $server->getContainers()); }
/** * Appends the value of the passed reflection property to the * configuration under the also passed path. * * @param \ReflectionProperty $reflectionProperty The reflection property * @param \TechDivision\Configuration\Interfaces\ConfigurationInterface $configuration The configuration instance * @param string $path A path were to append to * * @return void * @throws \Exception */ public function appendConfigurationChild(\ReflectionProperty $reflectionProperty, ConfigurationInterface $configuration, $path) { // tokenize the we want to append the configuration $token = strtok($path, '/'); $next = substr($path, strlen('/' . $token)); // if we can't find the specified path in that instance if (!empty($token) && !empty($next)) { // initialize the configuration value $child = new Configuration(); $child->setNodeName($token); // add it to this instance $this->appendConfigurationChild($reflectionProperty, $child, $next); // and also add it to the passed configuration $configuration->addChild($child); } elseif (!empty($token) && empty($next)) { // if we can find it // only add it the the passed configuration foreach ($this->{$reflectionProperty->getName()} as $node) { $configuration->addChild($node->exportToConfiguration()); } } else { // or throw an exception if the passed path is not valid throw new \Exception(sprintf('Found invalid path %s', $path)); } }