/** * Test deleting a game */ public function testJsonDeleteGame() { $this->authenticate('IAmDev', 'passdev'); $games = $this->loadGames(); // find a game created by user $gamesByUser = array_filter($games, function ($item) { return $item->getOwner()->getUsername() == $this->client->getServerParameter('PHP_AUTH_USER'); }); if (empty($gamesByUser)) { $this->markTestSkipped('You need an user with games to perform a delete'); } $game = array_pop($gamesByUser); $this->client->request('DELETE', $this->getUrl('api_1_delete_game', array('slug' => $game->getSlug()))); $response = $this->client->getResponse(); $this->assertEquals($response->getStatusCode(), 204, 'The response must be 204 No Content'); // Verify that the game was well deleted $this->client->request('GET', $this->getUrl('api_1_get_game', array('slug' => $game->getSlug()))); $response = $this->client->getResponse(); $this->assertEquals($response->getStatusCode(), 404, 'The game has not been deleted as expected'); }
/** * Takes a URI and converts it to absolute if it is not already absolute. * * @param string $uri A URI * @return string An absolute URI */ public function getAbsoluteUri($uri) { // already absolute? if (0 === strpos($uri, 'http://') || 0 === strpos($uri, 'https://')) { return $uri; } $currentUri = sprintf('http%s://%s/', $this->client->getServerParameter('HTTPS') ? 's' : '', $this->client->getServerParameter('HTTP_HOST', 'localhost')); // protocol relative URL if (0 === strpos($uri, '//')) { return parse_url($currentUri, PHP_URL_SCHEME) . ':' . $uri; } // anchor? if (!$uri || '#' == $uri[0]) { return preg_replace('/#.*?$/', '', $currentUri) . $uri; } if ('/' !== $uri[0]) { $path = parse_url($currentUri, PHP_URL_PATH); if ('/' !== substr($path, -1)) { $path = substr($path, 0, strrpos($path, '/') + 1); } $uri = $path . $uri; } return preg_replace('#^(.*?//[^/]+)\\/.*$#', '$1', $currentUri) . $uri; }
/** * Gets single server parameter for specified key. * * @param string $key A key of the parameter to get * @param string $default A default value when key is undefined * * @return string A value of the parameter */ public function getServerParameter($key, $default = '') { return $this->subject->getServerParameter($key, $default); }