コード例 #1
0
ファイル: FileTest.php プロジェクト: molovo/amnesia
 /**
  * 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;
 }
コード例 #2
0
ファイル: RedisTest.php プロジェクト: molovo/amnesia
 /**
  * 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);
 }
コード例 #3
0
ファイル: MemcachedTest.php プロジェクト: molovo/amnesia
 /**
  * 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;
 }
コード例 #4
0
ファイル: Application.php プロジェクト: pugphp/framework
 /**
  * Create a new application instance.
  */
 public function __construct()
 {
     // Store the instance statically
     static::$instance = $this;
     // Load the app's config
     $this->loadConfig();
     // Register the error handler
     $this->registerErrorHandler();
     // Create our request and response objects
     $this->request = new Request();
     $this->response = new Response();
     // Bootstrap the database
     Database::bootstrap($this->config->db->toArray());
     // Convert relative store paths to absolute, and bootstrap the cache
     foreach ($this->config->cache as $instance => $config) {
         $cacheStorePath = $config->store_path;
         if ($cacheStorePath !== null) {
             if (!is_dir($cacheStorePath) && is_dir(APP_ROOT . $cacheStorePath)) {
                 $this->config->cache->{$instance}->store_path = APP_ROOT . $cacheStorePath;
             }
         }
     }
     Cache::bootstrap($this->config->cache->toArray());
     // Convert relative store paths to absolute, and bootstrap the session
     $sessionStorePath = $this->config->session->store_path;
     if ($sessionStorePath !== null) {
         if (!is_dir($sessionStorePath) && is_dir(APP_ROOT . $sessionStorePath)) {
             $this->config->session->store_path = APP_ROOT . $sessionStorePath;
         }
     }
     Session::bootstrap($this->config->session);
     // Include the app routes
     require APP_ROOT . 'routes.php';
     // Register global view variables
     View::addGlobal('appName', $this->config->app->name);
     View::addGlobal('app', $this);
     View::addGlobal('input', $this->request->input);
     $this->compileAssets();
     // Execute routes
     Router::execute();
     if (PHP_SAPI !== 'cli') {
         $this->checkRoute();
     }
 }
コード例 #5
0
ファイル: InstanceTest.php プロジェクト: molovo/amnesia
 /**
  * Create the instance which we will use during testing.
  */
 public static function setUpBeforeClass()
 {
     Cache::bootstrap(['default' => ['driver' => 'redis']]);
     static::$instance = Cache::instance();
 }