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