ExitPassTest.php 2.0 KB

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