'//localhost/assets/', 'img_cache_path' => _dir(ROOT_DIR, 'public/images'), 'data_cache_path' => _dir(TEST_DATA_DIR, 'cache'), 'cache' => [ 'driver' => 'null', 'connection' => [] ], 'database' => [ 'collection' => [ 'type' => 'sqlite', 'host' => '', 'user' => '', 'pass' => '', 'port' => '', 'name' => 'default', 'database' => '', 'file' => ':memory:', ], 'cache' => [ 'type' => 'sqlite', 'host' => '', 'user' => '', 'pass' => '', 'port' => '', 'name' => 'default', 'database' => '', 'file' => ':memory:', ] ], 'routes' => [ 'route_config' => [ 'asset_path' => '/assets' ], 'routes' => [ ] ], 'redis' => [ 'host' => (array_key_exists('REDIS_HOST', $_ENV)) ? $_ENV['REDIS_HOST'] : 'localhost', 'database' => 13 ] ]; // Set up DI container $di = require _dir($APP_DIR, 'bootstrap.php'); $container = $di($config_array); // Use mock session handler $container->set('session-handler', function() { $session_handler = new TestSessionHandler(); session_set_save_handler($session_handler, TRUE); return $session_handler; }); $this->container = $container; } /** * Set arbitrary superglobal values for testing purposes * * @param array $supers * @return void */ public function setSuperGlobals($supers = []) { $default = [ '_SERVER' => $_SERVER, '_GET' => $_GET, '_POST' => $_POST, '_COOKIE' => $_COOKIE, '_FILES' => $_FILES ]; $request = call_user_func_array( ['Zend\Diactoros\ServerRequestFactory', 'fromGlobals'], array_merge($default, $supers) ); $this->container->setInstance('request', $request); $this->container->set('repsone', function() { return new HttpResponse(); }); } /** * Simplify getting test data * * Takes multiple path arguments * * @return string - contents of the data file */ public function getMockFile() { $args = func_get_args(); array_unshift($args, TEST_DATA_DIR); $filePath = implode(DIRECTORY_SEPARATOR, $args); return file_get_contents($filePath); } /** * Simplify getting mocked test data * * Takes multiple path arguments * * @return mixed - the decoded data */ public function getMockFileData() { $rawData = call_user_func_array([$this, 'getMockFile'], func_get_args()); return Json::decode($rawData); } /** * Create a mock guzzle client for testing * api call methods * * @param int $code The status code * @param array $headers * @param string $body * @return Client */ public function getMockClient($code, $headers, $body) { $mock = new MockHandler([ new Response($code, $headers, $body) ]); $handler = HandlerStack::create($mock); $client = new Client(['handler' => $handler]); return $client; } } // End of AnimeClient_TestCase.php