611fa30a7269910c53d253983cc0fa147e8c555d
[yaffs-website] / vendor / psy / psysh / test / Psy / Test / CodeCleaner / StaticConstructorPassTest.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 Psy\CodeCleaner\StaticConstructorPass;
15
16 class StaticConstructorPassTest extends CodeCleanerTestCase
17 {
18     protected function setUp()
19     {
20         $this->setPass(new StaticConstructorPass());
21     }
22
23     /**
24      * @dataProvider invalidStatements
25      * @expectedException \Psy\Exception\FatalErrorException
26      */
27     public function testProcessInvalidStatement($code)
28     {
29         $stmts = $this->parse($code);
30         $this->traverser->traverse($stmts);
31     }
32
33     /**
34      * @dataProvider invalidParserStatements
35      * @expectedException \Psy\Exception\ParseErrorException
36      */
37     public function testProcessInvalidStatementCatchedByParser($code)
38     {
39         $stmts = $this->parse($code);
40         $this->traverser->traverse($stmts);
41     }
42
43     public function invalidStatements()
44     {
45         $statements = array(
46             array('class A { public static function A() {}}'),
47             array('class A { private static function A() {}}'),
48         );
49
50         if (version_compare(PHP_VERSION, '5.3.3', '<')) {
51             $statements[] = array('namespace B; class A { private static function A() {}}');
52         }
53
54         return $statements;
55     }
56
57     public function invalidParserStatements()
58     {
59         $statements = array(
60             array('class A { public static function __construct() {}}'),
61             array('class A { private static function __construct() {}}'),
62             array('class A { private static function __construct() {} public function A() {}}'),
63             array('namespace B; class A { private static function __construct() {}}'),
64         );
65
66         return $statements;
67     }
68
69     /**
70      * @dataProvider validStatements
71      */
72     public function testProcessValidStatement($code)
73     {
74         $stmts = $this->parse($code);
75         $this->traverser->traverse($stmts);
76     }
77
78     public function validStatements()
79     {
80         $statements = array(
81             array('class A { public static function A() {} public function __construct() {}}'),
82             array('class A { private function __construct() {} public static function A() {}}'),
83         );
84
85         if (version_compare(PHP_VERSION, '5.3.3', '>=')) {
86             $statements[] = array('namespace B; class A { private static function A() {}}');
87         }
88
89         return $statements;
90     }
91 }