/
MemcacheTest.php
83 lines (67 loc) · 2.42 KB
/
MemcacheTest.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
<?php
/*
* This file is part of the Stash package.
*
* (c) Robert Hafner <tedivm@tedivm.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Stash\Test\Handler;
use Stash\Handler\Memcache;
use Stash\Cache;
/**
* @package Stash
* @author Robert Hafner <tedivm@tedivm.com>
*/
class MemcacheTest extends AbstractHandlerTest
{
protected $handlerClass = 'Stash\Handler\Memcache';
protected $extension = 'memcache';
protected $servers = array('127.0.0.1', '11211');
private $setup = false;
protected function getOptions()
{
return array('extension' => $this->extension, 'servers' => $this->servers);
}
protected function setUp()
{
if (!$this->setup) {
$this->startTime = time();
$this->expiration = $this->startTime + 3600;
$handlerClass = $this->handlerClass;
/*if (!$handlerClass::canEnable()) {
$this->markTestSkipped('Handler class unsuited for current environment');
return;
}*/
if (!class_exists(ucfirst($this->extension))) {
$this->markTestSkipped('Test requires ' . $this->extension . ' extension');
return;
}
if (!($sock = @fsockopen($this->servers[0], $this->servers[1], $errno, $errstr, 1))) {
$this->markTestSkipped('Memcache tests require memcache server');
return;
}
fclose($sock);
$this->data['object'] = new \stdClass();
}
}
public function testConstructionOptions()
{
$key = array('apple', 'sauce');
$options = array();
$options['servers'][] = array('127.0.0.1', '11211', '50');
$options['servers'][] = array('127.0.0.1', '11211');
$options['extension'] = $this->extension;
$handler = new Memcache($options);
$stash = new Cache($handler);
$stash->setupKey($key);
$this->assertTrue($stash->store($key), 'Able to load and store memcache handler using multiple servers');
$options = array();
$options['extension'] = $this->extension;
$handler = new Memcache($options);
$stash = new Cache($handler);
$stash->setupKey($key);
$this->assertTrue($stash->store($key), 'Able to load and store memcache handler using default server');
}
}