/**
  * Tests if the merge of two datasources into the application server
  * configuration returns the expected configuration node structure.
  *
  * @return void
  */
 public function testMergeDatasourcesIntoAppserver()
 {
     $configurationOne = new Configuration();
     $configurationOne->initFromFile(__DIR__ . '/_files/META-INF/appserver-ds.xml');
     $configurationTwo = new Configuration();
     $configurationTwo->initFromFile(__DIR__ . '/_files/META-INF/appserver-01-ds.xml');
     $configurationOne->merge($configurationTwo);
     $this->configuration->initFromFile(__DIR__ . '/../../_files/appserver.xml');
     $this->configuration->addChild($configurationOne);
     $this->assertCount(2, $this->configuration->getChilds('/appserver/datasources/datasource'));
 }
Esempio n. 2
0
 /**
  * Appends the value of the passed reflection property to the
  * configuration under the also passed path.
  *
  * @param \ReflectionProperty                                          $reflectionProperty The reflection property
  * @param \AppserverIo\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);
         // if we can find it
     } elseif (!empty($token) && empty($next)) {
         // 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));
     }
 }