|
| 1 | +--TEST-- |
| 2 | +UserCache\Cache: a DatePeriod whose start class the fetching process cannot load, or can only load as abstract, is unrestorable |
| 3 | +--EXTENSIONS-- |
| 4 | +pcntl |
| 5 | +--INI-- |
| 6 | +user_cache.enable=1 |
| 7 | +user_cache.enable_cli=1 |
| 8 | +user_cache.shm_size=16M |
| 9 | +date.timezone=UTC |
| 10 | +--FILE-- |
| 11 | +<?php |
| 12 | +/* The storing child declares concrete start classes; the fetching parent sees one of them only as abstract, the other not at all. */ |
| 13 | +$cache = UserCache\Cache::getPool('dateperiod-start-class'); |
| 14 | +$cache->clear(); |
| 15 | + |
| 16 | +spl_autoload_register(static function (string $class): void { |
| 17 | + echo "autoload: $class\n"; |
| 18 | + if ($class === 'UserCacheAbstractLaterStart') { |
| 19 | + eval('abstract class UserCacheAbstractLaterStart extends DateTimeImmutable {}'); |
| 20 | + } |
| 21 | +}); |
| 22 | + |
| 23 | +$pid = pcntl_fork(); |
| 24 | +if ($pid < 0) { |
| 25 | + die("fork failed\n"); |
| 26 | +} |
| 27 | +if ($pid === 0) { |
| 28 | + eval('class UserCacheAbstractLaterStart extends DateTimeImmutable {}'); |
| 29 | + eval('class UserCacheMissingLaterStart extends DateTimeImmutable {}'); |
| 30 | + $stored = $cache->store('abstract-start', new DatePeriod(new UserCacheAbstractLaterStart('2026-01-01'), new DateInterval('P1D'), 1)) |
| 31 | + && $cache->store('missing-start', new DatePeriod(new UserCacheMissingLaterStart('2026-01-01'), new DateInterval('P1D'), 1)) |
| 32 | + && $cache->store('plain-start', new DatePeriod(new DateTimeImmutable('2026-01-01'), new DateInterval('P1D'), 1)); |
| 33 | + exit($stored ? 0 : 1); |
| 34 | +} |
| 35 | +pcntl_waitpid($pid, $status); |
| 36 | +var_dump(pcntl_wexitstatus($status)); |
| 37 | + |
| 38 | +echo "stored by child:\n"; |
| 39 | +var_dump($cache->has('abstract-start'), $cache->has('missing-start'), $cache->has('plain-start')); |
| 40 | + |
| 41 | +echo "abstract start class:\n"; |
| 42 | +var_dump($cache->fetch('abstract-start', 'unrestorable')); |
| 43 | +var_dump(class_exists('UserCacheAbstractLaterStart', false)); |
| 44 | + |
| 45 | +echo "missing start class:\n"; |
| 46 | +var_dump($cache->fetch('missing-start', 'unrestorable')); |
| 47 | + |
| 48 | +echo "plain start class:\n"; |
| 49 | +$plain = $cache->fetch('plain-start', 'unrestorable'); |
| 50 | +var_dump($plain instanceof DatePeriod); |
| 51 | +var_dump($plain->getStartDate()->format('Y-m-d')); |
| 52 | + |
| 53 | +echo "unrestorable entries are dropped:\n"; |
| 54 | +var_dump($cache->has('abstract-start'), $cache->has('missing-start'), $cache->has('plain-start')); |
| 55 | +?> |
| 56 | +--EXPECT-- |
| 57 | +int(0) |
| 58 | +stored by child: |
| 59 | +bool(true) |
| 60 | +bool(true) |
| 61 | +bool(true) |
| 62 | +abstract start class: |
| 63 | +autoload: UserCacheAbstractLaterStart |
| 64 | +string(12) "unrestorable" |
| 65 | +bool(true) |
| 66 | +missing start class: |
| 67 | +autoload: UserCacheMissingLaterStart |
| 68 | +string(12) "unrestorable" |
| 69 | +plain start class: |
| 70 | +bool(true) |
| 71 | +string(10) "2026-01-01" |
| 72 | +unrestorable entries are dropped: |
| 73 | +bool(false) |
| 74 | +bool(false) |
| 75 | +bool(true) |
0 commit comments