Skip to content

Commit

Permalink
qa: add failing test for laminas#5
Browse files Browse the repository at this point in the history
Thanks to Michael Weimann

Signed-off-by: Maximilian Bösing <2189546+boesing@users.noreply.github.com>
  • Loading branch information
boesing committed Feb 27, 2021
1 parent 0d5a299 commit e6e124b
Showing 1 changed file with 22 additions and 1 deletion.
23 changes: 22 additions & 1 deletion test/unit/MemoryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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()));
}
}

0 comments on commit e6e124b

Please sign in to comment.