flatten() public static method

public static flatten ( array $array, $keyKey = 'Key', $valueKey = 'Value' )
$array array
 /**
  * @test
  */
 public function getUnsresolvedParameter()
 {
     $blueprint = $this->getMockedBlueprint(['parameters' => ['Foo' => '{env:DONTRESOVLE}']]);
     $parameters = $blueprint->getParameters(false);
     $parameters = Div::flatten($parameters, 'ParameterKey', 'ParameterValue');
     $this->assertEquals('{env:DONTRESOVLE}', $parameters['Foo']);
 }
示例#2
0
 public function compare()
 {
     if (empty($this->stack)) {
         throw new \InvalidArgumentException('Stack not set');
     }
     if (empty($this->blueprint)) {
         throw new \InvalidArgumentException('Blueprint not set');
     }
     $tmp = [];
     try {
         // parameters
         if ($this->output->isVerbose()) {
             $this->output->writeln($this->stack->getName() . ': Comparing parameters');
         }
         $parametersStack = $this->stack->getParameters();
         $parametersBlueprint = $this->blueprint->getParameters(true);
         $parametersBlueprint = Div::flatten($parametersBlueprint, 'ParameterKey', 'ParameterValue');
         if ($this->parametersAreEqual($parametersStack, $parametersBlueprint)) {
             $tmp['parameters'] = "<fg=green>equal</>";
         } else {
             $tmp['parameters'] = "<fg=red>different</>";
             $tmp['error'] = true;
         }
         // template
         if ($this->output->isVerbose()) {
             $this->output->writeln($this->stack->getName() . ': Comparing template');
         }
         $templateStack = trim($this->stack->getTemplate());
         $templateBlueprint = trim($this->blueprint->getPreprocessedTemplate());
         $templateStack = $this->normalizeJson($templateStack);
         $templateBlueprint = $this->normalizeJson($templateBlueprint);
         if ($templateStack === $templateBlueprint) {
             $tmp['template'] = "<fg=green>equal</>";
         } else {
             $tmp['template'] = "<fg=red>different</>";
             $tmp['error'] = true;
         }
     } catch (CloudFormationException $e) {
         $tmp['parameters'] = 'Stack not found';
         $tmp['template'] = 'Stack not found';
         $tmp['error'] = true;
     } catch (\Exception $e) {
         $tmp['parameters'] = '<fg=red>EXCEPTION: ' . $e->getMessage() . '</>';
         $tmp['template'] = 'EXCEPTION';
         $tmp['error'] = true;
     }
     return $tmp;
 }
示例#3
0
 /**
  * Get outputs
  *
  * @return array
  */
 public function getOutputs()
 {
     if (!isset($this->data['Outputs'])) {
         return [];
     }
     return Div::flatten($this->data['Outputs'], 'OutputKey', 'OutputValue');
 }
 /**
  * @test
  */
 public function testSwitchProfileComplex()
 {
     putenv('ACCOUNT=t');
     putenv('BASE_TYPE_VERSION=42');
     $profileManagerMock = $this->getMock('\\StackFormation\\Profile\\Manager', [], [], '', false);
     $profileManagerMock->method('getStackFactory')->willReturnCallback(function () {
         $stackFactoryMock = $this->getMock('\\StackFormation\\StackFactory', ['getStackOutput'], [], '', false);
         $stackFactoryMock->method('getStackOutput')->willReturnCallback(function ($stackName, $key) {
             return "DummyValue|{$stackName}|{$key}";
         });
         return $stackFactoryMock;
     });
     $config = new \StackFormation\Config([FIXTURE_ROOT . 'Config/blueprint.switch_profile.yml']);
     $valueResolver = new \StackFormation\ValueResolver\ValueResolver(null, $profileManagerMock, $config);
     $blueprintFactory = new \StackFormation\BlueprintFactory($config, $valueResolver);
     $blueprint = $blueprintFactory->getBlueprint('switch_profile_complex');
     $parameters = $blueprint->getParameters(true);
     $parameters = Div::flatten($parameters, 'ParameterKey', 'ParameterValue');
     $this->assertEquals('DummyValue|ecom-t-all-ami-types-42-stack|VarnishAmi', $parameters['VarnishAmi']);
 }