4 * This file is part of Psy Shell.
6 * (c) 2012-2018 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 Psy\CodeCleaner\FunctionReturnInWriteContextPass;
15 use Psy\Exception\FatalErrorException;
17 class FunctionReturnInWriteContextPassTest extends CodeCleanerTestCase
19 public function setUp()
21 $this->setPass(new FunctionReturnInWriteContextPass());
25 * @dataProvider invalidStatements
26 * @expectedException \Psy\Exception\FatalErrorException
27 * @expectedExceptionMessage Can't use function return value in write context
29 public function testProcessStatementFails($code)
31 $this->parseAndTraverse($code);
34 public function invalidStatements()
38 ['array(& $object->method())'],
39 ['$a->method(& $closure())'],
46 public function testIsset()
49 $this->traverser->traverse($this->parse('isset(strtolower("A"))'));
51 } catch (FatalErrorException $e) {
52 if (version_compare(PHP_VERSION, '5.5', '>=')) {
53 $this->assertContains(
54 'Cannot use isset() on the result of a function call (you can use "null !== func()" instead)',
58 $this->assertContains("Can't use function return value in write context", $e->getMessage());
64 * @expectedException \Psy\Exception\FatalErrorException
65 * @expectedExceptionMessage Can't use function return value in write context
67 public function testEmpty()
69 if (version_compare(PHP_VERSION, '5.5', '>=')) {
70 $this->markTestSkipped();
73 $this->traverser->traverse($this->parse('empty(strtolower("A"))'));
77 * @dataProvider validStatements
79 public function testValidStatements($code)
81 $this->parseAndTraverse($code);
82 $this->assertTrue(true);
85 public function validStatements()