Updated from some -dev modules to alpha, beta or full releases
[yaffs-website] / vendor / psy / psysh / test / CodeCleaner / ImplicitReturnPassTest.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\ImplicitReturnPass;
15
16 class ImplicitReturnPassTest extends CodeCleanerTestCase
17 {
18     public function setUp()
19     {
20         $this->setPass(new ImplicitReturnPass());
21     }
22
23     /**
24      * @dataProvider implicitReturns
25      */
26     public function testProcess($from, $to)
27     {
28         $this->assertProcessesAs($from, $to);
29     }
30
31     public function implicitReturns()
32     {
33         $data = [
34             ['4',        'return 4;'],
35             ['foo()',    'return foo();'],
36             ['return 1', 'return 1;'],
37             ['',         'return new \Psy\CodeCleaner\NoReturnValue();'],
38         ];
39
40         $from = 'echo "foo";';
41         $to   = <<<'EOS'
42 echo "foo";
43 return new \Psy\CodeCleaner\NoReturnValue();
44 EOS;
45         $data[] = [$from, $to];
46
47         $from = 'if (true) { 1; } elseif (true) { 2; } else { 3; }';
48         $to   = <<<'EOS'
49 if (true) {
50     return 1;
51 } elseif (true) {
52     return 2;
53 } else {
54     return 3;
55 }
56 return new \Psy\CodeCleaner\NoReturnValue();
57 EOS;
58         $data[] = [$from, $to];
59
60         $from = 'class A {}';
61         $to   = <<<'EOS'
62 class A
63 {
64 }
65 return new \Psy\CodeCleaner\NoReturnValue();
66 EOS;
67         $data[] = [$from, $to];
68
69         $from = <<<'EOS'
70 switch (false) {
71     case 0:
72         0;
73     case 1:
74         1;
75         break;
76     case 2:
77         2;
78         return;
79 }
80 EOS;
81         $to = <<<'EOS'
82 switch (false) {
83     case 0:
84         0;
85     case 1:
86         return 1;
87         break;
88     case 2:
89         2;
90         return;
91 }
92 return new \Psy\CodeCleaner\NoReturnValue();
93 EOS;
94         $data[] = [$from, $to];
95
96         $from = <<<'EOS'
97 namespace Foo {
98     1 + 1;
99 }
100 EOS;
101         $to = <<<'EOS'
102 namespace Foo;
103
104 return 1 + 1;
105 EOS;
106         $data[] = [$from, $to];
107
108         $data[] = ['exit()', 'exit;'];
109
110         return $data;
111     }
112 }