Yaffs site version 1.1
[yaffs-website] / vendor / psy / psysh / test / Psy / Test / CodeCleaner / CallTimePassByReferencePassTest.php
1 <?php
2
3 /*
4  * This file is part of Psy Shell.
5  *
6  * (c) 2012-2017 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\CodeCleaner;
13
14 use PhpParser\NodeTraverser;
15 use Psy\CodeCleaner\CallTimePassByReferencePass;
16
17 class CallTimePassByReferencePassTest extends CodeCleanerTestCase
18 {
19     public function setUp()
20     {
21         $this->pass      = new CallTimePassByReferencePass();
22         $this->traverser = new NodeTraverser();
23         $this->traverser->addVisitor($this->pass);
24     }
25
26     /**
27      * @dataProvider invalidStatements
28      * @expectedException \Psy\Exception\FatalErrorException
29      */
30     public function testProcessStatementFails($code)
31     {
32         if (version_compare(PHP_VERSION, '5.4', '<')) {
33             $this->markTestSkipped();
34         }
35
36         $stmts = $this->parse($code);
37         $this->traverser->traverse($stmts);
38     }
39
40     public function invalidStatements()
41     {
42         return array(
43             array('f(&$arg)'),
44             array('$object->method($first, &$arg)'),
45             array('$closure($first, &$arg, $last)'),
46             array('A::b(&$arg)'),
47         );
48     }
49
50     /**
51      * @dataProvider validStatements
52      */
53     public function testProcessStatementPasses($code)
54     {
55         $stmts = $this->parse($code);
56         $this->traverser->traverse($stmts);
57     }
58
59     public function validStatements()
60     {
61         $data = array(
62             array('array(&$var)'),
63             array('$a = &$b'),
64             array('f(array(&$b))'),
65         );
66
67         if (version_compare(PHP_VERSION, '5.4', '<')) {
68             $data = array_merge($data, $this->invalidStatements());
69         }
70
71         return $data;
72     }
73 }