/** * Process events * * @param Charcoal_IEventContext $context event context * * @return Charcoal_Boolean|bool */ public function processEvent($context) { $this->context = $context; /** @var Charcoal_TestEvent $event */ $event = $context->getEvent(); $is_debug = $context->isDebug(); // パラメータを取得 $section = $event->getSection(); $target = $event->getTarget(); $actions = $event->getActions(); $this->section = $section; if ($is_debug) { log_debug("debug,event", "event section: {$section}"); } if ($is_debug) { log_debug("debug,event", "event target: {$target}"); } if ($is_debug) { log_debug("debug,event", "event actions: {$actions}"); } if ($is_debug) { log_debug("debug,event", "this object path: " . $this->getObjectPath()); } if ($target != $this->getObjectPath()) { if ($is_debug) { log_debug("debug,event", "not target: " . $event); } return FALSE; } if ($is_debug) { log_debug("debug,event", "target: " . $event); } $actions = explode(',', $actions); // アクションに対するテストが記述されているか確認する $total_actions = 0; if ($actions) { foreach ($actions as $action) { $action = trim($action); if (strlen($action) === 0) { continue; } if ($this->isValidAction($action)) { $total_actions++; } } } if ($total_actions === 0) { return TRUE; } // テスト実行 $this->tests = 0; $this->asserts = 0; $this->failures = 0; echo PHP_EOL . "===================================================" . PHP_EOL; echo "Section[{$section}](total actions:{$total_actions})" . PHP_EOL . PHP_EOL; foreach ($actions as $action) { $action = trim($action); if (strlen($action) === 0) { continue; } $this->action = $action; if (!$this->isValidAction($action)) { continue; } //echo "-------------------------------------" . PHP_EOL; echo "Doing action: [{$action}] ..." . PHP_EOL; try { $this->setUp($action, $context); } catch (Exception $e) { echo "Test execution failed while setup:" . $e . PHP_EOL; return TRUE; } try { $tested = $this->test($action, $context); if ($tested) { $this->tests++; } } catch (Exception $e) { echo "[Info]Caught exception:" . get_class($e) . PHP_EOL; if ($this->expected_exception) { if ($this->expected_exception != get_class($e)) { $expected = $this->expected_exception; $actual = get_class($e); $this->message2(get_class($e), "Expected", "Actual", $expected, $actual); } } else { echo "[Warning]Test execution failed while test:" . $e . PHP_EOL; } } try { $this->cleanUp($action, $context); } catch (Exception $e) { echo "Test execution failed while clean up:" . $e . PHP_EOL; return TRUE; } echo "Action finished: [{$action}]" . PHP_EOL . PHP_EOL; } // 終了メッセージ if ($this->tests > 0) { echo "Tests complete! : [{$section}]" . PHP_EOL . PHP_EOL; echo "Tests: {$this->tests} Assertions: {$this->asserts} Failures: {$this->failures}" . PHP_EOL; } else { echo "No tests were processed." . PHP_EOL; } echo "===================================================" . PHP_EOL . PHP_EOL; return TRUE; }