Skip to content

Commit 38ed6f6

Browse files
committed
Code coverage
1 parent fc3cd96 commit 38ed6f6

File tree

6 files changed

+62
-6
lines changed

6 files changed

+62
-6
lines changed

tests/unit/ErrorTest.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,16 @@ public function testCreateWithObjectReturnsSelf()
7878
'source' => $error->get('source')->asArray(true),
7979
'meta' => $error->get('meta')->asArray(true),
8080
));
81+
82+
// test get() with not existing key throws an exception
83+
$this->assertFalse($error->has('something'));
84+
85+
$this->setExpectedException(
86+
'Art4\JsonApiClient\Exception\AccessException',
87+
'"something" doesn\'t exist in this error object.'
88+
);
89+
90+
$error->get('something');
8191
}
8292

8393
/**

tests/unit/JsonapiTest.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,16 @@ public function testCreateWithObject()
5555
'version' => $jsonapi->get('version'),
5656
'meta' => $jsonapi->get('meta')->asArray(true),
5757
));
58+
59+
// test get() with not existing key throws an exception
60+
$this->assertFalse($jsonapi->has('something'));
61+
62+
$this->setExpectedException(
63+
'Art4\JsonApiClient\Exception\AccessException',
64+
'"something" doesn\'t exist in this jsonapi object.'
65+
);
66+
67+
$jsonapi->get('something');
5868
}
5969

6070
/**

tests/unit/LinkTest.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,16 @@ public function testCreateWithObject()
5757
'link' => $link->get('link'),
5858
'meta' => $link->get('meta')->asArray(true),
5959
));
60+
61+
// test get() with not existing key throws an exception
62+
$this->assertFalse($link->has('something'));
63+
64+
$this->setExpectedException(
65+
'Art4\JsonApiClient\Exception\AccessException',
66+
'"something" doesn\'t exist in this object.'
67+
);
68+
69+
$link->get('something');
6070
}
6171

6272
/**

tests/unit/RelationshipTest.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,16 @@ public function testCreateWithObjectReturnsSelf()
3838

3939
// Test full array
4040
$this->assertSame($relationship->asArray(true), array('meta' => $meta->asArray(true)));
41+
42+
// test get() with not existing key throws an exception
43+
$this->assertFalse($relationship->has('something'));
44+
45+
$this->setExpectedException(
46+
'Art4\JsonApiClient\Exception\AccessException',
47+
'"something" doesn\'t exist in Relationship.'
48+
);
49+
50+
$relationship->get('something');
4151
}
4252

4353
/**

tests/unit/Resource/IdentifierTest.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,10 @@ public function testGetWithUndefinedValueThrowsException()
167167
$identifier = new Identifier($object, $this->manager);
168168
$this->assertFalse($identifier->has('foobar'));
169169

170-
$this->setExpectedException('Art4\JsonApiClient\Exception\AccessException');
170+
$this->setExpectedException(
171+
'Art4\JsonApiClient\Exception\AccessException',
172+
'"foobar" doesn\'t exist in this identifier.'
173+
);
171174

172175
$identifier->get('foobar');
173176
}

tests/unit/Resource/ItemTest.php

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -25,25 +25,34 @@ public function testCreateWithObject()
2525
$object = new \stdClass();
2626
$object->type = 'type';
2727
$object->id = 789;
28-
$object->meta = new \stdClass();
2928

3029
$resource = new Item($object, $this->manager);
3130

3231
$this->assertInstanceOf('Art4\JsonApiClient\Resource\ResourceInterface', $resource);
3332
$this->assertInstanceOf('Art4\JsonApiClient\Resource\Item', $resource);
3433
$this->assertInstanceOf('Art4\JsonApiClient\AccessInterface', $resource);
35-
$this->assertSame($resource->getKeys(), array('type', 'id', 'meta'));
34+
$this->assertSame($resource->getKeys(), array('type', 'id'));
3635

3736
$this->assertSame($resource->get('type'), 'type');
3837
$this->assertSame($resource->get('id'), '789');
39-
$this->assertTrue($resource->has('meta'));
38+
$this->assertFalse($resource->has('meta'));
4039
$this->assertFalse($resource->has('attributes'));
4140
$this->assertFalse($resource->has('relationships'));
4241
$this->assertFalse($resource->has('links'));
4342
$this->assertFalse($resource->isNull());
4443
$this->assertFalse($resource->isIdentifier());
4544
$this->assertTrue($resource->isItem());
4645
$this->assertFalse($resource->isCollection());
46+
47+
// test get() with not existing key throws an exception
48+
$this->assertFalse($resource->has('something'));
49+
50+
$this->setExpectedException(
51+
'Art4\JsonApiClient\Exception\AccessException',
52+
'"something" doesn\'t exist in this resource.'
53+
);
54+
55+
$resource->get('something');
4756
}
4857

4958
/**
@@ -54,6 +63,7 @@ public function testCreateWithFullObject()
5463
$object = new \stdClass();
5564
$object->type = 'type';
5665
$object->id = 789;
66+
$object->meta = new \stdClass();
5767
$object->attributes = new \stdClass();
5868
$object->relationships = new \stdClass();
5969
$object->links = new \stdClass();
@@ -65,18 +75,20 @@ public function testCreateWithFullObject()
6575

6676
$this->assertSame($resource->get('type'), 'type');
6777
$this->assertSame($resource->get('id'), '789');
68-
$this->assertFalse($resource->has('meta'));
78+
$this->assertTrue($resource->has('meta'));
79+
$this->assertInstanceOf('Art4\JsonApiClient\Meta', $resource->get('meta'));
6980
$this->assertTrue($resource->has('attributes'));
7081
$this->assertInstanceOf('Art4\JsonApiClient\Attributes', $resource->get('attributes'));
7182
$this->assertTrue($resource->has('relationships'));
7283
$this->assertInstanceOf('Art4\JsonApiClient\RelationshipCollection', $resource->get('relationships'));
7384
$this->assertTrue($resource->has('links'));
7485
$this->assertInstanceOf('Art4\JsonApiClient\Link', $resource->get('links'));
75-
$this->assertSame($resource->getKeys(), array('type', 'id', 'attributes', 'relationships', 'links'));
86+
$this->assertSame($resource->getKeys(), array('type', 'id', 'meta', 'attributes', 'relationships', 'links'));
7687

7788
$this->assertSame($resource->asArray(), array(
7889
'type' => $resource->get('type'),
7990
'id' => $resource->get('id'),
91+
'meta' => $resource->get('meta'),
8092
'attributes' => $resource->get('attributes'),
8193
'relationships' => $resource->get('relationships'),
8294
'links' => $resource->get('links'),
@@ -86,6 +98,7 @@ public function testCreateWithFullObject()
8698
$this->assertSame($resource->asArray(true), array(
8799
'type' => $resource->get('type'),
88100
'id' => $resource->get('id'),
101+
'meta' => $resource->get('meta')->asArray(true),
89102
'attributes' => $resource->get('attributes')->asArray(true),
90103
'relationships' => $resource->get('relationships')->asArray(true),
91104
'links' => $resource->get('links')->asArray(true),

0 commit comments

Comments
 (0)