CacheAdapterTest.php
46 lines
| 1 | <?php |
| 2 | /** |
| 3 | * CacheAdapterTest.php |
| 4 | * |
| 5 | * @package Tests |
| 6 | * @author Michael Pratt <yo@michael-pratt.com> |
| 7 | * @link http://www.michael-pratt.com/ |
| 8 | * |
| 9 | * For the full copyright and license information, please view the LICENSE |
| 10 | * file that was distributed with this source code. |
| 11 | */ |
| 12 | namespace Embera\Cache; |
| 13 | |
| 14 | use PHPUnit\Framework\TestCase; |
| 15 | |
| 16 | class CacheAdapterTest extends TestCase |
| 17 | { |
| 18 | public function testSetAndGetMultipleCacheItemsWithFileSystem() |
| 19 | { |
| 20 | $cache = new Filesystem(sys_get_temp_dir(), mt_rand(1, 5)); |
| 21 | $cache->clear(); |
| 22 | |
| 23 | $data = [ |
| 24 | 'data_1' => md5(mt_rand(1000, 9000)), |
| 25 | 'data_2' => md5(mt_rand(1000, 9000)), |
| 26 | 'data_3' => md5(mt_rand(1000, 9000)), |
| 27 | 'data_4' => md5(mt_rand(1000, 9000)), |
| 28 | ]; |
| 29 | |
| 30 | $this->assertTrue($cache->setMultiple($data, 10)); |
| 31 | |
| 32 | $returnedData = $cache->getMultiple(array_merge(['data_5', 'data_6'], array_keys($data)), 'default value'); |
| 33 | |
| 34 | foreach ($data as $k => $v) { |
| 35 | $this->assertEquals($v, $returnedData[$k]); |
| 36 | } |
| 37 | |
| 38 | foreach (['data_5', 'data_6'] as $k) { |
| 39 | $this->assertEquals('default value', $returnedData[$k]); |
| 40 | } |
| 41 | |
| 42 | $this->assertTrue($cache->deleteMultiple(array_keys($data))); |
| 43 | } |
| 44 | |
| 45 | } |
| 46 |