annotate vendor/psy/psysh/test/Psy/Test/CodeCleaner/ExitPassTest.php @ 0:4c8ae668cc8c

Initial import (non-working)
author Chris Cannam
date Wed, 29 Nov 2017 16:09:58 +0000
parents
children
rev   line source
Chris@0 1 <?php
Chris@0 2
Chris@0 3 /*
Chris@0 4 * This file is part of Psy Shell.
Chris@0 5 *
Chris@0 6 * (c) 2012-2017 Justin Hileman
Chris@0 7 *
Chris@0 8 * For the full copyright and license information, please view the LICENSE
Chris@0 9 * file that was distributed with this source code.
Chris@0 10 */
Chris@0 11
Chris@0 12 namespace Psy\Test\CodeCleaner;
Chris@0 13
Chris@0 14 use Psy\CodeCleaner\ExitPass;
Chris@0 15
Chris@0 16 class ExitPassTest extends CodeCleanerTestCase
Chris@0 17 {
Chris@0 18 /**
Chris@0 19 * @var string
Chris@0 20 */
Chris@0 21 private $expectedExceptionString = '\\Psy\\Exception\\BreakException::exitShell()';
Chris@0 22
Chris@0 23 public function setUp()
Chris@0 24 {
Chris@0 25 $this->setPass(new ExitPass());
Chris@0 26 }
Chris@0 27
Chris@0 28 /**
Chris@0 29 * @dataProvider dataProviderExitStatement
Chris@0 30 */
Chris@0 31 public function testExitStatement($from, $to)
Chris@0 32 {
Chris@0 33 $this->assertProcessesAs($from, $to);
Chris@0 34 }
Chris@0 35
Chris@0 36 /**
Chris@0 37 * Data provider for testExitStatement.
Chris@0 38 *
Chris@0 39 * @return array
Chris@0 40 */
Chris@0 41 public function dataProviderExitStatement()
Chris@0 42 {
Chris@0 43 return array(
Chris@0 44 array('exit;', "{$this->expectedExceptionString};"),
Chris@0 45 array('exit();', "{$this->expectedExceptionString};"),
Chris@0 46 array('die;', "{$this->expectedExceptionString};"),
Chris@0 47 array('exit(die(die));', "{$this->expectedExceptionString};"),
Chris@0 48 array('if (true) { exit; }', "if (true) {\n {$this->expectedExceptionString};\n}"),
Chris@0 49 array('if (false) { exit; }', "if (false) {\n {$this->expectedExceptionString};\n}"),
Chris@0 50 array('1 and exit();', "1 and {$this->expectedExceptionString};"),
Chris@0 51 array('foo() or die', "foo() or {$this->expectedExceptionString};"),
Chris@0 52 array('exit and 1;', "{$this->expectedExceptionString} and 1;"),
Chris@0 53 array('if (exit) { echo $wat; }', "if ({$this->expectedExceptionString}) {\n echo \$wat;\n}"),
Chris@0 54 array('exit or die;', "{$this->expectedExceptionString} or {$this->expectedExceptionString};"),
Chris@0 55 array('switch (die) { }', "switch ({$this->expectedExceptionString}) {\n}"),
Chris@0 56 array('for ($i = 1; $i < 10; die) {}', "for (\$i = 1; \$i < 10; {$this->expectedExceptionString}) {\n}"),
Chris@0 57 );
Chris@0 58 }
Chris@0 59 }