public function testMapType()
 {
     $identifier = ResourceIdentifier::create(self::TYPE, self::ID);
     $expected = 'My\\Class';
     $map = ['not-a-match' => 'unexpected', static::TYPE => $expected];
     $this->assertSame($expected, $identifier->mapType($map));
     $this->setExpectedException('RuntimeException');
     $identifier->mapType(['not-a-match' => 'unexpected']);
 }
Exemplo n.º 2
0
 public function testGetIdentifier()
 {
     $expected = ResourceIdentifier::create(self::TYPE, self::ID);
     $object = new Resource($this->data);
     $this->assertEquals($expected, $object->getIdentifier());
 }
 protected function setUp()
 {
     $this->a = ResourceIdentifier::create('foo', 123);
     $this->b = ResourceIdentifier::create('bar', 456);
 }
 /**
  * AcceptImmutableRelationship constructor.
  * @param string $type
  * @param string|int|null $id
  */
 public function __construct($type, $id = null)
 {
     if ($type && $id) {
         $this->current = ResourceIdentifier::create($type, $id);
     }
 }
Exemplo n.º 5
0
 /**
  * If exists returns false and then find is called, null should be returned without the adapter
  * being queried because the store already knows it does not exist.
  */
 public function testDoesNotExistBeforeFind()
 {
     $identifier = ResourceIdentifier::create('users', '99');
     $mock = $this->adapter($identifier->getType());
     $mock->expects($this->once())->method('exists')->with($identifier)->willReturn(false);
     $mock->expects($this->never())->method('find')->with($identifier);
     $store = $this->store([$mock]);
     $this->assertFalse($store->exists($identifier));
     $this->assertNull($store->find($identifier));
 }
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;
 }