diff options
Diffstat (limited to 'tests')
-rw-r--r-- | tests/PHPUnit/Core/ReleaseCheckListTest.php | 46 |
1 files changed, 46 insertions, 0 deletions
diff --git a/tests/PHPUnit/Core/ReleaseCheckListTest.php b/tests/PHPUnit/Core/ReleaseCheckListTest.php index 9f756a0a6c..3b722c8e59 100644 --- a/tests/PHPUnit/Core/ReleaseCheckListTest.php +++ b/tests/PHPUnit/Core/ReleaseCheckListTest.php @@ -165,6 +165,35 @@ class ReleaseCheckListTest extends PHPUnit_Framework_TestCase /** + * This tests that all PHP files start with <?php + * This would help detect errors such as a php file starting with spaces + */ + public function test_phpFilesStartWithRightCharacter() + { + $files = Filesystem::globr(PIWIK_INCLUDE_PATH, '*.php'); + + foreach($files as $file) { + $handle = fopen($file, "r"); + $expectedStart = "<?php"; + + + $isIniFile = strpos($file, ".ini.php") !== false || strpos($file, ".ini.travis.php") !== false; + if($isIniFile) { + $expectedStart = "; <?php exit;"; + } + + $skipStartFileTest = $this->isSkipPhpFileStartWithPhpBlock($file, $isIniFile); + + if($skipStartFileTest) { + continue; + } + + $start = fgets($handle, strlen($expectedStart) + 1 ); + $this->assertEquals($start, $expectedStart, "File $file does not start with $expectedStart"); + } + } + + /** * Check that directories in plugins/ folder are specifically either enabled or disabled. * * This fails when a new folder is added to plugins/* and forgot to enable or mark as disabled in Manager.php. @@ -304,5 +333,22 @@ class ReleaseCheckListTest extends PHPUnit_Framework_TestCase } } + /** + * @param $file + * @param $isIniFile + * @return bool + */ + protected function isSkipPhpFileStartWithPhpBlock($file, $isIniFile) + { + $isIniFileInTests = strpos($file, "/tests/") !== false; + $isTestResultFile = strpos($file, "/Integration/expected") !== false + || strpos($file, "/Integration/processed") !== false + || strpos($file, "tests/resources/Updater/") !== false + || strpos($file, "Twig/Tests/") !== false; + $isLib = strpos($file, "lib/xhprof") !== false; + + return ($isIniFile && $isIniFileInTests) || $isTestResultFile || $isLib; + } + } |