9
9
10
10
namespace ZendTest \Session \SaveHandler ;
11
11
12
+ use Prophecy \Argument ;
12
13
use Zend \Session \SaveHandler \Cache ;
13
- use Zend \Cache \StorageFactory as CacheFactory ;
14
- use Zend \Cache \Storage \Adapter \AdapterInterface as CacheAdapter ;
15
14
16
15
/**
17
16
* Unit testing for DbTable include all tests for
@@ -42,13 +41,19 @@ class CacheTest extends \PHPUnit_Framework_TestCase
42
41
43
42
public function setUp ()
44
43
{
45
- $ this ->cache = CacheFactory::adapterFactory ('memory ' , ['memory_limit ' => 0 ]);
46
44
$ this ->testArray = ['foo ' => 'bar ' , 'bar ' => ['foo ' => 'bar ' ]];
47
45
}
48
46
49
47
public function testReadWrite ()
50
48
{
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 ());
52
57
53
58
$ id = '242 ' ;
54
59
@@ -60,7 +65,13 @@ public function testReadWrite()
60
65
61
66
public function testReadWriteComplex ()
62
67
{
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 ());
64
75
$ saveHandler ->open ('savepath ' , 'sessionname ' );
65
76
66
77
$ id = '242 ' ;
@@ -72,7 +83,14 @@ public function testReadWriteComplex()
72
83
73
84
public function testReadWriteTwice ()
74
85
{
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 ());
76
94
77
95
$ id = '242 ' ;
78
96
0 commit comments