Esempio n. 1
0
 /**
  * Load configuration data from the source.
  * 
  * @param ConfigurationLoader $loader
  * @param array<string, mixed> $params
  * @return Configuration
  * 
  * @throws ConfigurationLoadingException
  */
 public function loadConfiguration(ConfigurationLoader $loader, array $params = [])
 {
     try {
         $data = $loader->findLoader($this->source)->load($this->source, $params);
         return new Configuration($this->createBase($data));
     } catch (\Exception $e) {
         throw new ConfigurationLoadingException(sprintf('Unable to load config from source "%s"', $this->source->getPathname()), 0, $e);
     }
 }
 /**
  * @test
  */
 public function it_loads_the_configuration_file()
 {
     // Mock Adviser\Utilities\FileUtility.
     $file = $this->mockUtility("File");
     $file->shouldReceive("exists")->once()->with(getcwd() . "/adviser.yml")->andReturn(true);
     $file->shouldReceive("read")->once()->with(ADVISER_DIR . "/adviser-default.yml")->andReturn(null);
     $file->shouldReceive("read")->once()->with(getcwd() . "/adviser.yml")->andReturn(null);
     // Mock Adviser\Utilities\YAMLParserUtility.
     $YAMLParser = $this->mockUtility("YAMLParser");
     $YAMLParser->shouldReceive("parse")->twice()->andReturn(["foo" => "bar", "qux" => 123], ["foo" => "baz"]);
     // Create a new instance of ConfigurationLoader.
     $loader = new ConfigurationLoader($file, $YAMLParser);
     $this->assertInternalType("array", $configuration = $loader->load(true));
     $this->assertEquals($configuration, ["foo" => ["bar", "baz"], "qux" => 123]);
 }