Skip to content

Commit 030dffc

Browse files
committed
Unit tests for squizlabs#1203
1 parent 51fdc11 commit 030dffc

File tree

2 files changed

+36
-0
lines changed

2 files changed

+36
-0
lines changed

tests/Core/File/FindEndOfStatementTest.inc

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,3 +22,8 @@ switch ($a) {
2222
case 1: {break;}
2323
default: {break;}
2424
}
25+
26+
/* testStatementAsArrayValue */
27+
$a = [new Datetime];
28+
$a = array(new Datetime);
29+
$a = new Datetime;

tests/Core/File/FindEndOfStatementTest.php

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -169,4 +169,35 @@ public function testSwitch()
169169
}//end testSwitch()
170170

171171

172+
/**
173+
* Test statements that are array values.
174+
*
175+
* @return void
176+
*/
177+
public function testStatementAsArrayValue()
178+
{
179+
// Test short array syntax.
180+
$start = ($this->phpcsFile->findNext(T_COMMENT, 0, null, false, '/* testStatementAsArrayValue */') + 7);
181+
$found = $this->phpcsFile->findEndOfStatement($start);
182+
183+
$tokens = $this->phpcsFile->getTokens();
184+
$this->assertSame($tokens[($start + 2)], $tokens[$found]);
185+
186+
// Test long array syntax.
187+
$start += 12;
188+
$found = $this->phpcsFile->findEndOfStatement($start);
189+
190+
$tokens = $this->phpcsFile->getTokens();
191+
$this->assertSame($tokens[($start + 2)], $tokens[$found]);
192+
193+
// Test same statement outside of array.
194+
$start += 10;
195+
$found = $this->phpcsFile->findEndOfStatement($start);
196+
197+
$tokens = $this->phpcsFile->getTokens();
198+
$this->assertSame($tokens[($start + 3)], $tokens[$found]);
199+
200+
}//end testStatementAsArrayValue()
201+
202+
172203
}//end class

0 commit comments

Comments
 (0)