CodeCleanerTestCase.php 918 B

12345678910111213141516171819202122232425262728293031323334353637383940414243
  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 PhpParser\NodeTraverser;
  12. use Psy\CodeCleaner\CodeCleanerPass;
  13. use Psy\Test\ParserTestCase;
  14. class CodeCleanerTestCase extends ParserTestCase
  15. {
  16. protected $pass;
  17. /**
  18. * @after
  19. */
  20. public function clearProperties()
  21. {
  22. $this->pass = null;
  23. }
  24. protected function setPass(CodeCleanerPass $pass)
  25. {
  26. $this->pass = $pass;
  27. if (!isset($this->traverser)) {
  28. $this->traverser = new NodeTraverser();
  29. }
  30. $this->traverser->addVisitor($this->pass);
  31. }
  32. protected function parseAndTraverse($code, $prefix = '<?php ')
  33. {
  34. return $this->traverse($this->parse($code, $prefix));
  35. }
  36. }