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\ExitPass;
|
Chris@13
|
15
|
Chris@13
|
16 class ExitPassTest extends CodeCleanerTestCase
|
Chris@13
|
17 {
|
Chris@13
|
18 /**
|
Chris@13
|
19 * @var string
|
Chris@13
|
20 */
|
Chris@13
|
21 private $expectedExceptionString = '\\Psy\\Exception\\BreakException::exitShell()';
|
Chris@13
|
22
|
Chris@13
|
23 public function setUp()
|
Chris@13
|
24 {
|
Chris@13
|
25 $this->setPass(new ExitPass());
|
Chris@13
|
26 }
|
Chris@13
|
27
|
Chris@13
|
28 /**
|
Chris@13
|
29 * @dataProvider dataProviderExitStatement
|
Chris@13
|
30 */
|
Chris@13
|
31 public function testExitStatement($from, $to)
|
Chris@13
|
32 {
|
Chris@13
|
33 $this->assertProcessesAs($from, $to);
|
Chris@13
|
34 }
|
Chris@13
|
35
|
Chris@13
|
36 /**
|
Chris@13
|
37 * Data provider for testExitStatement.
|
Chris@13
|
38 *
|
Chris@13
|
39 * @return array
|
Chris@13
|
40 */
|
Chris@13
|
41 public function dataProviderExitStatement()
|
Chris@13
|
42 {
|
Chris@13
|
43 return [
|
Chris@13
|
44 ['exit;', "{$this->expectedExceptionString};"],
|
Chris@13
|
45 ['exit();', "{$this->expectedExceptionString};"],
|
Chris@13
|
46 ['die;', "{$this->expectedExceptionString};"],
|
Chris@13
|
47 ['exit(die(die));', "{$this->expectedExceptionString};"],
|
Chris@13
|
48 ['if (true) { exit; }', "if (true) {\n {$this->expectedExceptionString};\n}"],
|
Chris@13
|
49 ['if (false) { exit; }', "if (false) {\n {$this->expectedExceptionString};\n}"],
|
Chris@13
|
50 ['1 and exit();', "1 and {$this->expectedExceptionString};"],
|
Chris@13
|
51 ['foo() or die', "foo() or {$this->expectedExceptionString};"],
|
Chris@13
|
52 ['exit and 1;', "{$this->expectedExceptionString} and 1;"],
|
Chris@13
|
53 ['if (exit) { echo $wat; }', "if ({$this->expectedExceptionString}) {\n echo \$wat;\n}"],
|
Chris@13
|
54 ['exit or die;', "{$this->expectedExceptionString} or {$this->expectedExceptionString};"],
|
Chris@13
|
55 ['switch (die) { }', "switch ({$this->expectedExceptionString}) {\n}"],
|
Chris@13
|
56 ['for ($i = 1; $i < 10; die) {}', "for (\$i = 1; \$i < 10; {$this->expectedExceptionString}) {\n}"],
|
Chris@13
|
57 ];
|
Chris@13
|
58 }
|
Chris@13
|
59 }
|