FunctionContextPassTest.php 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  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\FunctionContextPass;
  12. /**
  13. * @group isolation-fail
  14. */
  15. class FunctionContextPassTest extends CodeCleanerTestCase
  16. {
  17. /**
  18. * @before
  19. */
  20. public function getReady()
  21. {
  22. $this->setPass(new FunctionContextPass());
  23. }
  24. /**
  25. * @dataProvider validStatements
  26. */
  27. public function testProcessStatementPasses($code)
  28. {
  29. $this->parseAndTraverse($code);
  30. $this->assertTrue(true);
  31. }
  32. public function validStatements()
  33. {
  34. return [
  35. ['function foo() { yield; }'],
  36. ['if (function(){ yield; })'],
  37. ];
  38. }
  39. /**
  40. * @dataProvider invalidYieldStatements
  41. */
  42. public function testInvalidYield($code)
  43. {
  44. $this->expectException(\Psy\Exception\FatalErrorException::class);
  45. $this->parseAndTraverse($code);
  46. $this->fail();
  47. }
  48. public function invalidYieldStatements()
  49. {
  50. return [
  51. ['yield'],
  52. ['if (yield)'],
  53. ];
  54. }
  55. }