public function testIsCompleteReturnsTrueWhenUrlIsSet() { $property = new Property('describedby'); $property->setUrl('http://example.com/api/docs.html'); $this->assertTrue($property->isComplete()); }
/** * Creates a property object, given metadata and a resource * * @param Metadata $metadata * @param object $object * @param null|string $id * @param null|string $routeIdentifierName * @param string $relation * @return Property * @throws Exception\RuntimeException */ public function marshalPropertyFromMetadata(Metadata $metadata, $object, $id = null, $routeIdentifierName = null, $relation = 'id') { $property = new Property($relation); if ($metadata->hasUrl()) { $property->setUrl($metadata->getUrl()); return $property; } if (!$metadata->hasRoute()) { throw new Exception\RuntimeException(sprintf('Unable to create a self property for resource of type "%s"; metadata does not contain a route or a url', get_class($object))); } $params = $metadata->getRouteParams(); // process any callbacks foreach ($params as $key => $param) { // bind to the object if supported if ($param instanceof Closure && version_compare(PHP_VERSION, '5.4.0') >= 0) { $param = $param->bindTo($object); } // pass the object for callbacks and non-bound closures if (is_callable($param)) { $params[$key] = call_user_func_array($param, [$object]); } } if ($routeIdentifierName) { $params = array_merge($params, [$routeIdentifierName => $id]); } $property->setRoute($metadata->getRoute(), $params, $metadata->getRouteOptions()); return $property; }
/** * @group 71 */ public function testRenderingCollectionRendersAllPropertiesInEmbeddedEntities() { $embedded = new Entity((object) ['id' => 'foo', 'name' => 'foo'], 'foo'); $properties = $embedded->getProperties(); $self = new Property('id'); $self->setRoute('hostname/users', ['id' => 'foo']); $properties->add($self); $phones = new Property('phones'); $phones->setUrl('http://localhost.localdomain/users/foo/phones'); $properties->add($phones); $collection = new Collection([$embedded]); $collection->setCollectionName('users'); $self = new Property('id'); $self->setRoute('hostname/users'); $collection->getProperties()->add($self); $rendered = $this->plugin->renderCollection($collection); $this->assertRelationalPropertyContains('/users', 'id', $rendered); $this->assertArrayHasKey('users', $rendered); $this->assertInternalType('array', $rendered['users']); $users = $rendered['users']; $this->assertInternalType('array', $users); $user = array_shift($users); $this->assertRelationalPropertyContains('/users/foo', 'id', $user); $this->assertRelationalPropertyContains('/users/foo/phones', 'phones', $user); }