Chris@16
|
1 <?php
|
Chris@16
|
2
|
Chris@16
|
3 /*
|
Chris@16
|
4 * This file is part of Psy Shell.
|
Chris@16
|
5 *
|
Chris@16
|
6 * (c) 2012-2018 Justin Hileman
|
Chris@16
|
7 *
|
Chris@16
|
8 * For the full copyright and license information, please view the LICENSE
|
Chris@16
|
9 * file that was distributed with this source code.
|
Chris@16
|
10 */
|
Chris@16
|
11
|
Chris@16
|
12 namespace Psy\Test\Command\TimeitCommand;
|
Chris@16
|
13
|
Chris@16
|
14 use PhpParser\NodeTraverser;
|
Chris@16
|
15 use Psy\Command\TimeitCommand\TimeitVisitor;
|
Chris@16
|
16 use Psy\Test\ParserTestCase;
|
Chris@16
|
17
|
Chris@16
|
18 class TimeitVisitorTest extends ParserTestCase
|
Chris@16
|
19 {
|
Chris@16
|
20 public function setUp()
|
Chris@16
|
21 {
|
Chris@16
|
22 $this->traverser = new NodeTraverser();
|
Chris@16
|
23 $this->traverser->addVisitor(new TimeitVisitor());
|
Chris@16
|
24 }
|
Chris@16
|
25
|
Chris@16
|
26 /**
|
Chris@16
|
27 * @dataProvider codez
|
Chris@16
|
28 */
|
Chris@16
|
29 public function testProcess($from, $to)
|
Chris@16
|
30 {
|
Chris@16
|
31 $this->assertProcessesAs($from, $to);
|
Chris@16
|
32 }
|
Chris@16
|
33
|
Chris@16
|
34 public function codez()
|
Chris@16
|
35 {
|
Chris@16
|
36 $start = '\Psy\Command\TimeitCommand::markStart';
|
Chris@16
|
37 $end = '\Psy\Command\TimeitCommand::markEnd';
|
Chris@16
|
38 $noReturn = 'new \Psy\CodeCleaner\NoReturnValue()';
|
Chris@16
|
39
|
Chris@16
|
40 return [
|
Chris@16
|
41 ['', "$end($start());"], // heh
|
Chris@16
|
42 ['a()', "$start(); $end(a());"],
|
Chris@16
|
43 ['$b()', "$start(); $end(\$b());"],
|
Chris@16
|
44 ['$c->d()', "$start(); $end(\$c->d());"],
|
Chris@16
|
45 ['e(); f()', "$start(); e(); $end(f());"],
|
Chris@16
|
46 ['function g() { return 1; }', "$start(); function g() {return 1;} $end($noReturn);"],
|
Chris@16
|
47 ['return 1', "$start(); return $end(1);"],
|
Chris@16
|
48 ['return 1; 2', "$start(); return $end(1); $end(2);"],
|
Chris@16
|
49 ['return 1; function h() {}', "$start(); return $end(1); function h() {} $end($noReturn);"],
|
Chris@16
|
50 ];
|
Chris@16
|
51 }
|
Chris@16
|
52 }
|