@@ -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