Skip to content

Commit

Permalink
Fix variable indeces for array globals
Browse files Browse the repository at this point in the history
  • Loading branch information
nohponex committed Feb 10, 2016
1 parent 3a3f30f commit cc75783
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/Expression.php
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ class Expression
/**
* Regular expression pattern of array indices
*/
const PATTERN_ARRAY_INDEX = '[1-9]*[0-9]';
const PATTERN_ARRAY_INDEX = '[a-zA-Z][a-zA-Z0-9\-_]{1,}|[1-9]*[0-9]'; //[1-9]*[0-9]

/**
* Get prefix and suffix
Expand Down
39 changes: 39 additions & 0 deletions tests/src/GlobalsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,45 @@ public function testGetVariableAsArgument2()
$this->assertSame($echoVariable, $return);
}

/**
* @depends testSetArray
* @covers Phramework\Testphase\Globals::get
*/
public function testGetVariableAsIndex($array)
{
$variableIndex = '1';

Globals::set('variableIndex', $variableIndex);

$return = Globals::get(sprintf(
'array[%s]',
'variableIndex'
));

$this->assertSame($array[$variableIndex], $return);

//literal integer
$return = Globals::get(sprintf(
'array[%s]',
2
));

$this->assertSame($array[2], $return);
}

/**
* @covers Phramework\Testphase\Globals::get
* @expectedException \Exception
*/
public function testGetVariableAsIndexFailure()
{
//literal
$return = Globals::get(sprintf(
'array["%s"]',
2
));
}

/**
* @depends testSetArray
* @params int[] $array
Expand Down

0 comments on commit cc75783

Please sign in to comment.