diff options
author | mattab <matthieu.aubry@gmail.com> | 2014-02-21 05:33:23 +0400 |
---|---|---|
committer | mattab <matthieu.aubry@gmail.com> | 2014-02-21 05:33:23 +0400 |
commit | 539cb8df8d0ec28a6e5bd5e40e1a6321420a64e8 (patch) | |
tree | ae2d0d14a34d146f8f595a81aa8ad7d4ec93c56c /tests | |
parent | d90f41b8c306648ec63cb3847154a5bb1bda5b8d (diff) |
Add unit test check PHP files start with <?php -> prevent human error when IDE does not show white spaces
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; + } + } |