3 // @todo make all properties "read-only" (or as read-only as they can be in PHP)
6 public $sections = null;
8 private $_filename = '';
10 public function __construct(PHPT_SectionList
$sections, $filename)
12 assert('is_string($filename)');
14 $this->sections
= $sections;
15 $this->_filename
= $filename;
18 public function __destruct()
20 foreach ($this->sections
as $section) {
21 if (method_exists($section, '__destruct')) {
22 $section->__destruct();
27 public function run(PHPT_Reporter
$reporter)
29 $reporter->onCaseStart($this);
31 if ($this->sections
->filterByInterface('RunnableBefore')->valid()) {
32 foreach ($this->sections
as $section) {
36 $this->sections
->filterByInterface();
37 $this->sections
->FILE
->run($this);
38 if ($this->sections
->filterByInterface('RunnableAfter')->valid()) {
39 foreach ($this->sections
as $section) {
43 $reporter->onCasePass($this);
44 } catch (PHPT_Case_VetoException
$veto) {
45 $reporter->onCaseSkip($this, $veto);
46 } catch (PHPT_Case_FailureException
$failure) {
47 $reporter->onCaseFail($this, $failure);
49 $this->sections
->filterByInterface();
50 $reporter->onCaseEnd($this);
53 public function __set($key, $value)
57 $this->sections
->FILE
->leave_file
= $value;
61 $this->sections
->FILE
->contents
= $value;
66 public function __get($key)
70 return (string)$this->sections
->TEST
;
73 return $this->_filename
;
76 return (string)$this->sections
->FILE
->contents
;
80 public function is($validator)
82 return $this->_validatorFactory($validator)->is($this);
85 public function validate($validator)
87 $this->_validatorFactory($validator)->validate($this);
90 private function _validatorFactory($validator)
92 if (is_string($validator)) {
93 $validator_name = "PHPT_Case_Validator_{$validator}";
94 $validator = new $validator_name();
96 assert('$validator instanceof PHPT_Case_Validator || is_string($validator)');