Skip to content

Commit a78b236

Browse files
committed
Link object must have a "href" attribute
refs #23
1 parent cc4f340 commit a78b236

File tree

2 files changed

+6
-19
lines changed

2 files changed

+6
-19
lines changed

src/Link.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,11 @@ public function __construct($object, FactoryManagerInterface $manager, AccessInt
4747
throw new ValidationException('Link has to be an object, "' . gettype($object) . '" given.');
4848
}
4949

50+
if ( ! array_key_exists('href', $object) )
51+
{
52+
throw new ValidationException('Link must habe a "href" attribute.');
53+
}
54+
5055
$this->parent = $parent;
5156

5257
$this->manager = $manager;

tests/unit/LinkTest.php

Lines changed: 1 addition & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -92,31 +92,14 @@ public function testHrefHasToBeAString($input)
9292
$link = new Link($object, $this->manager, $this->parent_link);
9393
}
9494

95-
/**
96-
* @test meta attribute will be parsed as Link object inside Resource\Item
97-
*/
98-
public function testMetaIsParsedAsLinkInsideItem()
99-
{
100-
$object = new \stdClass();
101-
$object->meta = new \stdClass();
102-
103-
// Mock parent link
104-
$this->parent_link = $this->getMockBuilder('Art4\JsonApiClient\Resource\ItemInterface')
105-
->getMock();
106-
107-
$link = new Link($object, $this->manager, $this->parent_link);
108-
109-
$this->assertTrue($link->has('meta'));
110-
$this->assertInstanceOf('Art4\JsonApiClient\LinkInterface', $link->get('meta'));
111-
}
112-
11395
/**
11496
* @test meta attribute will be parsed as Meta object inside Link
11597
*/
11698
public function testMetaIsParsedAsMetaInsideItem()
11799
{
118100
$object = new \stdClass();
119101
$object->meta = new \stdClass();
102+
$object->href = 'http://example.org/href';
120103

121104
// Mock parent link
122105
$this->parent_link = $this->getMockBuilder('Art4\JsonApiClient\LinkInterface')
@@ -138,7 +121,6 @@ public function testCreateWithDataprovider($input)
138121
// A link object could be empty
139122
if ( gettype($input) === 'object' )
140123
{
141-
$this->assertInstanceOf('Art4\JsonApiClient\LinkInterface', new Link($input, $this->manager, $this->parent_link));
142124
return;
143125
}
144126

0 commit comments

Comments
 (0)