14 use PHPUnit\Framework\TestCase;
33 protected function setUp()
35 if (defined(
'HHVM_VERSION')) {
36 $this->markTestSkipped(
'PHPUnit_MockObject cannot mock the Memcached class on HHVM. See https://github.com/sebastianbergmann/phpunit-mock-objects/pull/289');
41 if (version_compare(phpversion(
'memcached'),
'2.2.0',
'>=') && version_compare(phpversion(
'memcached'),
'3.0.0b1',
'<')) {
42 $this->markTestSkipped(
'Tests can only be run with memcached extension 2.1.0 or lower, or 3.0.0b1 or higher');
45 $this->memcached = $this->getMockBuilder(
'Memcached')->getMock();
46 $this->storage =
new MemcachedSessionHandler(
48 array(
'prefix' => self::PREFIX,
'expiretime' => self::TTL)
54 $this->memcached =
null;
55 $this->storage =
null;
61 $this->assertTrue($this->storage->open(
'',
''));
66 $this->assertTrue($this->storage->close());
72 ->expects($this->once())
74 ->with(self::PREFIX.
'id')
77 $this->assertEquals(
'', $this->storage->read(
'id'));
83 ->expects($this->once())
85 ->with(self::PREFIX.
'id',
'data', $this->equalTo(time() + self::TTL, 2))
86 ->will($this->returnValue(
true))
89 $this->assertTrue($this->storage->write(
'id',
'data'));
95 ->expects($this->once())
97 ->with(self::PREFIX.
'id')
98 ->will($this->returnValue(
true))
101 $this->assertTrue($this->storage->destroy(
'id'));
106 $this->assertTrue($this->storage->gc(123));
116 $this->assertTrue($supported);
117 }
catch (\InvalidArgumentException $e) {
118 $this->assertFalse($supported);
125 array(array(
'prefix' =>
'session'),
true),
126 array(array(
'expiretime' => 100),
true),
127 array(array(
'prefix' =>
'session',
'expiretime' => 200),
true),
128 array(array(
'expiretime' => 100,
'foo' =>
'bar'),
false),
134 $method = new \ReflectionMethod($this->storage,
'getMemcached');
135 $method->setAccessible(
true);
137 $this->assertInstanceOf(
'\Memcached', $method->invoke($this->storage));