Mercurial > hg > isophonics-drupal-site
comparison vendor/psy/psysh/test/Psy/Test/CodeCleaner/PassableByReferencePassTest.php @ 0:4c8ae668cc8c
Initial import (non-working)
author | Chris Cannam |
---|---|
date | Wed, 29 Nov 2017 16:09:58 +0000 |
parents | |
children | 7a779792577d |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:4c8ae668cc8c |
---|---|
1 <?php | |
2 | |
3 /* | |
4 * This file is part of Psy Shell. | |
5 * | |
6 * (c) 2012-2017 Justin Hileman | |
7 * | |
8 * For the full copyright and license information, please view the LICENSE | |
9 * file that was distributed with this source code. | |
10 */ | |
11 | |
12 namespace Psy\Test\CodeCleaner; | |
13 | |
14 use PhpParser\NodeTraverser; | |
15 use Psy\CodeCleaner\PassableByReferencePass; | |
16 | |
17 class PassableByReferencePassTest extends CodeCleanerTestCase | |
18 { | |
19 public function setUp() | |
20 { | |
21 $this->pass = new PassableByReferencePass(); | |
22 $this->traverser = new NodeTraverser(); | |
23 $this->traverser->addVisitor($this->pass); | |
24 } | |
25 | |
26 /** | |
27 * @dataProvider invalidStatements | |
28 * @expectedException \Psy\Exception\FatalErrorException | |
29 */ | |
30 public function testProcessStatementFails($code) | |
31 { | |
32 $stmts = $this->parse($code); | |
33 $this->traverser->traverse($stmts); | |
34 } | |
35 | |
36 public function invalidStatements() | |
37 { | |
38 return array( | |
39 array('array_pop(array())'), | |
40 array('array_pop(array($foo))'), | |
41 array('array_shift(array())'), | |
42 ); | |
43 } | |
44 | |
45 /** | |
46 * @dataProvider validStatements | |
47 */ | |
48 public function testProcessStatementPasses($code) | |
49 { | |
50 $stmts = $this->parse($code); | |
51 $this->traverser->traverse($stmts); | |
52 } | |
53 | |
54 public function validStatements() | |
55 { | |
56 return array( | |
57 array('array_pop(json_decode("[]"))'), | |
58 array('array_pop($foo)'), | |
59 array('array_pop($foo->bar)'), | |
60 array('array_pop($foo::baz)'), | |
61 array('array_pop(Foo::qux)'), | |
62 ); | |
63 } | |
64 | |
65 /** | |
66 * @dataProvider validArrayMultisort | |
67 */ | |
68 public function testArrayMultisort($code) | |
69 { | |
70 $stmts = $this->parse($code); | |
71 $this->traverser->traverse($stmts); | |
72 } | |
73 | |
74 public function validArrayMultisort() | |
75 { | |
76 return array( | |
77 array('array_multisort($a)'), | |
78 array('array_multisort($a, $b)'), | |
79 array('array_multisort($a, SORT_NATURAL, $b)'), | |
80 array('array_multisort($a, SORT_NATURAL | SORT_FLAG_CASE, $b)'), | |
81 array('array_multisort($a, SORT_ASC, SORT_NATURAL | SORT_FLAG_CASE, $b)'), | |
82 array('array_multisort($a, SORT_NATURAL | SORT_FLAG_CASE, SORT_ASC, $b)'), | |
83 array('array_multisort($a, $b, SORT_ASC, SORT_NATURAL | SORT_FLAG_CASE)'), | |
84 array('array_multisort($a, SORT_NATURAL | SORT_FLAG_CASE, $b, SORT_ASC, SORT_NATURAL | SORT_FLAG_CASE)'), | |
85 array('array_multisort($a, 1, $b)'), | |
86 array('array_multisort($a, 1 + 2, $b)'), | |
87 array('array_multisort($a, getMultisortFlags(), $b)'), | |
88 ); | |
89 } | |
90 | |
91 /** | |
92 * @dataProvider invalidArrayMultisort | |
93 * @expectedException \Psy\Exception\FatalErrorException | |
94 */ | |
95 public function testInvalidArrayMultisort($code) | |
96 { | |
97 $stmts = $this->parse($code); | |
98 $this->traverser->traverse($stmts); | |
99 } | |
100 | |
101 public function invalidArrayMultisort() | |
102 { | |
103 return array( | |
104 array('array_multisort(1)'), | |
105 array('array_multisort(array(1, 2, 3))'), | |
106 array('array_multisort($a, SORT_NATURAL, SORT_ASC, SORT_NATURAL, $b)'), | |
107 ); | |
108 } | |
109 } |