TimeitVisitorTest.php 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  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\Command\TimeitCommand;
  11. use PhpParser\NodeTraverser;
  12. use Psy\Command\TimeitCommand\TimeitVisitor;
  13. use Psy\Test\ParserTestCase;
  14. /**
  15. * @group isolation-fail
  16. */
  17. class TimeitVisitorTest extends ParserTestCase
  18. {
  19. /**
  20. * @before
  21. */
  22. public function getReady()
  23. {
  24. $this->traverser = new NodeTraverser();
  25. $this->traverser->addVisitor(new TimeitVisitor());
  26. }
  27. /**
  28. * @dataProvider codez
  29. */
  30. public function testProcess($from, $to)
  31. {
  32. $this->assertProcessesAs($from, $to);
  33. }
  34. public function codez()
  35. {
  36. $start = '\Psy\Command\TimeitCommand::markStart';
  37. $end = '\Psy\Command\TimeitCommand::markEnd';
  38. $noReturn = 'new \Psy\CodeCleaner\NoReturnValue()';
  39. return [
  40. ['', "$end($start());"], // heh
  41. ['a()', "$start(); $end(a());"],
  42. ['$b()', "$start(); $end(\$b());"],
  43. ['$c->d()', "$start(); $end(\$c->d());"],
  44. ['e(); f()', "$start(); e(); $end(f());"],
  45. ['function g() { return 1; }', "$start(); function g() {return 1;} $end($noReturn);"],
  46. ['return 1', "$start(); return $end(1);"],
  47. ['return 1; 2', "$start(); return $end(1); $end(2);"],
  48. ['return 1; function h() {}', "$start(); return $end(1); function h() {} $end($noReturn);"],
  49. ];
  50. }
  51. }