mirror of
https://github.com/silverstripe/silverstripe-framework
synced 2024-10-22 14:05:37 +02:00
4499420ff2
git-svn-id: svn://svn.silverstripe.com/silverstripe/open/modules/sapphire/trunk@82063 467b73ca-7a2a-4603-9d3b-597d59a354a9
39 lines
1.3 KiB
PHP
39 lines
1.3 KiB
PHP
<?php
|
|
/**
|
|
* @package sapphire
|
|
* @subpackage tests
|
|
*
|
|
* 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');
|
|
$files[] = '../sapphire/dev/install/config-form.html';
|
|
|
|
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);
|
|
$hasErrors = ($returnCode != 0 && strpos('No syntax errors detected', $returnCode) === FALSE);
|
|
$this->assertFalse($hasErrors, "Syntax error parsing $CLI_file with setting $settingTest:\n" . implode("\n", $output) . " (Returned: {$returnCode})");
|
|
}
|
|
}
|
|
}
|
|
|
|
function getAllFiles($ext = 'php') {
|
|
// TODO: Unix only
|
|
$CLI_regexp = escapeshellarg("\.$ext\$");
|
|
return explode("\n", trim(`find .. | grep $CLI_regexp`));
|
|
}
|
|
} |