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
|
|
|
|
*/
|
2016-12-16 05:34:21 +01:00
|
|
|
class PhpSyntaxTest extends SapphireTest
|
|
|
|
{
|
2021-10-27 04:39:47 +02:00
|
|
|
protected function setUp(): void
|
2016-12-16 05:34:21 +01:00
|
|
|
{
|
|
|
|
parent::setUp();
|
|
|
|
$this->markTestSkipped('This needs to be written to include only core php files, not test/thirdparty files');
|
|
|
|
}
|
|
|
|
|
|
|
|
public 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;
|
2020-04-20 19:58:09 +02:00
|
|
|
$output = [];
|
2016-12-16 05:34:21 +01:00
|
|
|
exec("which find && which grep && which php", $output, $returnCode);
|
|
|
|
if ($returnCode != 0) {
|
|
|
|
$this->markTestSkipped("Only works on *nix based systems");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2020-04-20 19:58:09 +02:00
|
|
|
$settingTests = ['short_open_tag=Off','short_open_tag=On -d asp_tags=On'];
|
2016-12-16 05:34:21 +01:00
|
|
|
|
|
|
|
$files = $this->getAllFiles('php');
|
2018-01-16 19:39:30 +01:00
|
|
|
$files[] = FRAMEWORK_PATH . '/src/Dev/Install/config-form.html';
|
2016-12-16 05:34:21 +01:00
|
|
|
|
|
|
|
foreach ($files as $i => $file) {
|
|
|
|
$CLI_file = escapeshellarg($file);
|
|
|
|
foreach ($settingTests as $settingTest) {
|
|
|
|
$returnCode = 0;
|
2020-04-20 19:58:09 +02:00
|
|
|
$output = [];
|
2016-12-16 05:34:21 +01:00
|
|
|
exec("php -l -d $settingTest $CLI_file", $output, $returnCode);
|
|
|
|
$hasErrors = ($returnCode != 0
|
|
|
|
&& 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})"
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public function getAllFiles($ext = 'php')
|
|
|
|
{
|
|
|
|
// TODO: Unix only
|
|
|
|
$cmd = sprintf(
|
|
|
|
'find %s | grep %s',
|
|
|
|
BASE_PATH,
|
|
|
|
escapeshellarg(".{$ext}\$")
|
|
|
|
);
|
|
|
|
return explode("\n", trim(`$cmd`));
|
|
|
|
}
|
2012-03-24 04:38:57 +01:00
|
|
|
}
|