PassableByReferencePassTest.php 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. <?php
  2. /*
  3. * This file is part of Psy Shell.
  4. *
  5. * (c) 2012-2017 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 PhpParser\NodeTraverser;
  12. use Psy\CodeCleaner\PassableByReferencePass;
  13. class PassableByReferencePassTest extends CodeCleanerTestCase
  14. {
  15. public function setUp()
  16. {
  17. $this->pass = new PassableByReferencePass();
  18. $this->traverser = new NodeTraverser();
  19. $this->traverser->addVisitor($this->pass);
  20. }
  21. /**
  22. * @dataProvider invalidStatements
  23. * @expectedException \Psy\Exception\FatalErrorException
  24. */
  25. public function testProcessStatementFails($code)
  26. {
  27. $stmts = $this->parse($code);
  28. $this->traverser->traverse($stmts);
  29. }
  30. public function invalidStatements()
  31. {
  32. return array(
  33. array('array_pop(array())'),
  34. array('array_pop(array($foo))'),
  35. array('array_shift(array())'),
  36. );
  37. }
  38. /**
  39. * @dataProvider validStatements
  40. */
  41. public function testProcessStatementPasses($code)
  42. {
  43. $stmts = $this->parse($code);
  44. $this->traverser->traverse($stmts);
  45. }
  46. public function validStatements()
  47. {
  48. return array(
  49. array('array_pop(json_decode("[]"))'),
  50. array('array_pop($foo)'),
  51. array('array_pop($foo->bar)'),
  52. array('array_pop($foo::baz)'),
  53. array('array_pop(Foo::qux)'),
  54. );
  55. }
  56. }