4 * This file is part of Psy Shell.
6 * (c) 2012-2018 Justin Hileman
8 * For the full copyright and license information, please view the LICENSE
9 * file that was distributed with this source code.
12 namespace Psy\Test\CodeCleaner;
14 use Psy\CodeCleaner\ExitPass;
16 class ExitPassTest extends CodeCleanerTestCase
21 private $expectedExceptionString = '\\Psy\\Exception\\BreakException::exitShell()';
23 public function setUp()
25 $this->setPass(new ExitPass());
29 * @dataProvider dataProviderExitStatement
31 public function testExitStatement($from, $to)
33 $this->assertProcessesAs($from, $to);
37 * Data provider for testExitStatement.
41 public function dataProviderExitStatement()
44 ['exit;', "{$this->expectedExceptionString};"],
45 ['exit();', "{$this->expectedExceptionString};"],
46 ['die;', "{$this->expectedExceptionString};"],
47 ['exit(die(die));', "{$this->expectedExceptionString};"],
48 ['if (true) { exit; }', "if (true) {\n {$this->expectedExceptionString};\n}"],
49 ['if (false) { exit; }', "if (false) {\n {$this->expectedExceptionString};\n}"],
50 ['1 and exit();', "1 and {$this->expectedExceptionString};"],
51 ['foo() or die', "foo() or {$this->expectedExceptionString};"],
52 ['exit and 1;', "{$this->expectedExceptionString} and 1;"],
53 ['if (exit) { echo $wat; }', "if ({$this->expectedExceptionString}) {\n echo \$wat;\n}"],
54 ['exit or die;', "{$this->expectedExceptionString} or {$this->expectedExceptionString};"],
55 ['switch (die) { }', "switch ({$this->expectedExceptionString}) {\n}"],
56 ['for ($i = 1; $i < 10; die) {}', "for (\$i = 1; \$i < 10; {$this->expectedExceptionString}) {\n}"],