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