public function testFallbackToDefaultRepresentations() { $config = new Configuration(); $config->setMetadataCacheImpl(new \Doctrine\Common\Cache\ArrayCache()); $config->addPathsToConfigFiles(array(__DIR__ . '/../../Entities/Typical')); $config->setDefaultRepresentations(array('Json')); $config->setDebugMode(true); $dm = $this->_getDrestManager(null, $config); $request = \Symfony\Component\HttpFoundation\Request::create('/no_rep/1', 'GET'); $response = $dm->dispatch($request); // This should 404 (as it doesnt exist) $this->assertJsonStringEqualsJsonString('{"error":["An unknown error occurred"]}', $response->getBody()); }
public function testNoRouteMatchExceptionReturnedInAcceptedFormat() { $config = new Configuration(); $config->setMetadataCacheImpl(new \Doctrine\Common\Cache\ArrayCache()); $config->addPathsToConfigFiles(array(__DIR__ . '/../Entities/Typical')); $config->setDefaultRepresentations(array('Json')); $config->setDebugMode(false); // Triggers an actual return document $dm = $this->_getDrestManager(null, $config); $representation = new \DrestCommon\Representation\Json(); $request = \Symfony\Component\HttpFoundation\Request::create('/this-doesnt-exist', 'GET', [], [], [], array('HTTP_ACCEPT' => $representation->getContentType())); /** @var \DrestCommon\Response\Response $response */ $response = $dm->dispatch($request); $this->assertInstanceOf('DrestCommon\\Response\\Response', $response); // Ensure we can decode as a json string $responseDocument = json_decode($response->getBody(), true); $this->assertTrue(isset($responseDocument['error'])); }