Skip to content

Commit fc3cd96

Browse files
committed
Code coverage, Bug fixed
1 parent e8cc3ce commit fc3cd96

File tree

5 files changed

+54
-2
lines changed

5 files changed

+54
-2
lines changed

src/DocumentLink.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ public function __construct($object, FactoryManagerInterface $manager)
3333
{
3434
if ( ! is_object($object) )
3535
{
36-
throw new ValidationException('DocumentLinks has to be an object, "' . gettype($object) . '" given.');
36+
throw new ValidationException('DocumentLink has to be an object, "' . gettype($object) . '" given.');
3737
}
3838

3939
$this->manager = $manager;

src/RelationshipCollection.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ public function get($name)
101101
{
102102
if ( ! $this->has($name) )
103103
{
104-
throw new AccessException('"' . $key . '" doesn\'t exist in this relationship collection.');
104+
throw new AccessException('"' . $name . '" doesn\'t exist in this relationship collection.');
105105
}
106106

107107
return $this->_data[$name];

tests/unit/DocumentLinkTest.php

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,27 @@ public function testOnlySelfRelatedPaginationPropertiesExists()
6161
));
6262
}
6363

64+
/**
65+
* @dataProvider jsonValuesProvider
66+
*
67+
* links: a links object related to the primary data.
68+
*/
69+
public function testCreateWithoutObjectThrowsException($input)
70+
{
71+
// Input must be an object
72+
if ( gettype($input) === 'object' )
73+
{
74+
return;
75+
}
76+
77+
$this->setExpectedException(
78+
'Art4\JsonApiClient\Exception\ValidationException',
79+
'DocumentLink has to be an object, "' . gettype($input) . '" given.'
80+
);
81+
82+
$link = new DocumentLink($input, $this->manager);
83+
}
84+
6485
/**
6586
* @dataProvider jsonValuesProvider
6687
*

tests/unit/RelationshipCollectionTest.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,16 @@ public function testCreateWithObject()
5151
$this->assertSame($collection->asArray(true), array(
5252
'author' => $collection->get('author')->asArray(true),
5353
));
54+
55+
// test get() with not existing key throws an exception
56+
$this->assertFalse($collection->has('something'));
57+
58+
$this->setExpectedException(
59+
'Art4\JsonApiClient\Exception\AccessException',
60+
'"something" doesn\'t exist in this relationship collection.'
61+
);
62+
63+
$collection->get('something');
5464
}
5565

5666
/**

tests/unit/RelationshipLinkTest.php

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,27 @@ public function testOnlySelfRelatedPaginationPropertiesExists()
6565
));
6666
}
6767

68+
/**
69+
* @dataProvider jsonValuesProvider
70+
*
71+
* links: a links object containing at least one of the following:
72+
*/
73+
public function testCreateWithoutObjectThrowsException($input)
74+
{
75+
// Input must be an object
76+
if ( gettype($input) === 'object' )
77+
{
78+
return;
79+
}
80+
81+
$this->setExpectedException(
82+
'Art4\JsonApiClient\Exception\ValidationException',
83+
'RelationshipLink has to be an object, "' . gettype($input) . '" given.'
84+
);
85+
86+
$link = new RelationshipLink($input, $this->manager);
87+
}
88+
6889
/**
6990
* @test object contains at least one of the following: self, related
7091
*/

0 commit comments

Comments
 (0)