Security update for Core, with self-updated composer
[yaffs-website] / vendor / psy / psysh / test / Psy / Test / CodeCleaner / CalledClassPassTest.php
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         // @todo a better thing to assert here?
59         $this->assertTrue(true);
60     }
61
62     public function validStatements()
63     {
64         return array(
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()'),
76         );
77     }
78
79     /**
80      * @dataProvider validTraitStatements
81      */
82     public function testProcessTraitStatementPasses($code)
83     {
84         if (version_compare(PHP_VERSION, '5.4', '<')) {
85             $this->markTestSkipped();
86         }
87
88         $stmts = $this->parse($code);
89         $this->traverser->traverse($stmts);
90
91         // @todo a better thing to assert here?
92         $this->assertTrue(true);
93     }
94
95     public function validTraitStatements()
96     {
97         return array(
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); } }'),
102         );
103     }
104 }