2009-03-22 01:25:09 +01:00
|
|
|
<?php
|
2016-08-19 00:51:35 +02:00
|
|
|
|
2016-10-14 03:30:05 +02:00
|
|
|
namespace SilverStripe\Core\Tests;
|
|
|
|
|
2016-08-19 00:51:35 +02:00
|
|
|
use SilverStripe\Dev\SapphireTest;
|
2016-10-14 03:30:05 +02:00
|
|
|
|
2009-03-22 01:25:09 +01:00
|
|
|
/**
|
|
|
|
* Test the syntax of the PHP files with various settings
|
|
|
|
*/
|
|
|
|
class PhpSyntaxTest extends SapphireTest {
|
2011-12-17 03:35:49 +01:00
|
|
|
public function setUp() {
|
|
|
|
parent::setUp();
|
2012-09-26 23:34:00 +02:00
|
|
|
$this->markTestSkipped('This needs to be written to include only core php files, not test/thirdparty files');
|
2011-12-17 03:35:49 +01:00
|
|
|
}
|
2014-08-15 08:53:05 +02:00
|
|
|
|
2012-09-19 12:07:39 +02:00
|
|
|
public function testShortTagsOffWillWork() {
|
2009-03-22 01:25:09 +01:00
|
|
|
// 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);
|
2016-10-14 01:57:33 +02:00
|
|
|
if($returnCode != 0) {
|
|
|
|
$this->markTestSkipped("Only works on *nix based systems");
|
|
|
|
return;
|
|
|
|
}
|
2009-03-22 01:25:09 +01:00
|
|
|
|
|
|
|
$settingTests = array('short_open_tag=Off','short_open_tag=On -d asp_tags=On');
|
2014-08-15 08:53:05 +02:00
|
|
|
|
2009-03-22 01:25:09 +01:00
|
|
|
$files = $this->getAllFiles('php');
|
2016-11-01 04:13:06 +01:00
|
|
|
$files[] = FRAMEWORK_PATH.'/src/Dev/Install/config-form.html';
|
2014-08-15 08:53:05 +02:00
|
|
|
|
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);
|
2014-08-15 08:53:05 +02:00
|
|
|
$hasErrors = ($returnCode != 0
|
2012-09-26 23:34:00 +02:00
|
|
|
&& strpos('No syntax errors detected', implode("\n", $output)) === FALSE);
|
|
|
|
$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
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2014-08-15 08:53:05 +02:00
|
|
|
|
2012-09-19 12:07:39 +02:00
|
|
|
public function getAllFiles($ext = 'php') {
|
2009-03-22 01:25:09 +01:00
|
|
|
// TODO: Unix only
|
2010-10-19 05:46:04 +02:00
|
|
|
$cmd = sprintf(
|
2014-08-15 08:53:05 +02:00
|
|
|
'find %s | grep %s',
|
2010-10-19 05:46:04 +02:00
|
|
|
BASE_PATH,
|
2016-10-14 03:30:05 +02:00
|
|
|
escapeshellarg(".{$ext}\$")
|
2010-10-19 05:46:04 +02:00
|
|
|
);
|
|
|
|
return explode("\n", trim(`$cmd`));
|
2009-03-22 01:25:09 +01:00
|
|
|
}
|
2012-03-24 04:38:57 +01:00
|
|
|
}
|