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\CalledClassPass;
17 class CalledClassPassTest extends CodeCleanerTestCase
19 public function setUp()
21 $this->pass = new CalledClassPass();
22 $this->traverser = new NodeTraverser();
23 $this->traverser->addVisitor($this->pass);
27 * @dataProvider invalidStatements
28 * @expectedException \Psy\Exception\ErrorException
30 public function testProcessStatementFails($code)
32 $stmts = $this->parse($code);
33 $this->traverser->traverse($stmts);
36 public function invalidStatements()
40 array('get_class(null)'),
41 array('get_called_class()'),
42 array('get_called_class(null)'),
43 array('function foo() { return get_class(); }'),
44 array('function foo() { return get_class(null); }'),
45 array('function foo() { return get_called_class(); }'),
46 array('function foo() { return get_called_class(null); }'),
51 * @dataProvider validStatements
53 public function testProcessStatementPasses($code)
55 $stmts = $this->parse($code);
56 $this->traverser->traverse($stmts);
59 public function validStatements()
62 array('get_class($foo)'),
63 array('get_class(bar())'),
64 array('get_called_class($foo)'),
65 array('get_called_class(bar())'),
66 array('function foo($bar) { return get_class($bar); }'),
67 array('function foo($bar) { return get_called_class($bar); }'),
68 array('class Foo { function bar() { return get_class(); } }'),
69 array('class Foo { function bar() { return get_class(null); } }'),
70 array('class Foo { function bar() { return get_called_class(); } }'),
71 array('class Foo { function bar() { return get_called_class(null); } }'),
72 array('$foo = function () {}; $foo()'),
77 * @dataProvider validTraitStatements
79 public function testProcessTraitStatementPasses($code)
81 if (version_compare(PHP_VERSION, '5.4', '<')) {
82 $this->markTestSkipped();
85 $stmts = $this->parse($code);
86 $this->traverser->traverse($stmts);
89 public function validTraitStatements()
92 array('trait Foo { function bar() { return get_class(); } }'),
93 array('trait Foo { function bar() { return get_class(null); } }'),
94 array('trait Foo { function bar() { return get_called_class(); } }'),
95 array('trait Foo { function bar() { return get_called_class(null); } }'),