/** * Test the cache can be bootstrapped when using the redis driver. * * @covers Molovo\Amnesia\Cache::bootstrap * @covers Molovo\Amnesia\Cache\Instance::__construct * @covers Molovo\Amnesia\Driver\File::__construct * @covers Molovo\Amnesia\Cache::instance */ public function testBootstrap() { $name = 'file_driver_test'; $config = [$name => ['driver' => 'file', 'store_path' => dirname(dirname(__DIR__)) . '/_data/cache/store']]; if (!is_dir($config[$name]['store_path'])) { // This is a test cache, so just let anyone write to it // to avoid having to deal with permissions issues mkdir($config[$name]['store_path'], 0777, true); } Cache::bootstrap($config); $instance = Cache::instance($name); verify($instance)->isInstanceOf(Instance::class); // Test that the driver has been instantiated correctly $property = new \ReflectionProperty(Instance::class, 'driver'); $property->setAccessible(true); $driver = $property->getValue($instance); verify($driver)->isInstanceOf(File::class); // Call a second time to test retrieval from cache $cached_instance = Cache::instance($name); // Compare hashes of the two instances to ensure they are // the same object $hash1 = spl_object_hash($instance); $hash2 = spl_object_hash($cached_instance); verify($hash1)->equals($hash2); // Store the instance so we can use it in other tests static::$instance = $instance; }
/** * Test the cache can be bootstrapped when using the memcached driver. * * @covers Molovo\Amnesia\Cache::bootstrap * @covers Molovo\Amnesia\Cache\Instance::__construct * @covers Molovo\Amnesia\Driver\Memcached::__construct * @covers Molovo\Amnesia\Cache::instance */ public function testBootstrap() { $name = 'memcached_driver_test'; $config = [$name => ['driver' => 'memcached', 'servers' => [['localhost', 11211]]]]; Cache::bootstrap($config); $instance = Cache::instance($name); verify($instance)->isInstanceOf(Instance::class); // Test that the driver has been instantiated correctly $property = new \ReflectionProperty(Instance::class, 'driver'); $property->setAccessible(true); $driver = $property->getValue($instance); verify($driver)->isInstanceOf(Memcached::class); // Call a second time to test retrieval from cache $cached_instance = Cache::instance($name); // Compare hashes of the two instances to ensure they are // the same object $hash1 = spl_object_hash($instance); $hash2 = spl_object_hash($cached_instance); verify($hash1)->equals($hash2); // Store the instance so we can use it in other tests static::$instance = $instance; }
/** * Test the cache can be bootstrapped when using the redis driver. * * @covers Molovo\Amnesia\Cache::bootstrap * @covers Molovo\Amnesia\Cache\Instance::__construct * @covers Molovo\Amnesia\Driver\Redis::__construct * @covers Molovo\Amnesia\Cache::instance */ public function testBootstrapSocket() { $name = 'redis_driver_socket_test'; $config = [$name => ['driver' => 'redis', 'socket' => '/usr/local/var/run/redis/redis.sock']]; Cache::bootstrap($config); $instance = Cache::instance($name); verify($instance)->isInstanceOf(Instance::class); // Test that the driver has been instantiated correctly $property = new \ReflectionProperty(Instance::class, 'driver'); $property->setAccessible(true); $driver = $property->getValue($instance); verify($driver)->isInstanceOf(Redis::class); // Call a second time to test retrieval from cache $cached_instance = Cache::instance($name); // Compare hashes of the two instances to ensure they are // the same object $hash1 = spl_object_hash($instance); $hash2 = spl_object_hash($cached_instance); verify($hash1)->equals($hash2); }
/** * Create the instance which we will use during testing. */ public static function setUpBeforeClass() { Cache::bootstrap(['default' => ['driver' => 'redis']]); static::$instance = Cache::instance(); }