4 * This file is part of Psy Shell.
6 * (c) 2012-2017 Justin Hileman
8 * For the full copyright and license information, please view the LICENSE
9 * file that was distributed with this source code.
16 class CodeCleanerTest extends \PHPUnit\Framework\TestCase
19 * @dataProvider semicolonCodeProvider
21 public function testAutomaticSemicolons(array $lines, $requireSemicolons, $expected)
23 $cc = new CodeCleaner();
24 $this->assertEquals($expected, $cc->clean($lines, $requireSemicolons));
27 public function semicolonCodeProvider()
30 array(array('true'), false, 'return true;'),
31 array(array('true;'), false, 'return true;'),
32 array(array('true;'), true, 'return true;'),
33 array(array('true'), true, false),
35 array(array('echo "foo";', 'true'), true, false),
38 if (version_compare(PHP_VERSION, '5.4', '<')) {
39 $values[] = array(array('echo "foo";', 'true'), false, "echo 'foo';\nreturn true;");
41 $values[] = array(array('echo "foo";', 'true'), false, "echo \"foo\";\nreturn true;");
48 * @dataProvider unclosedStatementsProvider
50 public function testUnclosedStatements(array $lines, $isUnclosed)
52 $cc = new CodeCleaner();
53 $res = $cc->clean($lines);
56 $this->assertFalse($res);
58 $this->assertNotFalse($res);
62 public function unclosedStatementsProvider()
65 array(array('echo "'), true),
66 array(array('echo \''), true),
67 array(array('if (1) {'), true),
69 array(array('echo ""'), false),
70 array(array("echo ''"), false),
71 array(array('if (1) {}'), false),
73 array(array('// closed comment'), false),
74 array(array('function foo() { /**'), true),
76 array(array('var_dump(1, 2,'), true),
77 array(array('var_dump(1, 2,', '3)'), false),
82 * @dataProvider moreUnclosedStatementsProvider
84 public function testMoreUnclosedStatements(array $lines)
86 if (defined('HHVM_VERSION')) {
87 $this->markTestSkipped('HHVM not supported.');
90 $cc = new CodeCleaner();
91 $res = $cc->clean($lines);
93 $this->assertFalse($res);
96 public function moreUnclosedStatementsProvider()
99 array(array("\$content = <<<EOS\n")),
100 array(array("\$content = <<<'EOS'\n")),
102 array(array('/* unclosed comment')),
103 array(array('/** unclosed comment')),
108 * @dataProvider invalidStatementsProvider
109 * @expectedException \Psy\Exception\ParseErrorException
111 public function testInvalidStatementsThrowParseErrors($code)
113 $cc = new CodeCleaner();
114 $cc->clean(array($code));
117 public function invalidStatementsProvider()
120 array('function "what'),
121 array("function 'what"),
129 array('var_dump(1,2,)'),