No Description

TimeitVisitorTest.php 1.5KB

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