add in support for building PHPT_Core from git repo and add build-specific files...
[phpt.git] / src / PHPT / Case.php
blob34a234a470d25107161e7d8ae35f8ec9e7fc2d98
1 <?php
3 // @todo make all properties "read-only" (or as read-only as they can be in PHP)
4 class PHPT_Case
6 public $sections = null;
7 public $output = 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);
30 try {
31 if ($this->sections->filterByInterface('RunnableBefore')->valid()) {
32 foreach ($this->sections as $section) {
33 $section->run($this);
36 $this->sections->filterByInterface();
37 $this->sections->FILE->run($this);
38 if ($this->sections->filterByInterface('RunnableAfter')->valid()) {
39 foreach ($this->sections as $section) {
40 $section->run($this);
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)
55 switch ($key) {
56 case 'leave_file' :
57 $this->sections->FILE->leave_file = $value;
58 break;
60 case 'code' :
61 $this->sections->FILE->contents = $value;
62 break;
66 public function __get($key)
68 switch ($key) {
69 case 'name' :
70 return (string)$this->sections->TEST;
72 case 'filename' :
73 return $this->_filename;
75 case 'code' :
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)');
97 return $validator;