Skip to content
This repository has been archived by the owner on Sep 12, 2022. It is now read-only.

Commit

Permalink
#45 Add ExpandCslPort test
Browse files Browse the repository at this point in the history
  • Loading branch information
Julian Kleinhans committed Dec 14, 2016
1 parent 4ec2ef0 commit ef9fcc8
Show file tree
Hide file tree
Showing 2 changed files with 70 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/StackFormation/PreProcessor/Stage/Tree/ExpandCslPort.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@

use StackFormation\PreProcessor\Stage\AbstractTreePreProcessorStage;
use StackFormation\PreProcessor\Rootline;
use StackFormation\PreProcessor\RootlineItem;
use StackFormation\PreProcessor\RecursiveArrayObject;

class ExpandCslPort extends AbstractTreePreProcessorStage
{
Expand Down
68 changes: 68 additions & 0 deletions tests/StackFormation/PreProcessor/Stage/Tree/ExpandCslPortTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
<?php

namespace StackFormation\Tests\PreProcessor\Stage\Tree;

class ExpandCslPortTest extends \PHPUnit_Framework_TestCase
{
/**
* @test
*/
public function expandCslPort()
{
$granparentData = [
'granparent' => [
'IpProtocol' => 'tcp',
'Port' => '80,443',
'CidrIp' => '1.1.1.1/1'
]
];
$parentData = $granparentData['granparent'];

$parentRecursiveArrayObject = new \StackFormation\PreProcessor\RecursiveArrayObject($parentData, \ArrayObject::ARRAY_AS_PROPS);
$gradnparentRecursiveArrayObject = new \StackFormation\PreProcessor\RecursiveArrayObject($granparentData, \ArrayObject::ARRAY_AS_PROPS);

$parentRootlineItem = $this->getMockBuilder('\StackFormation\PreProcessor\RootlineItem')
->disableOriginalConstructor()
->setMethods(['getValue', 'getKey'])
->getMock();
$parentRootlineItem->method('getValue')->willReturn($parentRecursiveArrayObject);
$parentRootlineItem->method('getKey')->willReturn('granparent');

$grandParentRootlineItem = $this->getMockBuilder('\StackFormation\PreProcessor\RootlineItem')
->disableOriginalConstructor()
->setMethods(['getValue'])
->getMock();
$grandParentRootlineItem->method('getValue')->willReturn($gradnparentRecursiveArrayObject);

$rootline = $this->getMockBuilder('\StackFormation\PreProcessor\Rootline')
->setMethods(['parent'])
->getMock();
$rootline->expects($this->any())
->method('parent')
->with($this->logicalOr(
$this->equalTo(1),
$this->equalTo(2)
))
->will($this->returnCallback(
function($param) use ($parentRootlineItem, $grandParentRootlineItem) {
print_r($param);
if ($param == 1) return $parentRootlineItem;
if ($param == 2) return $grandParentRootlineItem;
}
));

$treePreProcessor = $this->getMock('\StackFormation\PreProcessor\TreePreProcessor', [], [], '', false);
$transformer = new \StackFormation\PreProcessor\Stage\Tree\ExpandCslPort($treePreProcessor);

$output = $transformer->invoke('/Resources/InstanceSecurityGroup/Properties/SecurityGroupIngress/1/Port', '80,443', $rootline);
$this->assertTrue($output);

$grandparentData = $rootline->parent(2)->getValue()->getArrayCopy();

$this->assertSame(2, count($grandparentData));
$this->assertSame('80', $grandparentData[0]['FromPort']);
$this->assertSame('80', $grandparentData[0]['ToPort']);
$this->assertSame('443', $grandparentData[1]['FromPort']);
$this->assertSame('443', $grandparentData[1]['ToPort']);
}
}

0 comments on commit ef9fcc8

Please sign in to comment.