Ejemplo n.º 1
0
    public function testNoRepresentationIsAllowed()
    {
        $file_contents = <<<HEREDOC
<?php
\$resources = [];
\$resources['DrestTests\\Entities\\NoAnnotation\\User'] = [
    'representations' => [],
    'routes' => [
        ['name' => 'get_user', 'routePattern' => '/user/:id', 'routeConditions' => ['id' => '\\d+'], 'verbs' => ['GET'], 'action' => 'Action\\Custom'],
        ['name' => 'post_user', 'routePattern' => '/user', 'verbs' => ['POST'], 'expose' => ['username', 'email_address', 'profile' => ['firstname', 'lastname'], 'phone_numbers' => ['number']], 'handle_call' => 'populatePost']
    ]
];
return \$resources;
HEREDOC;
        $tmp = $this->createCustomTmpFile($file_contents);
        $metadataFactory = new MetadataFactory(\Drest\Mapping\Driver\PhpDriver::create([$tmp]));
        $className = 'DrestTests\\Entities\\NoAnnotation\\User';
        $cmd = $metadataFactory->getMetadataForClass($className);
        $this->assertEmpty($cmd->getRepresentations());
    }
Ejemplo n.º 2
0
 public function testClassMetadataElementName()
 {
     $metadataFactory = new MetadataFactory(\Drest\Mapping\Driver\AnnotationDriver::create(array(__DIR__ . '/../Entities/Typical')));
     $className = 'DrestTests\\Entities\\Typical\\User';
     $cmd = $metadataFactory->getMetadataForClass($className);
     $this->assertEquals('user', $cmd->getElementName());
 }
Ejemplo n.º 3
0
 public function testRemovingExtension()
 {
     $annotationDriver = \Drest\Mapping\Driver\AnnotationDriver::create(array(__DIR__ . '/../Entities/Typical'));
     $annotationDriver->removeExtensions();
     $metadataFactory = new MetadataFactory($annotationDriver);
     $this->assertCount(0, $metadataFactory->getAllClassNames());
     $annotationDriver->addExtension('php');
     $this->assertGreaterThan(0, $metadataFactory->getAllClassNames());
 }
Ejemplo n.º 4
0
 /**
  * Iterates through annotation definitions, any exceptions thrown will bubble up.
  */
 public function checkDefinitions()
 {
     foreach ($this->metadataFactory->getAllClassNames() as $class) {
         $this->getClassMetadata($class);
     }
 }
Ejemplo n.º 5
0
 /**
  * Get the metadata for a class
  * @param $class
  * @throws \Drest\DrestException
  * @return \Drest\Mapping\ClassMetaData
  */
 public function getMetaDataForClass($class)
 {
     return $this->metadataFactory->getMetadataForClass($class);
 }