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\Sudo;
14 use PhpParser\NodeTraverser;
15 use Psy\Sudo\SudoVisitor;
16 use Psy\Test\ParserTestCase;
18 class SudoVisitorTest extends ParserTestCase
20 public function setUp()
22 $this->traverser = new NodeTraverser();
23 $this->traverser->addVisitor(new SudoVisitor());
27 * @dataProvider propertyFetches
29 public function testPropertyFetch($from, $to)
31 $this->assertProcessesAs($from, $to);
34 public function propertyFetches()
37 ['$a->b', "\Psy\Sudo::fetchProperty(\$a, 'b');"],
38 ['$a->$b', '\Psy\Sudo::fetchProperty($a, $b);'],
39 ["\$a->{'b'}", "\Psy\Sudo::fetchProperty(\$a, 'b');"],
44 * @dataProvider propertyAssigns
46 public function testPropertyAssign($from, $to)
48 $this->assertProcessesAs($from, $to);
51 public function propertyAssigns()
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);"],
61 * @dataProvider methodCalls
63 public function testMethodCall($from, $to)
65 $this->assertProcessesAs($from, $to);
68 public function methodCalls()
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');"],
79 * @dataProvider staticPropertyFetches
81 public function testStaticPropertyFetch($from, $to)
83 $this->assertProcessesAs($from, $to);
86 public function staticPropertyFetches()
89 ['A::$b', "\Psy\Sudo::fetchStaticProperty('A', 'b');"],
90 ['$a::$b', "\Psy\Sudo::fetchStaticProperty(\$a, 'b');"],
95 * @dataProvider staticPropertyAssigns
97 public function testStaticPropertyAssign($from, $to)
99 $this->assertProcessesAs($from, $to);
102 public function staticPropertyAssigns()
105 ['A::$b = $c', "\Psy\Sudo::assignStaticProperty('A', 'b', \$c);"],
106 ['$a::$b = $c', "\Psy\Sudo::assignStaticProperty(\$a, 'b', \$c);"],
111 * @dataProvider staticCalls
113 public function testStaticCall($from, $to)
115 $this->assertProcessesAs($from, $to);
118 public function staticCalls()
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');"],
129 * @dataProvider classConstFetches
131 public function testClassConstFetch($from, $to)
133 $this->assertProcessesAs($from, $to);
136 public function classConstFetches()
139 ['A::B', "\Psy\Sudo::fetchClassConst('A', 'B');"],