ExitPassTest.php 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. <?php
  2. /*
  3. * This file is part of Psy Shell.
  4. *
  5. * (c) 2012-2023 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. /**
  13. * @group isolation-fail
  14. */
  15. class ExitPassTest extends CodeCleanerTestCase
  16. {
  17. /**
  18. * @var string
  19. */
  20. private $expectedExceptionString = '\\Psy\\Exception\\BreakException::exitShell()';
  21. /**
  22. * @before
  23. */
  24. public function getReady()
  25. {
  26. $this->setPass(new ExitPass());
  27. }
  28. /**
  29. * @dataProvider dataProviderExitStatement
  30. */
  31. public function testExitStatement($from, $to)
  32. {
  33. $this->assertProcessesAs($from, $to);
  34. }
  35. /**
  36. * Data provider for testExitStatement.
  37. *
  38. * @return array
  39. */
  40. public function dataProviderExitStatement()
  41. {
  42. return [
  43. ['exit;', "{$this->expectedExceptionString};"],
  44. ['exit();', "{$this->expectedExceptionString};"],
  45. ['die;', "{$this->expectedExceptionString};"],
  46. ['exit(die(die));', "{$this->expectedExceptionString};"],
  47. ['if (true) { exit; }', "if (true) { {$this->expectedExceptionString}; }"],
  48. ['if (false) { exit; }', "if (false) { {$this->expectedExceptionString}; }"],
  49. ['1 and exit();', "1 and {$this->expectedExceptionString};"],
  50. ['foo() or die', "foo() or {$this->expectedExceptionString};"],
  51. ['exit and 1;', "{$this->expectedExceptionString} and 1;"],
  52. ['if (exit) { echo $wat; }', "if ({$this->expectedExceptionString}) { echo \$wat; }"],
  53. ['exit or die;', "{$this->expectedExceptionString} or {$this->expectedExceptionString};"],
  54. ['switch (die) { }', "switch ({$this->expectedExceptionString}) {}"],
  55. ['for ($i = 1; $i < 10; die) {}', "for (\$i = 1; \$i < 10; {$this->expectedExceptionString}) {}"],
  56. ];
  57. }
  58. }