@@ -17,29 +17,53 @@ require __DIR__ . '/Cache.php';
1717test ('storage without bulk load support ' , function () {
1818 $ storage = new TestStorage ;
1919 $ cache = new Cache ($ storage , 'ns ' );
20+ $ cache ->onEvent [] = function (...$ args ) use (&$ event ) {
21+ $ event [] = $ args ;
22+ };
23+
2024 Assert::same ([1 => null , 2 => null ], $ cache ->bulkLoad ([1 , 2 ]), 'data ' );
25+ Assert::same ([[$ cache , $ cache ::EVENT_MISS , 1 ], [$ cache , $ cache ::EVENT_MISS , 2 ]], $ event );
2126
27+ $ event = [];
2228 Assert::same ([1 => 1 , 2 => 2 ], $ cache ->bulkLoad ([1 , 2 ], function ($ key ) {
2329 return $ key ;
2430 }));
31+ Assert::same ([
32+ [$ cache , $ cache ::EVENT_MISS , 1 ], [$ cache , $ cache ::EVENT_SAVE , 1 ],
33+ [$ cache , $ cache ::EVENT_MISS , 2 ], [$ cache , $ cache ::EVENT_SAVE , 2 ],
34+ ], $ event );
2535
36+ $ event = [];
2637 $ data = $ cache ->bulkLoad ([1 , 2 ]);
2738 Assert::same (1 , $ data [1 ]['data ' ]);
2839 Assert::same (2 , $ data [2 ]['data ' ]);
40+ Assert::same ([[$ cache , $ cache ::EVENT_HIT , 1 ], [$ cache , $ cache ::EVENT_HIT , 2 ]], $ event );
2941});
3042
3143test ('storage with bulk load support ' , function () {
3244 $ storage = new BulkReadTestStorage ;
3345 $ cache = new Cache ($ storage , 'ns ' );
46+ $ cache ->onEvent [] = function (...$ args ) use (&$ event ) {
47+ $ event [] = $ args ;
48+ };
49+
3450 Assert::same ([1 => null , 2 => null ], $ cache ->bulkLoad ([1 , 2 ]));
51+ Assert::same ([[$ cache , $ cache ::EVENT_MISS , 1 ], [$ cache , $ cache ::EVENT_MISS , 2 ]], $ event );
3552
53+ $ event = [];
3654 Assert::same ([1 => 1 , 2 => 2 ], $ cache ->bulkLoad ([1 , 2 ], function ($ key ) {
3755 return $ key ;
3856 }));
57+ Assert::same ([
58+ [$ cache , $ cache ::EVENT_MISS , 1 ], [$ cache , $ cache ::EVENT_SAVE , 1 ],
59+ [$ cache , $ cache ::EVENT_MISS , 2 ], [$ cache , $ cache ::EVENT_SAVE , 2 ],
60+ ], $ event );
3961
62+ $ event = [];
4063 $ data = $ cache ->bulkLoad ([1 , 2 ]);
4164 Assert::same (1 , $ data [1 ]['data ' ]);
4265 Assert::same (2 , $ data [2 ]['data ' ]);
66+ Assert::same ([[$ cache , $ cache ::EVENT_HIT , 1 ], [$ cache , $ cache ::EVENT_HIT , 2 ]], $ event );
4367});
4468
4569test ('dependencies ' , function () {
0 commit comments