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()); }
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()); }
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()); }
/** * Iterates through annotation definitions, any exceptions thrown will bubble up. */ public function checkDefinitions() { foreach ($this->metadataFactory->getAllClassNames() as $class) { $this->getClassMetadata($class); } }
/** * Get the metadata for a class * @param $class * @throws \Drest\DrestException * @return \Drest\Mapping\ClassMetaData */ public function getMetaDataForClass($class) { return $this->metadataFactory->getMetadataForClass($class); }