44
55namespace SimpleSAML \Test \Store ;
66
7- use PHPUnit \Framework \{ MockObject \ MockObject , TestCase } ;
7+ use PHPUnit \Framework \TestCase ;
88use Predis \Client ;
99use SimpleSAML \{Configuration , Store };
1010
2121 */
2222class RedisStoreTest extends TestCase
2323{
24- /** @var \PHPUnit\Framework\MockObject\MockObject */
25- protected MockObject $ mocked_redis ;
24+ /** @var \Predis\Client */
25+ protected Client $ client ;
2626
2727 /** @var \SimpleSAML\Store\RedisStore */
2828 protected Store \RedisStore $ store ;
@@ -37,24 +37,43 @@ protected function setUp(): void
3737 {
3838 $ this ->config = [];
3939
40- $ this ->mocked_redis = $ this ->getMockBuilder (Client::class)
41- ->onlyMethods (['get ' , 'set ' , 'setex ' , 'del ' , 'disconnect ' , '__destruct ' ])
42- ->disableOriginalConstructor ()
43- ->getMock ();
44-
45- $ this ->mocked_redis ->method ('get ' )
46- ->will ($ this ->returnCallback ([$ this , 'getMocked ' ]));
47-
48- $ this ->mocked_redis ->method ('set ' )
49- ->will ($ this ->returnCallback ([$ this , 'setMocked ' ]));
50-
51- $ this ->mocked_redis ->method ('setex ' )
52- ->will ($ this ->returnCallback ([$ this , 'setexMocked ' ]));
53-
54- $ this ->mocked_redis ->method ('del ' )
55- ->will ($ this ->returnCallback ([$ this , 'delMocked ' ]));
56-
57- $ this ->store = new Store \RedisStore ($ this ->mocked_redis );
40+ $ this ->client = new class ($ this ) extends Client
41+ {
42+ public function __construct (
43+ protected TestCase $ unitTest
44+ ) {
45+ }
46+
47+ public function __deconstruct ()
48+ {
49+ }
50+
51+ public function disconnect (): void
52+ {
53+ }
54+
55+ public function get (string $ str ): ?string
56+ {
57+ return $ this ->unitTest ->getMocked ($ str );
58+ }
59+
60+ public function set (string $ str , mixed $ value ): void
61+ {
62+ $ this ->unitTest ->setMocked ($ str , $ value );
63+ }
64+
65+ public function setEx (string $ str , int $ expire , mixed $ value ): void
66+ {
67+ $ this ->unitTest ->setExMocked ($ str , $ expire , $ value );
68+ }
69+
70+ public function del (string $ str ): void
71+ {
72+ $ this ->unitTest ->delMocked ($ str );
73+ }
74+ };
75+
76+ $ this ->store = new Store \RedisStore ($ this ->client );
5877 }
5978
6079
@@ -72,7 +91,7 @@ public function getMocked(string $key): ?string
7291 * @param string $key
7392 * @param mixed $value
7493 */
75- public function setMocked (string $ key , $ value ): void
94+ public function setMocked (string $ key , mixed $ value ): void
7695 {
7796 $ this ->config [$ key ] = $ value ;
7897 }
@@ -83,7 +102,7 @@ public function setMocked(string $key, $value): void
83102 * @param int $expire
84103 * @param mixed $value
85104 */
86- public function setexMocked (string $ key , int $ expire , $ value ): void
105+ public function setexMocked (string $ key , int $ expire , mixed $ value ): void
87106 {
88107 // Testing expiring data is more trouble than it's worth for now
89108 $ this ->setMocked ($ key , $ value );
0 commit comments