More updates to stop using dev or alpha or beta versions.
[yaffs-website] / vendor / psy / psysh / test / CodeCleaner / CalledClassPassTest.php
1 <?php
2
3 /*
4  * This file is part of Psy Shell.
5  *
6  * (c) 2012-2018 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 Psy\CodeCleaner\CalledClassPass;
15
16 class CalledClassPassTest extends CodeCleanerTestCase
17 {
18     public function setUp()
19     {
20         $this->setPass(new CalledClassPass());
21     }
22
23     /**
24      * @dataProvider invalidStatements
25      * @expectedException \Psy\Exception\ErrorException
26      */
27     public function testProcessStatementFails($code)
28     {
29         $this->parseAndTraverse($code);
30     }
31
32     public function invalidStatements()
33     {
34         return [
35             ['get_class()'],
36             ['get_class(null)'],
37             ['get_called_class()'],
38             ['get_called_class(null)'],
39             ['function foo() { return get_class(); }'],
40             ['function foo() { return get_class(null); }'],
41             ['function foo() { return get_called_class(); }'],
42             ['function foo() { return get_called_class(null); }'],
43         ];
44     }
45
46     /**
47      * @dataProvider validStatements
48      */
49     public function testProcessStatementPasses($code)
50     {
51         $this->parseAndTraverse($code);
52         $this->assertTrue(true);
53     }
54
55     public function validStatements()
56     {
57         return [
58             ['get_class($foo)'],
59             ['get_class(bar())'],
60             ['get_called_class($foo)'],
61             ['get_called_class(bar())'],
62             ['function foo($bar) { return get_class($bar); }'],
63             ['function foo($bar) { return get_called_class($bar); }'],
64             ['class Foo { function bar() { return get_class(); } }'],
65             ['class Foo { function bar() { return get_class(null); } }'],
66             ['class Foo { function bar() { return get_called_class(); } }'],
67             ['class Foo { function bar() { return get_called_class(null); } }'],
68             ['$foo = function () {}; $foo()'],
69         ];
70     }
71
72     /**
73      * @dataProvider validTraitStatements
74      */
75     public function testProcessTraitStatementPasses($code)
76     {
77         $this->parseAndTraverse($code);
78         $this->assertTrue(true);
79     }
80
81     public function validTraitStatements()
82     {
83         return [
84             ['trait Foo { function bar() { return get_class(); } }'],
85             ['trait Foo { function bar() { return get_class(null); } }'],
86             ['trait Foo { function bar() { return get_called_class(); } }'],
87             ['trait Foo { function bar() { return get_called_class(null); } }'],
88         ];
89     }
90 }