From ae894c14acc99fdcec7df46aae153137c4dc2e84 Mon Sep 17 00:00:00 2001 From: Bernhard Reiter Date: Sat, 6 Dec 2014 00:55:49 +0100 Subject: [PATCH] Base VIPRestrictedClassesCheck on ClassCheckVisitor, and modify test accordingly --- .../checks/test-VIPRestrictedClassesCheck.php | 16 +++---- tests/data/VIPRestrictedClassesTest.inc | 3 ++ .../checks/VIPRestrictedClassesCheck.php | 43 +++---------------- 3 files changed, 16 insertions(+), 46 deletions(-) create mode 100644 tests/data/VIPRestrictedClassesTest.inc diff --git a/tests/checks/test-VIPRestrictedClassesCheck.php b/tests/checks/test-VIPRestrictedClassesCheck.php index cbb228e..191ca02 100644 --- a/tests/checks/test-VIPRestrictedClassesCheck.php +++ b/tests/checks/test-VIPRestrictedClassesCheck.php @@ -1,16 +1,12 @@ runCheck( $file_contents ); - - $this->assertContains( $class_name, $error_slugs ); + public function expectedErrors() { + return array( + array( 3, 'WP_User_Query', 'Note', 'Use of WP_User_Query' ), + ); } } \ No newline at end of file diff --git a/tests/data/VIPRestrictedClassesTest.inc b/tests/data/VIPRestrictedClassesTest.inc new file mode 100644 index 0000000..1fcd5fc --- /dev/null +++ b/tests/data/VIPRestrictedClassesTest.inc @@ -0,0 +1,3 @@ + array( 'level' => "Note", "note" => "Use of WP_User_Query" ), + function __construct() { + parent::__construct( + array( + // WordPress Classes + "WP_User_Query" => array( 'level' => "Note", "note" => "Use of WP_User_Query" ), + ) ); - - - foreach ( $this->filter_files( $files, 'php' ) as $file_path => $file_content ) { - foreach ( $class_names as $class_name => $check_info ) { - $this->increment_check_count(); - - if ( strpos( $file_content, $class_name ) !== false ) { - $pattern = "/\s+($class_name)+\s?\(+/msiU"; - - if ( preg_match( $pattern, $file_content, $matches ) ) { - $filename = $this->get_filename( $file_path ); - - $lines = $this->grep_content( rtrim( $matches[0], '(' ), $file_content ); - - $this->add_error( - $class_name, - $check_info['note'], - $check_info['level'], - $filename, - $lines - ); - - $result = false; - } - } - } - } - - return $result; } }