Skip to content

Commit fb07d2b

Browse files
committed
Mocked out zend-cache in tests, removed dependency on zendframework/zend-cache#22
1 parent 3976f1d commit fb07d2b

File tree

2 files changed

+26
-14
lines changed

2 files changed

+26
-14
lines changed

composer.json

+2-8
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
"zendframework/zend-stdlib": "~2.5"
1919
},
2020
"require-dev": {
21-
"zendframework/zend-cache": "dev-feature/refactor-service-event-manager as 2.6-dev",
21+
"zendframework/zend-cache": "~2.5",
2222
"zendframework/zend-db": "~2.5",
2323
"zendframework/zend-http": "~2.5",
2424
"zendframework/zend-servicemanager": "dev-develop as 2.5",
@@ -46,11 +46,5 @@
4646
"psr-4": {
4747
"ZendTest\\Session\\": "test/"
4848
}
49-
},
50-
"repositories": [
51-
{
52-
"type": "vcs",
53-
"url": "https://github.com/ezimuel/zend-cache"
54-
}
55-
]
49+
}
5650
}

test/SaveHandler/CacheTest.php

+24-6
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,8 @@
99

1010
namespace ZendTest\Session\SaveHandler;
1111

12+
use Prophecy\Argument;
1213
use Zend\Session\SaveHandler\Cache;
13-
use Zend\Cache\StorageFactory as CacheFactory;
14-
use Zend\Cache\Storage\Adapter\AdapterInterface as CacheAdapter;
1514

1615
/**
1716
* Unit testing for DbTable include all tests for
@@ -42,13 +41,19 @@ class CacheTest extends \PHPUnit_Framework_TestCase
4241

4342
public function setUp()
4443
{
45-
$this->cache = CacheFactory::adapterFactory('memory', ['memory_limit' => 0]);
4644
$this->testArray = ['foo' => 'bar', 'bar' => ['foo' => 'bar']];
4745
}
4846

4947
public function testReadWrite()
5048
{
51-
$this->usedSaveHandlers[] = $saveHandler = new Cache($this->cache);
49+
$cacheStorage = $this->prophesize('Zend\Cache\Storage\StorageInterface');
50+
$cacheStorage->setItem('242', Argument::type('string'))
51+
->will(function($args) {
52+
$this->getItem('242')->willReturn($args[1]);
53+
return true;
54+
}
55+
);
56+
$this->usedSaveHandlers[] = $saveHandler = new Cache($cacheStorage->reveal());
5257

5358
$id = '242';
5459

@@ -60,7 +65,13 @@ public function testReadWrite()
6065

6166
public function testReadWriteComplex()
6267
{
63-
$this->usedSaveHandlers[] = $saveHandler = new Cache($this->cache);
68+
$cacheStorage = $this->prophesize('Zend\Cache\Storage\StorageInterface');
69+
$cacheStorage->setItem('242', Argument::type('string'))
70+
->will(function($args) {
71+
$this->getItem('242')->willReturn($args[1]);
72+
return true;
73+
});
74+
$this->usedSaveHandlers[] = $saveHandler = new Cache($cacheStorage->reveal());
6475
$saveHandler->open('savepath', 'sessionname');
6576

6677
$id = '242';
@@ -72,7 +83,14 @@ public function testReadWriteComplex()
7283

7384
public function testReadWriteTwice()
7485
{
75-
$this->usedSaveHandlers[] = $saveHandler = new Cache($this->cache);
86+
$cacheStorage = $this->prophesize('Zend\Cache\Storage\StorageInterface');
87+
$cacheStorage->setItem('242', Argument::type('string'))
88+
->will(function($args) {
89+
$this->getItem('242')->willReturn($args[1])->shouldBeCalledTimes(2);
90+
return true;
91+
})
92+
->shouldBeCalledTimes(2);
93+
$this->usedSaveHandlers[] = $saveHandler = new Cache($cacheStorage->reveal());
7694

7795
$id = '242';
7896

0 commit comments

Comments
 (0)