|
17 | 17 | use Phpfastcache\Core\Pool\ExtendedCacheItemPoolInterface; |
18 | 18 | use Phpfastcache\Event\EventReferenceParameter; |
19 | 19 | use Phpfastcache\EventManager; |
| 20 | +use Phpfastcache\Exceptions\PhpfastcacheInvalidTypeException; |
20 | 21 | use Phpfastcache\Tests\Helper\TestHelper; |
21 | 22 |
|
22 | 23 | chdir(__DIR__); |
|
33 | 34 | } |
34 | 35 | }); |
35 | 36 |
|
| 37 | +$eventInstance->onCacheItemSet(static function (ExtendedCacheItemInterface $item, EventReferenceParameter $eventReferenceParameter) use ($testHelper) { |
| 38 | + try{ |
| 39 | + $eventReferenceParameter->setParameterValue(1000); |
| 40 | + $testHelper->assertPass('The event reference parameter accepted a value type change'); |
| 41 | + } catch(PhpfastcacheInvalidTypeException){ |
| 42 | + $testHelper->assertFail('The event reference parameter denied a value type change'); |
| 43 | + } |
| 44 | +}); |
36 | 45 |
|
37 | 46 | $cacheKey = 'testItem'; |
38 | 47 | $cacheKey2 = 'testItem2'; |
39 | 48 |
|
40 | 49 | $item = $cacheInstance->getItem($cacheKey); |
41 | | -$item->set(1000)->expiresAfter(60); |
| 50 | +$item->set(false)->expiresAfter(60); |
42 | 51 | $cacheInstance->save($item); |
43 | 52 |
|
44 | 53 | if ($cacheInstance->getItem($cacheKey)->get() === 1337) { |
45 | 54 | $testHelper->assertPass('The dispatched event executed the custom callback to alter the item'); |
46 | 55 | } else { |
47 | | - $testHelper->assertFail("The dispatched event is not working properly, the expected value '1337', got '" . (int) $cacheInstance->getItem($cacheKey)->get() . "'"); |
| 56 | + $testHelper->assertFail("The dispatched event is not working properly, the expected value '1337', got '" . $cacheInstance->getItem($cacheKey)->get() . "'"); |
48 | 57 | } |
49 | 58 | $cacheInstance->clear(); |
50 | 59 | unset($item); |
|
53 | 62 |
|
54 | 63 | $eventInstance->onCacheSaveMultipleItems(static function (ExtendedCacheItemPoolInterface $itemPool, EventReferenceParameter $eventReferenceParameter) use ($testHelper) { |
55 | 64 | $parameterValue = $eventReferenceParameter->getParameterValue(); |
56 | | - $eventReferenceParameter->setParameterValue([]); |
| 65 | + |
| 66 | + try{ |
| 67 | + $eventReferenceParameter->setParameterValue(null); |
| 68 | + $testHelper->assertFail('The event reference parameter accepted a value type change'); |
| 69 | + } catch(PhpfastcacheInvalidTypeException){ |
| 70 | + $testHelper->assertPass('The event reference parameter denied a value type change'); |
| 71 | + $eventReferenceParameter->setParameterValue([]); |
| 72 | + } |
57 | 73 |
|
58 | 74 | if (is_array($parameterValue) && count($parameterValue) === 2) { |
59 | 75 | $testHelper->assertPass('The event reference parameter returned an array of 2 cache items'); |
|
0 commit comments