29470d50b45a24f11fc31846a352e1e05a69e01e
[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         ];
38
39         $from = 'if (true) { 1; } elseif (true) { 2; } else { 3; }';
40         $to   = <<<'EOS'
41 if (true) {
42     return 1;
43 } elseif (true) {
44     return 2;
45 } else {
46     return 3;
47 }
48 return new \Psy\CodeCleaner\NoReturnValue();
49 EOS;
50         $data[] = [$from, $to];
51
52         $from = 'class A {}';
53         $to   = <<<'EOS'
54 class A
55 {
56 }
57 return new \Psy\CodeCleaner\NoReturnValue();
58 EOS;
59         $data[] = [$from, $to];
60
61         $from = <<<'EOS'
62 switch (false) {
63     case 0:
64         0;
65     case 1:
66         1;
67         break;
68     case 2:
69         2;
70         return;
71 }
72 EOS;
73         $to = <<<'EOS'
74 switch (false) {
75     case 0:
76         0;
77     case 1:
78         return 1;
79         break;
80     case 2:
81         2;
82         return;
83 }
84 return new \Psy\CodeCleaner\NoReturnValue();
85 EOS;
86         $data[] = [$from, $to];
87
88         $data[] = ['exit()', 'exit;'];
89
90         return $data;
91     }
92 }