Chris@13
|
1 <?php
|
Chris@13
|
2
|
Chris@13
|
3 /*
|
Chris@13
|
4 * This file is part of Psy Shell.
|
Chris@13
|
5 *
|
Chris@13
|
6 * (c) 2012-2018 Justin Hileman
|
Chris@13
|
7 *
|
Chris@13
|
8 * For the full copyright and license information, please view the LICENSE
|
Chris@13
|
9 * file that was distributed with this source code.
|
Chris@13
|
10 */
|
Chris@13
|
11
|
Chris@13
|
12 namespace Psy\Test\CodeCleaner;
|
Chris@13
|
13
|
Chris@13
|
14 use Psy\CodeCleaner\UseStatementPass;
|
Chris@13
|
15
|
Chris@13
|
16 class UseStatementPassTest extends CodeCleanerTestCase
|
Chris@13
|
17 {
|
Chris@13
|
18 public function setUp()
|
Chris@13
|
19 {
|
Chris@13
|
20 $this->setPass(new UseStatementPass());
|
Chris@13
|
21 }
|
Chris@13
|
22
|
Chris@13
|
23 /**
|
Chris@13
|
24 * @dataProvider useStatements
|
Chris@13
|
25 */
|
Chris@13
|
26 public function testProcess($from, $to)
|
Chris@13
|
27 {
|
Chris@13
|
28 $this->assertProcessesAs($from, $to);
|
Chris@13
|
29 }
|
Chris@13
|
30
|
Chris@13
|
31 public function useStatements()
|
Chris@13
|
32 {
|
Chris@13
|
33 return [
|
Chris@13
|
34 [
|
Chris@13
|
35 "use StdClass as NotSoStd;\n\$std = new NotSoStd();",
|
Chris@13
|
36 '$std = new \\StdClass();',
|
Chris@13
|
37 ],
|
Chris@13
|
38 [
|
Chris@13
|
39 "namespace Foo;\n\nuse StdClass as S;\n\$std = new S();",
|
Chris@13
|
40 "namespace Foo;\n\n\$std = new \\StdClass();",
|
Chris@13
|
41 ],
|
Chris@13
|
42 [
|
Chris@13
|
43 "namespace Foo;\n\nuse \\StdClass as S;\n\$std = new S();",
|
Chris@13
|
44 "namespace Foo;\n\n\$std = new \\StdClass();",
|
Chris@13
|
45 ],
|
Chris@13
|
46 [
|
Chris@13
|
47 "use Foo\\Bar as fb;\n\$baz = new fb\\Baz();",
|
Chris@13
|
48 '$baz = new \\Foo\\Bar\\Baz();',
|
Chris@13
|
49 ],
|
Chris@13
|
50 [
|
Chris@13
|
51 "use Foo\\Bar;\n\$baz = new Bar\\Baz();",
|
Chris@13
|
52 '$baz = new \\Foo\\Bar\\Baz();',
|
Chris@13
|
53 ],
|
Chris@13
|
54 [
|
Chris@13
|
55 "namespace Foo;\nuse Bar;\n\$baz = new Bar\\Baz();",
|
Chris@13
|
56 "namespace Foo;\n\n\$baz = new \\Bar\\Baz();",
|
Chris@13
|
57 ],
|
Chris@16
|
58 [
|
Chris@16
|
59 "namespace Foo;\n\nuse \\StdClass as S;\n\$std = new S();\nnamespace Foo;\n\n\$std = new S();",
|
Chris@16
|
60 "namespace Foo;\n\n\$std = new \\StdClass();\nnamespace Foo;\n\n\$std = new \\StdClass();",
|
Chris@16
|
61 ],
|
Chris@16
|
62 [
|
Chris@16
|
63 "namespace Foo;\n\nuse \\StdClass as S;\n\$std = new S();\nnamespace Bar;\n\n\$std = new S();",
|
Chris@16
|
64 "namespace Foo;\n\n\$std = new \\StdClass();\nnamespace Bar;\n\n\$std = new S();",
|
Chris@16
|
65 ],
|
Chris@16
|
66 [
|
Chris@16
|
67 "use Foo\\Bar as fb, Qux as Q;\n\$baz = new fb\\Baz();\n\$qux = new Q();",
|
Chris@16
|
68 "\$baz = new \\Foo\\Bar\\Baz();\n\$qux = new \\Qux();",
|
Chris@16
|
69 ],
|
Chris@16
|
70 ];
|
Chris@16
|
71 }
|
Chris@16
|
72
|
Chris@16
|
73 /**
|
Chris@16
|
74 * @dataProvider groupUseStatements
|
Chris@16
|
75 */
|
Chris@16
|
76 public function testGroupUseProcess($from, $to)
|
Chris@16
|
77 {
|
Chris@16
|
78 $this->assertProcessesAs($from, $to);
|
Chris@16
|
79 }
|
Chris@16
|
80
|
Chris@16
|
81 public function groupUseStatements()
|
Chris@16
|
82 {
|
Chris@17
|
83 if (\version_compare(PHP_VERSION, '7.0', '<')) {
|
Chris@16
|
84 $this->markTestSkipped();
|
Chris@16
|
85 }
|
Chris@16
|
86
|
Chris@16
|
87 return [
|
Chris@16
|
88 [
|
Chris@16
|
89 "use Foo\\{Bar, Baz, Qux as Q};\n\$bar = new Bar();\n\$baz = new Baz();\n\$qux = new Q();",
|
Chris@16
|
90 "\$bar = new \\Foo\\Bar();\n\$baz = new \\Foo\\Baz();\n\$qux = new \\Foo\\Qux();",
|
Chris@16
|
91 ],
|
Chris@16
|
92 [
|
Chris@16
|
93 "use X\\{Foo, Bar as B};\n\$foo = new Foo();\n\$baz = new B\\Baz();",
|
Chris@16
|
94 "\$foo = new \\X\\Foo();\n\$baz = new \\X\\Bar\\Baz();",
|
Chris@16
|
95 ],
|
Chris@16
|
96 [
|
Chris@16
|
97 "use X\\{Foo, Bar as B};\n\$foo = new Foo();\n\$bar = new Bar();\n\$baz = new B\\Baz();",
|
Chris@16
|
98 "\$foo = new \\X\\Foo();\n\$bar = new Bar();\n\$baz = new \\X\\Bar\\Baz();",
|
Chris@16
|
99 ],
|
Chris@13
|
100 ];
|
Chris@13
|
101 }
|
Chris@13
|
102 }
|