comparison vendor/psy/psysh/test/Psy/Test/CodeCleaner/CalledClassPassTest.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\CalledClassPass;
16
17 class CalledClassPassTest extends CodeCleanerTestCase
18 {
19 public function setUp()
20 {
21 $this->pass = new CalledClassPass();
22 $this->traverser = new NodeTraverser();
23 $this->traverser->addVisitor($this->pass);
24 }
25
26 /**
27 * @dataProvider invalidStatements
28 * @expectedException \Psy\Exception\ErrorException
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('get_class()'),
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); }'),
47 );
48 }
49
50 /**
51 * @dataProvider validStatements
52 */
53 public function testProcessStatementPasses($code)
54 {
55 $stmts = $this->parse($code);
56 $this->traverser->traverse($stmts);
57 }
58
59 public function validStatements()
60 {
61 return array(
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()'),
73 );
74 }
75
76 /**
77 * @dataProvider validTraitStatements
78 */
79 public function testProcessTraitStatementPasses($code)
80 {
81 if (version_compare(PHP_VERSION, '5.4', '<')) {
82 $this->markTestSkipped();
83 }
84
85 $stmts = $this->parse($code);
86 $this->traverser->traverse($stmts);
87 }
88
89 public function validTraitStatements()
90 {
91 return array(
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); } }'),
96 );
97 }
98 }