1: <?php
2:
3: /**
4: * Jyxo PHP Library
5: *
6: * LICENSE
7: *
8: * This source file is subject to the new BSD license that is bundled
9: * with this package in the file license.txt.
10: * It is also available through the world-wide-web at this URL:
11: * https://github.com/jyxo/php/blob/master/license.txt
12: */
13:
14: /**
15: * Test result.
16: *
17: * @category Jyxo
18: * @package Jyxo_Beholder
19: * @copyright Copyright (c) 2005-2011 Jyxo, s.r.o.
20: * @license https://github.com/jyxo/php/blob/master/license.txt
21: * @author Jan Matoušek
22: * @author Jaroslav Hanslík
23: */
24: class Jyxo_Beholder_Result
25: {
26: /**
27: * Success.
28: *
29: * @var string
30: */
31: const SUCCESS = 'success';
32:
33: /**
34: * Failure.
35: *
36: * @var string
37: */
38: const FAILURE = 'failure';
39:
40: /**
41: * Not-applicable test.
42: *
43: * @var string
44: */
45: const NOT_APPLICABLE = 'not-applicable';
46:
47: /**
48: * List of statuses.
49: *
50: * @var array
51: */
52: private static $statusList = array(
53: self::SUCCESS => 'OK',
54: self::FAILURE => 'FAILED',
55: self::NOT_APPLICABLE => 'NOT APPLICABLE'
56: );
57:
58: /**
59: * Status.
60: *
61: * @var boolean
62: */
63: private $status;
64:
65: /**
66: * Description.
67: *
68: * @var string
69: */
70: private $description = '';
71:
72:
73: /**
74: * Result constructor.
75: *
76: * @param string $status Result status
77: * @param string $description Status description
78: * @throws InvalidArgumentException On an unknown status
79: */
80: public function __construct($status, $description = '')
81: {
82: // Checks status
83: $status = (string) $status;
84: if (!isset(self::$statusList[$status])) {
85: throw new InvalidArgumentException(sprintf('Invalid status %s', $status));
86: }
87: $this->status = $status;
88:
89: // Sets description
90: $description = (string) $description;
91: if (empty($description)) {
92: $description = self::$statusList[$status];
93: }
94: $this->description = $description;
95: }
96:
97: /**
98: * Returns if the test was successful.
99: *
100: * @return boolean
101: */
102: public function isSuccess()
103: {
104: return ($this->status !== self::FAILURE);
105: }
106:
107: /**
108: * Returns the test status.
109: *
110: * @return string
111: */
112: public function getStatus()
113: {
114: return $this->status;
115: }
116:
117: /**
118: * Returns the status message.
119: *
120: * @return string
121: */
122: public function getStatusMessage()
123: {
124: return self::$statusList[$this->status];
125: }
126:
127: /**
128: * Returns the description.
129: *
130: * @return string
131: */
132: public function getDescription()
133: {
134: return $this->description;
135: }
136: }
137: