FunctionContextPassTest.php 1.1 KB

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