2009-03-22 01:25:09 +01:00
|
|
|
<?php
|
|
|
|
/**
|
2009-05-14 08:57:57 +02:00
|
|
|
* @package sapphire
|
|
|
|
* @subpackage tests
|
|
|
|
*
|
2009-03-22 01:25:09 +01:00
|
|
|
* Test the syntax of the PHP files with various settings
|
|
|
|
*/
|
|
|
|
class PhpSyntaxTest extends SapphireTest {
|
|
|
|
function testShortTagsOffWillWork() {
|
|
|
|
// Ignore this test completely if running the test suite on windows
|
|
|
|
// TODO: Make it work on all platforms, by building an alternative to find | grep.
|
|
|
|
$returnCode = 0;
|
|
|
|
$output = array();
|
|
|
|
exec("which find && which grep && which php", $output, $returnCode);
|
|
|
|
if($returnCode != 0) return;
|
|
|
|
|
|
|
|
$settingTests = array('short_open_tag=Off','short_open_tag=On -d asp_tags=On');
|
|
|
|
|
|
|
|
$files = $this->getAllFiles('php');
|
2010-04-13 01:14:36 +02:00
|
|
|
$files[] = BASE_PATH.'/sapphire/dev/install/config-form.html';
|
2009-03-22 01:25:09 +01:00
|
|
|
|
|
|
|
foreach($files as $i => $file) {
|
|
|
|
$CLI_file = escapeshellarg($file);
|
|
|
|
foreach($settingTests as $settingTest) {
|
|
|
|
$returnCode = 0;
|
|
|
|
$output = array();
|
|
|
|
exec("php -l -d $settingTest $CLI_file", $output, $returnCode);
|
2009-10-11 11:01:36 +02:00
|
|
|
$hasErrors = ($returnCode != 0 && strpos('No syntax errors detected', implode("\n", $output)) === FALSE);
|
2009-07-17 01:55:46 +02:00
|
|
|
$this->assertFalse($hasErrors, "Syntax error parsing $CLI_file with setting $settingTest:\n" . implode("\n", $output) . " (Returned: {$returnCode})");
|
2009-03-22 01:25:09 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function getAllFiles($ext = 'php') {
|
|
|
|
// TODO: Unix only
|
|
|
|
$CLI_regexp = escapeshellarg("\.$ext\$");
|
|
|
|
return explode("\n", trim(`find .. | grep $CLI_regexp`));
|
|
|
|
}
|
|
|
|
}
|