CodeCleanerTestCase.php 909 B

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