Skip to content

Commit 0907b65

Browse files
committed
Code Coverage
1 parent adc25a3 commit 0907b65

File tree

1 file changed

+160
-0
lines changed

1 file changed

+160
-0
lines changed

tests/unit/RelationshipLinkTest.php

Lines changed: 160 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -168,6 +168,166 @@ public function testRelatedMustBeAString($input)
168168
$link = new RelationshipLink($object, $this->manager);
169169
}
170170

171+
/**
172+
* @dataProvider jsonValuesProvider
173+
*
174+
* Keys MUST either be omitted or have a null value to indicate that a particular link is unavailable.
175+
*/
176+
public function testFirstCanBeAStringOrNull($input)
177+
{
178+
$object = new \stdClass();
179+
$object->self = 'https://example.org/self';
180+
$object->first = $input;
181+
182+
// Input must be null or string
183+
if ( gettype($input) === 'string' )
184+
{
185+
$link = new RelationshipLink($object, $this->manager);
186+
$this->assertSame($link->getKeys(), array('self', 'first'));
187+
188+
$this->assertTrue($link->has('first'));
189+
$this->assertSame($link->get('first'), $input);
190+
191+
return;
192+
}
193+
elseif ( gettype($input) === 'NULL' )
194+
{
195+
$link = new RelationshipLink($object, $this->manager);
196+
$this->assertSame($link->getKeys(), array('self'));
197+
198+
$this->assertFalse($link->has('first'));
199+
200+
return;
201+
}
202+
203+
$this->setExpectedException(
204+
'Art4\JsonApiClient\Exception\ValidationException',
205+
'property "first" has to be a string or null, "' . gettype($input) . '" given.'
206+
);
207+
208+
$link = new RelationshipLink($object, $this->manager);
209+
}
210+
211+
/**
212+
* @dataProvider jsonValuesProvider
213+
*
214+
* Keys MUST either be omitted or have a null value to indicate that a particular link is unavailable.
215+
*/
216+
public function testLastCanBeAStringOrNull($input)
217+
{
218+
$object = new \stdClass();
219+
$object->self = 'https://example.org/self';
220+
$object->last = $input;
221+
222+
// Input must be null or string
223+
if ( gettype($input) === 'string' )
224+
{
225+
$link = new RelationshipLink($object, $this->manager);
226+
$this->assertSame($link->getKeys(), array('self', 'last'));
227+
228+
$this->assertTrue($link->has('last'));
229+
$this->assertSame($link->get('last'), $input);
230+
231+
return;
232+
}
233+
elseif ( gettype($input) === 'NULL' )
234+
{
235+
$link = new RelationshipLink($object, $this->manager);
236+
$this->assertSame($link->getKeys(), array('self'));
237+
238+
$this->assertFalse($link->has('last'));
239+
240+
return;
241+
}
242+
243+
$this->setExpectedException(
244+
'Art4\JsonApiClient\Exception\ValidationException',
245+
'property "last" has to be a string or null, "' . gettype($input) . '" given.'
246+
);
247+
248+
$link = new RelationshipLink($object, $this->manager);
249+
}
250+
251+
/**
252+
* @dataProvider jsonValuesProvider
253+
*
254+
* Keys MUST either be omitted or have a null value to indicate that a particular link is unavailable.
255+
*/
256+
public function testPrevCanBeAStringOrNull($input)
257+
{
258+
$object = new \stdClass();
259+
$object->self = 'https://example.org/self';
260+
$object->prev = $input;
261+
262+
// Input must be null or string
263+
if ( gettype($input) === 'string' )
264+
{
265+
$link = new RelationshipLink($object, $this->manager);
266+
$this->assertSame($link->getKeys(), array('self', 'prev'));
267+
268+
$this->assertTrue($link->has('prev'));
269+
$this->assertSame($link->get('prev'), $input);
270+
271+
return;
272+
}
273+
elseif ( gettype($input) === 'NULL' )
274+
{
275+
$link = new RelationshipLink($object, $this->manager);
276+
$this->assertSame($link->getKeys(), array('self'));
277+
278+
$this->assertFalse($link->has('prev'));
279+
280+
return;
281+
}
282+
283+
$this->setExpectedException(
284+
'Art4\JsonApiClient\Exception\ValidationException',
285+
'property "prev" has to be a string or null, "' . gettype($input) . '" given.'
286+
);
287+
288+
$link = new RelationshipLink($object, $this->manager);
289+
}
290+
291+
/**
292+
* @dataProvider jsonValuesProvider
293+
*
294+
* Keys MUST either be omitted or have a null value to indicate that a particular link is unavailable.
295+
*/
296+
public function testNextCanBeAStringOrNull($input)
297+
{
298+
$object = new \stdClass();
299+
$object->self = 'https://example.org/self';
300+
$object->next = $input;
301+
302+
// Input must be null or string
303+
if ( gettype($input) === 'string' )
304+
{
305+
$link = new RelationshipLink($object, $this->manager);
306+
$this->assertSame($link->getKeys(), array('self', 'next'));
307+
308+
$this->assertTrue($link->has('next'));
309+
$this->assertSame($link->get('next'), $input);
310+
311+
return;
312+
}
313+
elseif ( gettype($input) === 'NULL' )
314+
{
315+
$link = new RelationshipLink($object, $this->manager);
316+
$this->assertSame($link->getKeys(), array('self'));
317+
318+
$this->assertFalse($link->has('next'));
319+
320+
return;
321+
}
322+
323+
$this->setExpectedException(
324+
'Art4\JsonApiClient\Exception\ValidationException',
325+
'property "next" has to be a string or null, "' . gettype($input) . '" given.'
326+
);
327+
328+
$link = new RelationshipLink($object, $this->manager);
329+
}
330+
171331
/**
172332
* @test
173333
*/

0 commit comments

Comments
 (0)