Skip to content

Commit ca3c453

Browse files
committed
Code Coverage
refs #23
1 parent f582100 commit ca3c453

8 files changed

+105
-13
lines changed

src/DocumentLink.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,7 @@ private function setLink($name, $link)
173173
{
174174
if ( ! is_string($link) and ! is_object($link) )
175175
{
176-
throw new ValidationException('Link has to be an object or string, "' . gettype($link) . '" given.');
176+
throw new ValidationException('Link attribute has to be an object or string, "' . gettype($link) . '" given.');
177177
}
178178

179179
if ( is_string($link) )

src/ErrorLink.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ private function setLink($name, $link)
110110
{
111111
if ( ! is_string($link) and ! is_object($link) )
112112
{
113-
throw new ValidationException('Link has to be an object or string, "' . gettype($link) . '" given.');
113+
throw new ValidationException('Link attribute has to be an object or string, "' . gettype($link) . '" given.');
114114
}
115115

116116
if ( is_string($link) )

src/RelationshipLink.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,7 @@ private function setLink($name, $link)
176176
{
177177
if ( ! is_string($link) and ! is_object($link) )
178178
{
179-
throw new ValidationException('Link has to be an object or string, "' . gettype($link) . '" given.');
179+
throw new ValidationException('Link attribute has to be an object or string, "' . gettype($link) . '" given.');
180180
}
181181

182182
if ( is_string($link) )

src/Resource/ItemLink.php

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -54,14 +54,7 @@ public function __construct($object, FactoryManagerInterface $manager, AccessInt
5454

5555
$this->container = new DataContainer();
5656

57-
$object_vars = get_object_vars($object);
58-
59-
if ( count($object_vars) === 0 )
60-
{
61-
return $this;
62-
}
63-
64-
foreach ($object_vars as $name => $value)
57+
foreach (get_object_vars($object) as $name => $value)
6558
{
6659
$this->set($name, $value);
6760
}
@@ -102,7 +95,7 @@ protected function set($name, $link)
10295
// - an object ("link object") which can contain the following members:
10396
if ( ! is_object($link) and ! is_string($link) )
10497
{
105-
throw new ValidationException('Link has to be an object or string, "' . gettype($link) . '" given.');
98+
throw new ValidationException('Link attribute has to be an object or string, "' . gettype($link) . '" given.');
10699
}
107100

108101
if ( is_string($link) )

tests/unit/DocumentLinkTest.php

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,31 @@ public function testCreateWithoutObjectThrowsException($input)
114114
$link = new DocumentLink($input, $this->manager, $this->parent);
115115
}
116116

117+
/**
118+
* @dataProvider jsonValuesProvider
119+
*
120+
* test create without object or string attribute throws exception
121+
*/
122+
public function testCreateWithoutObjectOrStringAttributeThrowsException($input)
123+
{
124+
// Input must be an object
125+
if ( gettype($input) === 'string' or gettype($input) === 'object' )
126+
{
127+
return;
128+
}
129+
130+
$object = new \stdClass();
131+
$object->self = 'http://example.org/self';
132+
$object->input = $input;
133+
134+
$this->setExpectedException(
135+
'Art4\JsonApiClient\Exception\ValidationException',
136+
'Link attribute has to be an object or string, "' . gettype($input) . '" given.'
137+
);
138+
139+
$link = new DocumentLink($object, $this->manager, $this->parent);
140+
}
141+
117142
/**
118143
* @dataProvider jsonValuesProvider
119144
*

tests/unit/ErrorLinkTest.php

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,31 @@ public function testCreateWithDataprovider($input)
116116
$link = new ErrorLink($input, $this->manager);
117117
}
118118

119+
/**
120+
* @dataProvider jsonValuesProvider
121+
*
122+
* test create without object or string attribute throws exception
123+
*/
124+
public function testCreateWithoutObjectOrStringAttributeThrowsException($input)
125+
{
126+
// Input must be an object
127+
if ( gettype($input) === 'string' or gettype($input) === 'object' )
128+
{
129+
return;
130+
}
131+
132+
$object = new \stdClass();
133+
$object->about = 'http://example.org/about';
134+
$object->input = $input;
135+
136+
$this->setExpectedException(
137+
'Art4\JsonApiClient\Exception\ValidationException',
138+
'Link attribute has to be an object or string, "' . gettype($input) . '" given.'
139+
);
140+
141+
$link = new ErrorLink($object, $this->manager);
142+
}
143+
119144
/**
120145
* @dataProvider jsonValuesProvider
121146
*

tests/unit/RelationshipLinkTest.php

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -185,7 +185,7 @@ public function testPaginationNotParsedIfRelationshipIdentifierCollectionNotExis
185185
->method('has')
186186
->with($this->equalTo('data'))
187187
->will($this->returnValue(true));
188-
188+
189189
// Mock identifier item
190190
$data = $this->getMockBuilder('Art4\JsonApiClient\Resource\IdentifierInterface')
191191
->getMock();
@@ -233,6 +233,31 @@ public function testCreateWithoutObjectThrowsException($input)
233233
$link = new RelationshipLink($input, $this->manager, $this->relationship);
234234
}
235235

236+
/**
237+
* @dataProvider jsonValuesProvider
238+
*
239+
* test create without object or string attribute throws exception
240+
*/
241+
public function testCreateWithoutObjectOrStringAttributeThrowsException($input)
242+
{
243+
// Input must be an object
244+
if ( gettype($input) === 'string' or gettype($input) === 'object' )
245+
{
246+
return;
247+
}
248+
249+
$object = new \stdClass();
250+
$object->self = 'http://example.org/self';
251+
$object->input = $input;
252+
253+
$this->setExpectedException(
254+
'Art4\JsonApiClient\Exception\ValidationException',
255+
'Link attribute has to be an object or string, "' . gettype($input) . '" given.'
256+
);
257+
258+
$link = new RelationshipLink($object, $this->manager, $this->relationship);
259+
}
260+
236261
/**
237262
* @test object contains at least one of the following: self, related
238263
*/

tests/unit/Resource/ItemLinkTest.php

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,30 @@ public function testCreateWithoutObjectThrowsException($input)
7272
$link = new ItemLink($input, $this->manager, $this->parent);
7373
}
7474

75+
/**
76+
* @dataProvider jsonValuesProvider
77+
*
78+
* test create without object or string attribute throws exception
79+
*/
80+
public function testCreateWithoutObjectOrStringAttributeThrowsException($input)
81+
{
82+
// Input must be an object
83+
if ( gettype($input) === 'string' or gettype($input) === 'object' )
84+
{
85+
return;
86+
}
87+
88+
$object = new \stdClass();
89+
$object->input = $input;
90+
91+
$this->setExpectedException(
92+
'Art4\JsonApiClient\Exception\ValidationException',
93+
'Link attribute has to be an object or string, "' . gettype($input) . '" given.'
94+
);
95+
96+
$link = new ItemLink($object, $this->manager, $this->parent);
97+
}
98+
7599
/**
76100
* @test
77101
*/

0 commit comments

Comments
 (0)