4 * This file is part of Psy Shell.
6 * (c) 2012-2017 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 array('exit;', "{$this->expectedExceptionString};"),
45 array('exit();', "{$this->expectedExceptionString};"),
46 array('die;', "{$this->expectedExceptionString};"),
47 array('exit(die(die));', "{$this->expectedExceptionString};"),
48 array('if (true) { exit; }', "if (true) {\n {$this->expectedExceptionString};\n}"),
49 array('if (false) { exit; }', "if (false) {\n {$this->expectedExceptionString};\n}"),
50 array('1 and exit();', "1 and {$this->expectedExceptionString};"),
51 array('foo() or die', "foo() or {$this->expectedExceptionString};"),
52 array('exit and 1;', "{$this->expectedExceptionString} and 1;"),
53 array('if (exit) { echo $wat; }', "if ({$this->expectedExceptionString}) {\n echo \$wat;\n}"),
54 array('exit or die;', "{$this->expectedExceptionString} or {$this->expectedExceptionString};"),
55 array('switch (die) { }', "switch ({$this->expectedExceptionString}) {\n}"),
56 array('for ($i = 1; $i < 10; die) {}', "for (\$i = 1; \$i < 10; {$this->expectedExceptionString}) {\n}"),