Chris@16: setPass(new ListPass()); Chris@16: } Chris@16: Chris@16: /** Chris@16: * @dataProvider invalidStatements Chris@16: * @expectedException \Psy\Exception\ParseErrorException Chris@16: */ Chris@16: public function testProcessInvalidStatement($code, $expectedMessage) Chris@16: { Chris@17: if (\method_exists($this, 'setExpectedException')) { Chris@16: $this->setExpectedException('Psy\Exception\ParseErrorException', $expectedMessage); Chris@16: } else { Chris@16: $this->expectExceptionMessage($expectedMessage); Chris@16: } Chris@16: Chris@16: $stmts = $this->parse($code); Chris@16: $this->traverser->traverse($stmts); Chris@16: } Chris@16: Chris@16: public function invalidStatements() Chris@16: { Chris@16: // Not typo. It is ambiguous whether "Syntax" or "syntax". Chris@16: $errorShortListAssign = "yntax error, unexpected '='"; Chris@16: $errorEmptyList = 'Cannot use empty list'; Chris@16: $errorAssocListAssign = 'Syntax error, unexpected T_CONSTANT_ENCAPSED_STRING, expecting \',\' or \')\''; Chris@16: $errorNonVariableAssign = 'Assignments can only happen to writable values'; Chris@16: $errorPhpParserSyntax = 'PHP Parse error: Syntax error, unexpected'; Chris@16: Chris@16: $invalidExpr = [ Chris@16: ['list() = array()', $errorEmptyList], Chris@16: ['list("a") = array(1)', $errorPhpParserSyntax], Chris@16: ]; Chris@16: Chris@17: if (\version_compare(PHP_VERSION, '7.1', '<')) { Chris@17: return \array_merge($invalidExpr, [ Chris@16: ['list("a" => _) = array("a" => 1)', $errorPhpParserSyntax], Chris@16: ['[] = []', $errorShortListAssign], Chris@16: ['[$a] = [1]', $errorShortListAssign], Chris@16: ['list("a" => $a) = array("a" => 1)', $errorAssocListAssign], Chris@17: ['[$a[0], $a[1]] = [1, 2]', $errorShortListAssign], Chris@17: ['[$a->b, $a->c] = [1, 2]', $errorShortListAssign], Chris@16: ]); Chris@16: } Chris@16: Chris@17: return \array_merge($invalidExpr, [ Chris@16: ['list("a" => _) = array("a" => 1)', $errorPhpParserSyntax], Chris@16: ['["a"] = [1]', $errorNonVariableAssign], Chris@16: ['[] = []', $errorEmptyList], Chris@16: ['[,] = [1,2]', $errorEmptyList], Chris@17: ['[,,] = [1,2,3]', $errorEmptyList], Chris@16: ]); Chris@16: } Chris@16: Chris@16: /** Chris@16: * @dataProvider validStatements Chris@16: */ Chris@16: public function testProcessValidStatement($code) Chris@16: { Chris@16: $stmts = $this->parse($code); Chris@16: $this->traverser->traverse($stmts); Chris@16: $this->assertTrue(true); Chris@16: } Chris@16: Chris@16: public function validStatements() Chris@16: { Chris@16: $validExpr = [ Chris@16: ['list($a) = array(1)'], Chris@16: ['list($x, $y) = array(1, 2)'], Chris@16: ]; Chris@16: Chris@17: if (\version_compare(PHP_VERSION, '7.1', '>=')) { Chris@17: return \array_merge($validExpr, [ Chris@16: ['[$a] = array(1)'], Chris@16: ['list($b) = [2]'], Chris@16: ['[$x, $y] = array(1, 2)'], Chris@16: ['[$a] = [1]'], Chris@16: ['[$x, $y] = [1, 2]'], Chris@16: ['["_" => $v] = ["_" => 1]'], Chris@16: ['[$a,] = [1,2,3]'], Chris@16: ['[,$b] = [1,2,3]'], Chris@16: ['[$a,,$c] = [1,2,3]'], Chris@16: ['[$a,,,] = [1,2,3]'], Chris@17: ['[$a[0], $a[1]] = [1, 2]'], Chris@17: ['[$a[0][0][0], $a[0][0][1]] = [1, 2]'], Chris@17: ['[$a->b, $a->c] = [1, 2]'], Chris@17: ['[$a->b[0], $a->c[1]] = [1, 2]'], Chris@17: ['[$a[0]->b[0], $a[0]->c[1]] = [1, 2]'], Chris@17: ['[$a[$b->c + $b->d]] = [1]'], Chris@17: ['[$a->c()->d, $a->c()->e] = [1, 2]'], Chris@17: ['[x()->a, x()->b] = [1, 2]'], Chris@16: ]); Chris@16: } Chris@16: Chris@16: return $validExpr; Chris@16: } Chris@16: }