Yaffs site version 1.1
[yaffs-website] / vendor / psy / psysh / test / Psy / Test / CodeCleaner / ExitPassTest.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\ExitPass;
15
16 class ExitPassTest extends CodeCleanerTestCase
17 {
18     /**
19      * @var string
20      */
21     private $expectedExceptionString = '\\Psy\\Exception\\BreakException::exitShell()';
22
23     public function setUp()
24     {
25         $this->setPass(new ExitPass());
26     }
27
28     /**
29      * @dataProvider dataProviderExitStatement
30      */
31     public function testExitStatement($from, $to)
32     {
33         $this->assertProcessesAs($from, $to);
34     }
35
36     /**
37      * Data provider for testExitStatement.
38      *
39      * @return array
40      */
41     public function dataProviderExitStatement()
42     {
43         return array(
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}"),
57         );
58     }
59 }