public function testGroupsUsageInExternalFile() { $masterContent = <<<CONFFILE [externals] secured.conf [groups] qa = [staging] [variables] db.pass: staging = <external> default = fail CONFFILE; $securedContent = <<<CONFFILE [variables] db.pass: qa = success CONFFILE; $parser = new Parser(new Filesystem(new InMemory(array(self::MASTERFILE_PATH => $masterContent, 'secured.conf' => $securedContent)))); $parser->enableIncludeSupport()->enableExternalSupport()->enableGroupSupport(); $variables = $parser->parse(self::MASTERFILE_PATH); $reader = new Reader($variables, $parser->getExternalVariables(), $parser->getGroups()); $this->assertSame('success', $reader->read('db.pass', 'staging')); }
public function testGroups() { $masterContent = <<<CONFFILE [groups] # comment qa = [ staging, preprod ] dev = [ dev1, dev2,dev3] # comment production=[prod] [variables] db.pass: dev = 1234 qa = password prod = <external> db.user: dev1 = devuser1 dev2 = devuser2 dev3 = devuser3 qa = qauser db.cache: preprod = true default = false CONFFILE; $parser = new Parser(new Filesystem(new InMemory(array(self::MASTERFILE_PATH => $masterContent)))); $parser->enableIncludeSupport()->enableExternalSupport()->enableGroupSupport(); $variables = $parser->parse(self::MASTERFILE_PATH); $expected = array('db.pass' => array('dev' => 1234, 'qa' => 'password', 'prod' => '<external>'), 'db.user' => array('dev1' => 'devuser1', 'dev2' => 'devuser2', 'dev3' => 'devuser3', 'qa' => 'qauser'), 'db.cache' => array('preprod' => true, 'default' => false)); foreach ($expected as $variable => $info) { foreach ($info as $environment => $expectedValue) { $this->assertArrayHasKey($variable, $variables); $this->assertArrayHasKey('env', $variables[$variable]); $this->assertArrayHasKey($environment, $variables[$variable]['env']); $this->assertSame($expectedValue, $variables[$variable]['env'][$environment]); } } $groups = $parser->getGroups(); $expected = array('dev' => array('dev1', 'dev2', 'dev3'), 'qa' => array('staging', 'preprod'), 'production' => array('prod')); $this->assertSameArraysExceptOrder($expected, $groups); }