/**
  * @inheritdoc
  */
 public function accept(ResourceIdentifierInterface $identifier, $record = null, $key = null, ResourceInterface $resource = null)
 {
     if (!$this->current) {
         return true;
     }
     return $this->current->getType() == $identifier->getType() && $this->current->getId() == $identifier->getId();
 }
 public function testMeta()
 {
     $identifier = new ResourceIdentifier();
     $this->assertEquals(new StandardObject(), $identifier->getMeta());
     $meta = new stdClass();
     $meta->foo = 'bar';
     $expected = new StandardObject($meta);
     $identifier->set(ResourceIdentifier::META, $meta);
     $this->assertEquals($expected, $identifier->getMeta());
 }
 /**
  * @depends testMap
  */
 public function testMapWithTypeConversion(ResourceIdentifierCollection $collection)
 {
     $a = 'Alias-A';
     $b = 'Alias-B';
     $map = [$this->a->getType() => $a, $this->b->getType() => $b];
     $expected = [$a => [$this->a->getId()], $b => [$this->b->getId()]];
     $this->assertEquals($expected, $collection->map($map));
 }
Exemplo n.º 4
0
 public function testGetIdentifier()
 {
     $expected = ResourceIdentifier::create(self::TYPE, self::ID);
     $object = new Resource($this->data);
     $this->assertEquals($expected, $object->getIdentifier());
 }
Exemplo n.º 5
0
 /**
  * @param ResourceIdentifier $identifier
  * @param $object
  * @param $expectation
  * @return PHPUnit_Framework_MockObject_MockObject
  */
 private function willFind(ResourceIdentifier $identifier, $object, $expectation = null)
 {
     $expectation = $expectation ?: $this->any();
     $mock = $this->adapter($identifier->getType());
     $mock->expects($expectation)->method('find')->with($identifier)->willReturn($object);
     return $mock;
 }
Exemplo n.º 6
0
 /**
  * @param ApiInterface $api
  * @return object
  */
 protected function locateRecord(ApiInterface $api)
 {
     $interpreter = $api->getRequestInterpreter();
     if (!($id = $interpreter->getResourceId())) {
         return null;
     }
     $store = $api->getStore();
     $identifier = ResourceIdentifier::create($interpreter->getResourceType(), $id);
     $record = $store->find($identifier);
     if (!$record) {
         throw new JsonApiException([], 404);
     }
     return $record;
 }
Exemplo n.º 7
0
 /**
  * @inheritdoc
  */
 public function getIdentifier()
 {
     return ResourceIdentifier::create($this->getType(), $this->getId());
 }
 /**
  * @param ResourceCollection $resources
  * @depends testCreate
  */
 public function testGetMissingResource(ResourceCollection $resources)
 {
     $this->setExpectedException(RuntimeException::class);
     $resources->get(ResourceIdentifier::create('posts', '999'));
 }
 /**
  * @param $resourceId
  * @return $this
  */
 private function withRecord($resourceId)
 {
     $this->expectedRecord = new stdClass();
     $identifier = ResourceIdentifier::create('posts', $resourceId);
     $this->adapter->method('exists')->with($identifier)->willReturn(true);
     $this->adapter->method('find')->with($identifier)->willReturn($this->expectedRecord);
     return $this;
 }