Example #1
0
 public function _getDefaultDrestConfig()
 {
     $config = new Configuration();
     $config->setMetadataCacheImpl(new \Doctrine\Common\Cache\ArrayCache());
     $config->addPathsToConfigFiles(array(__DIR__ . '/Entities'));
     $config->setDebugMode(true);
     return $config;
 }
Example #2
0
 /**
  * @expectedException \Drest\Route\NoMatchException
  */
 public function testAllowOptionsSetToFalse()
 {
     $config = new Configuration();
     $config->setMetadataCacheImpl(new \Doctrine\Common\Cache\ArrayCache());
     $config->addPathsToConfigFiles(array(__DIR__ . '/../../Entities'));
     $config->setDebugMode(true);
     $config->setAllowOptionsRequest(false);
     $dm = $this->_getDrestManager(null, $config);
     $request = \Symfony\Component\HttpFoundation\Request::create('/user/1', 'OPTIONS');
     $dm->dispatch($request);
 }
 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());
 }
Example #4
0
 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']));
 }
Example #5
0
$loader->add('Action', __DIR__ . '/../');
$loader->add('MyEvents', __DIR__ . '/../');
// Create an example doctrine application
$ormConfig = new \Doctrine\ORM\Configuration();
$pathToEntities = array(__DIR__ . '/../Entities');
$ORMDriver = $ormConfig->newDefaultAnnotationDriver($pathToEntities, false);
$ormConfig->setMetadataDriverImpl($ORMDriver);
// Do proxy stuff
$ormConfig->setProxyDir(__DIR__ . '/Entities/Proxies');
$ormConfig->setProxyNamespace('Entities\\Proxies');
$ormConfig->setAutoGenerateProxyClasses(true);
$em = \Doctrine\ORM\EntityManager::create(array('host' => 'localhost', 'user' => 'developer', 'password' => 'developer', 'dbname' => 'drest', 'driver' => 'pdo_mysql'), $ormConfig);
/********************START SETTING UP DREST CONFIGURATION***************************/
$drestConfig = new Configuration();
$drestConfig->setDetectContentOptions(array(Configuration::DETECT_CONTENT_HEADER => 'Accept', Configuration::DETECT_CONTENT_EXTENSION => true, Configuration::DETECT_CONTENT_PARAM => 'format'));
$drestConfig->setExposureDepth(3);
$drestConfig->setExposeRequestOption(Configuration::EXPOSE_REQUEST_PARAM_GET, 'expose');
$drestConfig->setMetadataCacheImpl(new \Doctrine\Common\Cache\ArrayCache());
//$drestConfig->setDebugMode(true);
$drestConfig->addPathsToConfigFiles($pathToEntities);
// Set up event manager
$evm = new Event\Manager();
//$evm->addEventListener(array('preServiceAction', 'postServiceAction', 'preRouting', 'postRouting', 'preDispatch', 'postDispatch'), new MyEvents\MyEvent());
// Set up the service action registry
$serviceActions = new Drest\Service\Action\Registry();
$serviceActions->register(new Action\Custom(), ['Entities\\User::get_user2', 'Entities\\User::get_user3']);
$emr = \Drest\EntityManagerRegistry::getSimpleManagerRegistry($em);
$drestManager = \Drest\Manager::create($emr, $drestConfig, $evm, $serviceActions);
echo $drestManager->dispatch();
//echo $drestManager->dispatch(null, null, 'Entities\User::get_user', array('id' => 1));
//echo $drestManager->dispatch(new \Zend\Http\PhpEnvironment\Request(), new Zend\Http\PhpEnvironment\Response());
Example #6
0
 /**
  * @expectedException \Drest\DrestException
  */
 public function testRunningInDebugMode()
 {
     $config = new Configuration();
     $config->setMetadataCacheImpl(new \Doctrine\Common\Cache\ArrayCache());
     $config->setDebugMode(true);
     $config->ensureProductionSettings();
 }