e6a1bdfe67ac810e88e33c5ccdea0fa0ca102f6d
[yaffs-website] / vendor / psy / psysh / test / Psy / Test / CodeCleaner / ImplicitReturnPassTest.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\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         $values = array(
34             array('4',        'return 4;'),
35             array('foo()',    'return foo();'),
36             array('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         $values[] = array($from, $to);
51
52         $from = 'class A {}';
53         $to = <<<'EOS'
54 class A
55 {
56 }
57 return new \Psy\CodeCleaner\NoReturnValue();
58 EOS;
59         $values[] = array($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         $values[] = array($from, $to);
87
88         if (version_compare(PHP_VERSION, '5.4', '<')) {
89             $values[] = array('exit()', 'die;');
90         } else {
91             $values[] = array('exit()', 'exit;');
92         }
93
94         return $values;
95     }
96 }