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);
58 // @todo a better thing to assert here?
59 $this->assertTrue(true);
62 public function validStatements()
65 array('get_class($foo)'),
66 array('get_class(bar())'),
67 array('get_called_class($foo)'),
68 array('get_called_class(bar())'),
69 array('function foo($bar) { return get_class($bar); }'),
70 array('function foo($bar) { return get_called_class($bar); }'),
71 array('class Foo { function bar() { return get_class(); } }'),
72 array('class Foo { function bar() { return get_class(null); } }'),
73 array('class Foo { function bar() { return get_called_class(); } }'),
74 array('class Foo { function bar() { return get_called_class(null); } }'),
75 array('$foo = function () {}; $foo()'),
80 * @dataProvider validTraitStatements
82 public function testProcessTraitStatementPasses($code)
84 if (version_compare(PHP_VERSION, '5.4', '<')) {
85 $this->markTestSkipped();
88 $stmts = $this->parse($code);
89 $this->traverser->traverse($stmts);
91 // @todo a better thing to assert here?
92 $this->assertTrue(true);
95 public function validTraitStatements()
98 array('trait Foo { function bar() { return get_class(); } }'),
99 array('trait Foo { function bar() { return get_class(null); } }'),
100 array('trait Foo { function bar() { return get_called_class(); } }'),
101 array('trait Foo { function bar() { return get_called_class(null); } }'),