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\PassableByReferencePass;
17 class PassableByReferencePassTest extends CodeCleanerTestCase
19 public function setUp()
21 $this->pass = new PassableByReferencePass();
22 $this->traverser = new NodeTraverser();
23 $this->traverser->addVisitor($this->pass);
27 * @dataProvider invalidStatements
28 * @expectedException \Psy\Exception\FatalErrorException
30 public function testProcessStatementFails($code)
32 $stmts = $this->parse($code);
33 $this->traverser->traverse($stmts);
36 public function invalidStatements()
39 array('array_pop(array())'),
40 array('array_pop(array($foo))'),
41 array('array_shift(array())'),
46 * @dataProvider validStatements
48 public function testProcessStatementPasses($code)
50 $stmts = $this->parse($code);
51 $this->traverser->traverse($stmts);
53 // @todo a better thing to assert here?
54 $this->assertTrue(true);
57 public function validStatements()
60 array('array_pop(json_decode("[]"))'),
61 array('array_pop($foo)'),
62 array('array_pop($foo->bar)'),
63 array('array_pop($foo::baz)'),
64 array('array_pop(Foo::qux)'),
69 * @dataProvider validArrayMultisort
71 public function testArrayMultisort($code)
73 $stmts = $this->parse($code);
74 $this->traverser->traverse($stmts);
76 // @todo a better thing to assert here?
77 $this->assertTrue(true);
80 public function validArrayMultisort()
83 array('array_multisort($a)'),
84 array('array_multisort($a, $b)'),
85 array('array_multisort($a, SORT_NATURAL, $b)'),
86 array('array_multisort($a, SORT_NATURAL | SORT_FLAG_CASE, $b)'),
87 array('array_multisort($a, SORT_ASC, SORT_NATURAL | SORT_FLAG_CASE, $b)'),
88 array('array_multisort($a, SORT_NATURAL | SORT_FLAG_CASE, SORT_ASC, $b)'),
89 array('array_multisort($a, $b, SORT_ASC, SORT_NATURAL | SORT_FLAG_CASE)'),
90 array('array_multisort($a, SORT_NATURAL | SORT_FLAG_CASE, $b, SORT_ASC, SORT_NATURAL | SORT_FLAG_CASE)'),
91 array('array_multisort($a, 1, $b)'),
92 array('array_multisort($a, 1 + 2, $b)'),
93 array('array_multisort($a, getMultisortFlags(), $b)'),
98 * @dataProvider invalidArrayMultisort
99 * @expectedException \Psy\Exception\FatalErrorException
101 public function testInvalidArrayMultisort($code)
103 $stmts = $this->parse($code);
104 $this->traverser->traverse($stmts);
107 public function invalidArrayMultisort()
110 array('array_multisort(1)'),
111 array('array_multisort(array(1, 2, 3))'),
112 array('array_multisort($a, SORT_NATURAL, SORT_ASC, SORT_NATURAL, $b)'),