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),
79 * @dataProvider moreUnclosedStatementsProvider
81 public function testMoreUnclosedStatements(array $lines)
83 if (defined('HHVM_VERSION')) {
84 $this->markTestSkipped('HHVM not supported.');
87 $cc = new CodeCleaner();
88 $res = $cc->clean($lines);
90 $this->assertFalse($res);
93 public function moreUnclosedStatementsProvider()
96 array(array("\$content = <<<EOS\n")),
97 array(array("\$content = <<<'EOS'\n")),
99 array(array('/* unclosed comment')),
100 array(array('/** unclosed comment')),
105 * @dataProvider invalidStatementsProvider
106 * @expectedException \Psy\Exception\ParseErrorException
108 public function testInvalidStatementsThrowParseErrors($code)
110 $cc = new CodeCleaner();
111 $cc->clean(array($code));
114 public function invalidStatementsProvider()
117 array('function "what'),
118 array("function 'what"),