annotate vendor/psy/psysh/test/Psy/Test/CodeCleaner/CallTimePassByReferencePassTest.php @ 12:7a779792577d

Update Drupal core to v8.4.5 (via Composer)
author Chris Cannam
date Fri, 23 Feb 2018 15:52:07 +0000
parents 4c8ae668cc8c
children
rev   line source
Chris@0 1 <?php
Chris@0 2
Chris@0 3 /*
Chris@0 4 * This file is part of Psy Shell.
Chris@0 5 *
Chris@0 6 * (c) 2012-2017 Justin Hileman
Chris@0 7 *
Chris@0 8 * For the full copyright and license information, please view the LICENSE
Chris@0 9 * file that was distributed with this source code.
Chris@0 10 */
Chris@0 11
Chris@0 12 namespace Psy\Test\CodeCleaner;
Chris@0 13
Chris@0 14 use PhpParser\NodeTraverser;
Chris@0 15 use Psy\CodeCleaner\CallTimePassByReferencePass;
Chris@0 16
Chris@0 17 class CallTimePassByReferencePassTest extends CodeCleanerTestCase
Chris@0 18 {
Chris@0 19 public function setUp()
Chris@0 20 {
Chris@0 21 $this->pass = new CallTimePassByReferencePass();
Chris@0 22 $this->traverser = new NodeTraverser();
Chris@0 23 $this->traverser->addVisitor($this->pass);
Chris@0 24 }
Chris@0 25
Chris@0 26 /**
Chris@0 27 * @dataProvider invalidStatements
Chris@0 28 * @expectedException \Psy\Exception\FatalErrorException
Chris@0 29 */
Chris@0 30 public function testProcessStatementFails($code)
Chris@0 31 {
Chris@0 32 if (version_compare(PHP_VERSION, '5.4', '<')) {
Chris@0 33 $this->markTestSkipped();
Chris@0 34 }
Chris@0 35
Chris@0 36 $stmts = $this->parse($code);
Chris@0 37 $this->traverser->traverse($stmts);
Chris@0 38 }
Chris@0 39
Chris@0 40 public function invalidStatements()
Chris@0 41 {
Chris@0 42 return array(
Chris@0 43 array('f(&$arg)'),
Chris@0 44 array('$object->method($first, &$arg)'),
Chris@0 45 array('$closure($first, &$arg, $last)'),
Chris@0 46 array('A::b(&$arg)'),
Chris@0 47 );
Chris@0 48 }
Chris@0 49
Chris@0 50 /**
Chris@0 51 * @dataProvider validStatements
Chris@0 52 */
Chris@0 53 public function testProcessStatementPasses($code)
Chris@0 54 {
Chris@0 55 $stmts = $this->parse($code);
Chris@0 56 $this->traverser->traverse($stmts);
Chris@12 57
Chris@12 58 // @todo a better thing to assert here?
Chris@12 59 $this->assertTrue(true);
Chris@0 60 }
Chris@0 61
Chris@0 62 public function validStatements()
Chris@0 63 {
Chris@0 64 $data = array(
Chris@0 65 array('array(&$var)'),
Chris@0 66 array('$a = &$b'),
Chris@0 67 array('f(array(&$b))'),
Chris@0 68 );
Chris@0 69
Chris@0 70 if (version_compare(PHP_VERSION, '5.4', '<')) {
Chris@0 71 $data = array_merge($data, $this->invalidStatements());
Chris@0 72 }
Chris@0 73
Chris@0 74 return $data;
Chris@0 75 }
Chris@0 76 }