ExitPassTest.php 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. <?php
  2. /*
  3. * This file is part of Psy Shell.
  4. *
  5. * (c) 2012-2015 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 = "throw new Psy\\Exception\\BreakException('Goodbye.');";
  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('if (true) { exit; }', "if (true) {\n $this->expectedExceptionString\n}"),
  41. array('if (false) { exit; }', "if (false) {\n $this->expectedExceptionString\n}"),
  42. );
  43. }
  44. }