comparison vendor/psy/psysh/test/Psy/Test/CodeCleaner/AssignThisVariablePassTest.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\AssignThisVariablePass;
16
17 class AssignThisVariablePassTest extends CodeCleanerTestCase
18 {
19 public function setUp()
20 {
21 $this->pass = new AssignThisVariablePass();
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('$this = 3'),
40 array('strtolower($this = "this")'),
41 );
42 }
43
44 /**
45 * @dataProvider validStatements
46 */
47 public function testProcessStatementPasses($code)
48 {
49 $stmts = $this->parse($code);
50 $this->traverser->traverse($stmts);
51 }
52
53 public function validStatements()
54 {
55 return array(
56 array('$this'),
57 array('$a = $this'),
58 array('$a = "this"; $$a = 3'),
59 array('$$this = "b"'),
60 );
61 }
62 }