summaryrefslogtreecommitdiff
path: root/core/tests
diff options
context:
space:
mode:
authorBharat Mediratta <bharat@menalto.com>2009-01-14 04:12:02 +0000
committerBharat Mediratta <bharat@menalto.com>2009-01-14 04:12:02 +0000
commitf3ba69c1d67c425ffa180d082a373e5cce0c86ce (patch)
tree5ecbbe0ba96a94e3f4aadd26042c8ad1a32ef1bc /core/tests
parent02af2d8b7639fdc18fba3d69a4ca0a3f5c92b948 (diff)
Make sure that helper functions are all static. Add new
File_Structure_Test to make sure we don't regress. According to the PHP docs, the "public" keyword is implied on static functions, so remove it. Also, require private static functions to start with an _. http://php.net/manual/en/language.oop5.visibility.php
Diffstat (limited to 'core/tests')
-rw-r--r--core/tests/File_Structure_Test.php40
1 files changed, 31 insertions, 9 deletions
diff --git a/core/tests/File_Structure_Test.php b/core/tests/File_Structure_Test.php
index d1ebec81..2c6bd239 100644
--- a/core/tests/File_Structure_Test.php
+++ b/core/tests/File_Structure_Test.php
@@ -21,7 +21,6 @@ class File_Structure_Test extends Unit_Test_Case {
public function no_trailing_closing_php_tag_test() {
$dir = new GalleryCodeFilterIterator(
new RecursiveIteratorIterator(new RecursiveDirectoryIterator(DOCROOT)));
- $incorrect = array();
foreach ($dir as $file) {
if (!preg_match("|\.html\.php$|", $file->getPathname())) {
$this->assert_false(
@@ -86,15 +85,14 @@ class File_Structure_Test extends Unit_Test_Case {
}
public function no_tabs_in_our_code_test() {
- $dir = new GalleryCodeFilterIterator(
- new RecursiveIteratorIterator(new RecursiveDirectoryIterator(DOCROOT)));
- $incorrect = array();
+ $dir = new PhpCodeFilterIterator(
+ new GalleryCodeFilterIterator(
+ new RecursiveIteratorIterator(
+ new RecursiveDirectoryIterator(DOCROOT))));
foreach ($dir as $file) {
- if (substr($file->getFilename(), -4) == ".php") {
- $this->assert_false(
- preg_match('/\t/', file_get_contents($file)),
- "{$file->getPathname()} has tabs in it");
- }
+ $this->assert_false(
+ preg_match('/\t/', file_get_contents($file)),
+ "{$file->getPathname()} has tabs in it");
}
}
@@ -109,6 +107,30 @@ class File_Structure_Test extends Unit_Test_Case {
}
return $copy;
}
+
+ public function helpers_are_static_test() {
+ $dir = new PhpCodeFilterIterator(
+ new GalleryCodeFilterIterator(
+ new RecursiveIteratorIterator(
+ new RecursiveDirectoryIterator(DOCROOT))));
+ foreach ($dir as $file) {
+ if (basename(dirname($file)) == "helpers") {
+ foreach (file($file) as $line) {
+ $this->assert_true(
+ !preg_match("/\sfunction\s.*\(/", $line) ||
+ preg_match("/^\s*(private static function _|static function)/", $line),
+ "should be \"static function foo\" or \"private static function _foo\":\n" .
+ "$file\n$line\n");
+ }
+ }
+ }
+ }
+}
+
+class PhpCodeFilterIterator extends FilterIterator {
+ public function accept() {
+ return substr($this->getInnerIterator()->getPathName(), -4) == ".php";
+ }
}
class GalleryCodeFilterIterator extends FilterIterator {