4 * This file is part of Psy Shell.
6 * (c) 2012-2017 Justin Hileman
8 * For the full copyright and license information, please view the LICENSE
9 * file that was distributed with this source code.
12 namespace Psy\Test\CodeCleaner;
14 use PhpParser\NodeTraverser;
15 use Psy\CodeCleaner\FunctionReturnInWriteContextPass;
16 use Psy\Exception\FatalErrorException;
18 class FunctionReturnInWriteContextPassTest extends CodeCleanerTestCase
20 public function setUp()
22 $this->pass = new FunctionReturnInWriteContextPass();
23 $this->traverser = new NodeTraverser();
24 $this->traverser->addVisitor($this->pass);
28 * @dataProvider invalidStatements
29 * @expectedException \Psy\Exception\FatalErrorException
30 * @expectedExceptionMessage Can't use function return value in write context
32 public function testProcessStatementFails($code)
34 $stmts = $this->parse($code);
35 $this->traverser->traverse($stmts);
38 public function invalidStatements()
42 array('array(& $object->method())'),
43 array('$a->method(& $closure())'),
44 array('array(& A::b())'),
49 public function testIsset()
52 $this->traverser->traverse($this->parse('isset(strtolower("A"))'));
54 } catch (FatalErrorException $e) {
55 if (version_compare(PHP_VERSION, '5.5', '>=')) {
56 $this->assertContains(
57 'Cannot use isset() on the result of a function call (you can use "null !== func()" instead)',
61 $this->assertContains("Can't use function return value in write context", $e->getMessage());
67 * @expectedException \Psy\Exception\FatalErrorException
68 * @expectedExceptionMessage Can't use function return value in write context
70 public function testEmpty()
72 if (version_compare(PHP_VERSION, '5.5', '>=')) {
73 $this->markTestSkipped();
76 $this->traverser->traverse($this->parse('empty(strtolower("A"))'));