diff --git a/test/unit/MemoryTest.php b/test/unit/MemoryTest.php index 9ce0c83..4fd1c4f 100644 --- a/test/unit/MemoryTest.php +++ b/test/unit/MemoryTest.php @@ -9,6 +9,10 @@ namespace LaminasTest\Cache\Storage\Adapter; use Laminas\Cache; +use Laminas\Cache\Exception\OutOfSpaceException; +use function memory_get_usage; +use function mt_rand; +use function sha1; /** * @group Laminas_Cache @@ -38,7 +42,24 @@ public function testThrowOutOfSpaceException() { $this->_options->setMemoryLimit(memory_get_usage(true) - 8); - $this->expectException('Laminas\Cache\Exception\OutOfSpaceException'); + $this->expectException(OutOfSpaceException::class); $this->_storage->addItem('test', 'test'); } + + public function testReclaimMemory() + { + $this->_options->setMemoryLimit(memory_get_usage(true) + 200); + + try { + for ($i = 0; $i <= 100000; $i++) { + $this->_storage->addItem('item' . $i, sha1((string) mt_rand())); + } + + self::fail('filling the cache with test data to reach the memory limit failed'); + } catch (OutOfSpaceException $ignore) { + } + + $this->_storage->flush(); + $this->_storage->addItem('item' . $i, sha1((string) mt_rand())); + } }