CallTimePassByReferencePassTest.php 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  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\CallTimePassByReferencePass;
  12. /**
  13. * @group isolation-fail
  14. */
  15. class CallTimePassByReferencePassTest extends CodeCleanerTestCase
  16. {
  17. /**
  18. * @before
  19. */
  20. public function getReady()
  21. {
  22. $this->setPass(new CallTimePassByReferencePass());
  23. }
  24. /**
  25. * @dataProvider invalidStatements
  26. */
  27. public function testProcessStatementFails($code)
  28. {
  29. $this->expectException(\Psy\Exception\FatalErrorException::class);
  30. $this->parseAndTraverse($code);
  31. $this->fail();
  32. }
  33. public function invalidStatements()
  34. {
  35. return [
  36. ['f(&$arg)'],
  37. ['$object->method($first, &$arg)'],
  38. ['$closure($first, &$arg, $last)'],
  39. ['A::b(&$arg)'],
  40. ];
  41. }
  42. /**
  43. * @dataProvider validStatements
  44. */
  45. public function testProcessStatementPasses($code)
  46. {
  47. $this->parseAndTraverse($code);
  48. $this->assertTrue(true);
  49. }
  50. public function validStatements()
  51. {
  52. return [
  53. ['[&$var]'],
  54. ['$a = &$b'],
  55. ['f([&$b])'],
  56. ];
  57. }
  58. }