1: <?php
2:
3: 4: 5: 6: 7: 8: 9: 10: 11: 12:
13:
14: 15: 16: 17: 18: 19: 20: 21: 22:
23: class Jyxo_Beholder_TestCase_Memcached extends Jyxo_Beholder_TestCase
24: {
25: 26: 27: 28: 29:
30: private $ip;
31:
32: 33: 34: 35: 36:
37: private $port;
38:
39: 40: 41: 42: 43: 44: 45:
46: public function __construct($description, $ip, $port)
47: {
48: parent::__construct($description);
49:
50: $this->ip = (string) $ip;
51: $this->port = (int) $port;
52: }
53:
54: 55: 56: 57: 58:
59: public function run()
60: {
61:
62: if (!extension_loaded('memcache')) {
63: return new Jyxo_Beholder_Result(Jyxo_Beholder_Result::NOT_APPLICABLE, 'Extension memcache missing');
64: }
65:
66: $random = md5(uniqid(time(), true));
67: $key = 'beholder-' . $random;
68: $value = $random;
69:
70:
71: $description = gethostbyaddr($this->ip) . ':' . $this->port;
72:
73:
74: $memcache = new Memcache();
75: if (false === $memcache->connect($this->ip, $this->port)) {
76: return new Jyxo_Beholder_Result(Jyxo_Beholder_Result::FAILURE, sprintf('Connection error %s', $description));
77: }
78:
79:
80: if (false === $memcache->set($key, $value)) {
81: $memcache->close();
82: return new Jyxo_Beholder_Result(Jyxo_Beholder_Result::FAILURE, sprintf('Write error %s', $description));
83: }
84:
85:
86: $check = $memcache->get($key);
87: if ((false === $check) || ($check !== $value)) {
88: $memcache->close();
89: return new Jyxo_Beholder_Result(Jyxo_Beholder_Result::FAILURE, sprintf('Read error %s', $description));
90: }
91:
92:
93: if (false === $memcache->delete($key)) {
94: $memcache->close();
95: return new Jyxo_Beholder_Result(Jyxo_Beholder_Result::FAILURE, sprintf('Delete error %s', $description));
96: }
97:
98: $memcache->close();
99:
100:
101: return new Jyxo_Beholder_Result(Jyxo_Beholder_Result::SUCCESS, $description);
102: }
103: }
104: