/**
  * @expectedException Tystr\RestOrm\Exception\InvalidArgumentException
  */
 public function testGetRepositoryThrowsExceptionIfRepositoryDoesNotImplementRepositoryInterface()
 {
     $metadata = new Metadata(new \ReflectionClass('stdClass'));
     $metadata->setRepositoryClass('stdClass');
     $this->metadataRegistry->expects($this->once())->method('getMetadataForClass')->with('stdClass')->willReturn($metadata);
     $repository = $this->factory->getRepository('stdClass');
 }
示例#2
0
 /**
  * @param string $class
  *
  * @return Metadata
  */
 public function create($class)
 {
     $reader = new AnnotationReader();
     $reflClass = new ReflectionClass($class);
     $resource = $reader->getClassAnnotation($reflClass, Resource::class);
     $hal = $reader->getClassAnnotation($reflClass, Hal::class);
     $metadata = new Metadata($reflClass);
     $metadata->setResource($resource->value);
     $metadata->setRepositoryClass($resource->repositoryClass);
     $identifier = $this->getIdentifier($reflClass, $reader);
     if (null === $identifier) {
         throw new MissingIdentifierMappingException('You must specify an identifier mapping.');
     }
     if (null !== $hal) {
         $metadata->setEmbeddedRel($hal->embeddedRel);
     }
     $metadata->setIdentifier($identifier);
     return $metadata;
 }
示例#3
0
 /**
  * @expectedException Tystr\RestOrm\Exception\InvalidArgumentException
  */
 public function testGetIdentifierValueThrowsException()
 {
     $metadata = new Metadata(new \ReflectionClass('Tystr\\RestOrm\\Model\\Blog'));
     $metadata->setIdentifier('id');
     $this->assertEquals(42, $metadata->getIdentifierValue(new \stdClass()));
 }