public function testPropertyCollectionWithTwoPropertiesForSameRelationShouldReturnArrayWithOneKeyAggregatingProperties()
 {
     $propertyCollection = new PropertyCollection();
     $propertyCollection->add(Property::factory(['key' => 'foo', 'url' => 'http://example.com/foo']));
     $propertyCollection->add(Property::factory(['key' => 'foo', 'url' => 'http://example.com/bar']));
     $propertyCollection->add(Property::factory(['key' => 'baz', 'url' => 'http://example.com/baz']));
     $result = $this->propertyCollectionExtractor->extract($propertyCollection);
     $this->assertInternalType('array', $result);
     $this->assertCount(2, $result);
     $this->assertInternalType('array', $result['foo']);
     $this->assertCount(2, $result['foo']);
 }
Esempio n. 2
0
 /**
  * Inject any properties found in the metadata into the resource's property collection
  *
  * @param  Metadata $metadata
  * @param  PropertyCollection $properties
  */
 public function marshalMetadataProperties(Metadata $metadata, PropertyCollection $properties)
 {
     foreach ($metadata->getProperties() as $propertyData) {
         $property = Property::factory($propertyData);
         $properties->add($property);
     }
 }
Esempio n. 3
0
 public function testAllowsSettingAdditionalEntityProperties()
 {
     $properties = new PropertyCollection();
     $properties->add(new Property('describedby'));
     $properties->add(new Property('orders'));
     $jsonLD = new Collection([], 'item/route');
     $jsonLD->setEntityProperties($properties);
     $this->assertSame($properties, $jsonLD->getEntityProperties());
 }
Esempio n. 4
0
 /**
  * @group 102
  */
 public function testRenderingEntityTwiceMustNotDuplicatePropertyCollectionProperties()
 {
     $property = new Property('resource');
     $property->setRoute('resource', ['id' => 'user']);
     $properties = new PropertyCollection();
     $properties->add($property);
     $entity = new Entity((object) ['id' => 'user', 'name' => 'matthew', 'resources' => $properties], 'user');
     $rendered1 = $this->plugin->renderEntity($entity);
     $rendered2 = $this->plugin->renderEntity($entity);
     $this->assertEquals($rendered1, $rendered2);
 }