ExitPassTest.php 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. <?php
  2. /*
  3. * This file is part of Psy Shell.
  4. *
  5. * (c) 2012-2018 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 [
  37. ['exit;', "{$this->expectedExceptionString};"],
  38. ['exit();', "{$this->expectedExceptionString};"],
  39. ['die;', "{$this->expectedExceptionString};"],
  40. ['exit(die(die));', "{$this->expectedExceptionString};"],
  41. ['if (true) { exit; }', "if (true) {\n {$this->expectedExceptionString};\n}"],
  42. ['if (false) { exit; }', "if (false) {\n {$this->expectedExceptionString};\n}"],
  43. ['1 and exit();', "1 and {$this->expectedExceptionString};"],
  44. ['foo() or die', "foo() or {$this->expectedExceptionString};"],
  45. ['exit and 1;', "{$this->expectedExceptionString} and 1;"],
  46. ['if (exit) { echo $wat; }', "if ({$this->expectedExceptionString}) {\n echo \$wat;\n}"],
  47. ['exit or die;', "{$this->expectedExceptionString} or {$this->expectedExceptionString};"],
  48. ['switch (die) { }', "switch ({$this->expectedExceptionString}) {\n}"],
  49. ['for ($i = 1; $i < 10; die) {}', "for (\$i = 1; \$i < 10; {$this->expectedExceptionString}) {\n}"],
  50. ];
  51. }
  52. }