More updates to stop using dev or alpha or beta versions.
[yaffs-website] / vendor / psy / psysh / test / Sudo / SudoVisitorTest.php
1 <?php
2
3 /*
4  * This file is part of Psy Shell.
5  *
6  * (c) 2012-2018 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\Sudo;
13
14 use PhpParser\NodeTraverser;
15 use Psy\Sudo\SudoVisitor;
16 use Psy\Test\ParserTestCase;
17
18 class SudoVisitorTest extends ParserTestCase
19 {
20     public function setUp()
21     {
22         $this->traverser = new NodeTraverser();
23         $this->traverser->addVisitor(new SudoVisitor());
24     }
25
26     /**
27      * @dataProvider propertyFetches
28      */
29     public function testPropertyFetch($from, $to)
30     {
31         $this->assertProcessesAs($from, $to);
32     }
33
34     public function propertyFetches()
35     {
36         return [
37             ['$a->b', "\Psy\Sudo::fetchProperty(\$a, 'b');"],
38             ['$a->$b', '\Psy\Sudo::fetchProperty($a, $b);'],
39             ["\$a->{'b'}", "\Psy\Sudo::fetchProperty(\$a, 'b');"],
40         ];
41     }
42
43     /**
44      * @dataProvider propertyAssigns
45      */
46     public function testPropertyAssign($from, $to)
47     {
48         $this->assertProcessesAs($from, $to);
49     }
50
51     public function propertyAssigns()
52     {
53         return [
54             ['$a->b = $c', "\Psy\Sudo::assignProperty(\$a, 'b', \$c);"],
55             ['$a->$b = $c', '\Psy\Sudo::assignProperty($a, $b, $c);'],
56             ["\$a->{'b'} = \$c", "\Psy\Sudo::assignProperty(\$a, 'b', \$c);"],
57         ];
58     }
59
60     /**
61      * @dataProvider methodCalls
62      */
63     public function testMethodCall($from, $to)
64     {
65         $this->assertProcessesAs($from, $to);
66     }
67
68     public function methodCalls()
69     {
70         return [
71             ['$a->b()', "\Psy\Sudo::callMethod(\$a, 'b');"],
72             ['$a->$b()', '\Psy\Sudo::callMethod($a, $b);'],
73             ["\$a->b(\$c, 'd')", "\Psy\Sudo::callMethod(\$a, 'b', \$c, 'd');"],
74             ["\$a->\$b(\$c, 'd')", "\Psy\Sudo::callMethod(\$a, \$b, \$c, 'd');"],
75         ];
76     }
77
78     /**
79      * @dataProvider staticPropertyFetches
80      */
81     public function testStaticPropertyFetch($from, $to)
82     {
83         $this->assertProcessesAs($from, $to);
84     }
85
86     public function staticPropertyFetches()
87     {
88         return [
89             ['A::$b', "\Psy\Sudo::fetchStaticProperty('A', 'b');"],
90             ['$a::$b', "\Psy\Sudo::fetchStaticProperty(\$a, 'b');"],
91         ];
92     }
93
94     /**
95      * @dataProvider staticPropertyAssigns
96      */
97     public function testStaticPropertyAssign($from, $to)
98     {
99         $this->assertProcessesAs($from, $to);
100     }
101
102     public function staticPropertyAssigns()
103     {
104         return [
105             ['A::$b = $c', "\Psy\Sudo::assignStaticProperty('A', 'b', \$c);"],
106             ['$a::$b = $c', "\Psy\Sudo::assignStaticProperty(\$a, 'b', \$c);"],
107         ];
108     }
109
110     /**
111      * @dataProvider staticCalls
112      */
113     public function testStaticCall($from, $to)
114     {
115         $this->assertProcessesAs($from, $to);
116     }
117
118     public function staticCalls()
119     {
120         return [
121             ['A::b()', "\Psy\Sudo::callStatic('A', 'b');"],
122             ['A::$b()', "\Psy\Sudo::callStatic('A', \$b);"],
123             ["A::b(\$c, 'd')", "\Psy\Sudo::callStatic('A', 'b', \$c, 'd');"],
124             ["A::\$b(\$c, 'd')", "\Psy\Sudo::callStatic('A', \$b, \$c, 'd');"],
125         ];
126     }
127
128     /**
129      * @dataProvider classConstFetches
130      */
131     public function testClassConstFetch($from, $to)
132     {
133         $this->assertProcessesAs($from, $to);
134     }
135
136     public function classConstFetches()
137     {
138         return [
139             ['A::B', "\Psy\Sudo::fetchClassConst('A', 'B');"],
140         ];
141     }
142 }