review_name = $review_name; } function setUp() { // Only do the setUp once per test case, not once per function call. static $run_once; if (!isset($run_once)) { parent::setUp(); $run_once = TRUE; } } protected function assertCoderPass($code) { // Run the coder review on the code snippet. $results = coder_test($code, $this->review_name); // Display the test results. $message = 'Pass:'. str_replace(array('%s', '%d'), array('%%s', '%%d'), $code); if (count($results) == 0) { $this->assertTrue(TRUE, $message); } else { $this->assertTrue(FALSE, $message .': '. $this->getWarnings($results)); } } protected function assertCoderFail($code) { // Run the coder review on the code snippet. $results = coder_test($code, $this->review_name); // Display the test results. $message = 'Fail:'. str_replace(array('%s', '%d'), array('%%s', '%%d'), $code); if (count($results) <= 1) { $this->assertTrue(count($results) == 1, $message); } else { $this->assertTrue(FALSE, $message .': '. $this->getWarnings($results)); } } private function getWarnings($results) { $warnings = array(); foreach ($results as $error) { $warning = _coder_warning($error['rule']); if (is_array($warning)) { $warning = $warning['#warning']; } $warnings[] = $warning; } return implode('; ', $warnings); } }