File tree Expand file tree Collapse file tree 3 files changed +48
-4
lines changed Expand file tree Collapse file tree 3 files changed +48
-4
lines changed Original file line number Diff line number Diff line change 33namespace Art4 \JsonApiClient \Tests ;
44
55use Art4 \JsonApiClient \Attributes ;
6+ use Art4 \JsonApiClient \Tests \Fixtures \JsonValueTrait ;
67
78class AttributesTest extends \PHPUnit_Framework_TestCase
89{
10+ use JsonValueTrait;
11+
912 /**
1013 * @test create with object
1114 */
@@ -44,13 +47,20 @@ public function testCreateWithObject()
4447 }
4548
4649 /**
47- * @test create with empty object
50+ * @dataProvider jsonValuesProvider
4851 */
49- public function testCreateWithEmptyObject ( )
52+ public function testCreateWithDataProvider ( $ input )
5053 {
51- $ object = new \stdClass ();
54+ // Input must be an object
55+ if ( gettype ($ input ) === 'object ' )
56+ {
57+ $ this ->assertInstanceOf ('Art4\JsonApiClient\Attributes ' , new Attributes ($ input ));
58+
59+ return ;
60+ }
5261
53- $ this ->assertInstanceOf ('Art4\JsonApiClient\Attributes ' , new Attributes ($ object ));
62+ $ this ->setExpectedException ('Art4\JsonApiClient\Exception\ValidationException ' );
63+ $ error = new Attributes ($ input );
5464 }
5565
5666 /**
Original file line number Diff line number Diff line change @@ -34,6 +34,23 @@ public function testOnlyAboutPropertyExists()
3434 $ this ->assertSame ($ link ->get ('about ' ), 'http://example.org/about ' );
3535 }
3636
37+ /**
38+ * @test 'about' property must be set
39+ *
40+ * An error object MAY have the following members:
41+ * - links: a links object containing the following members:
42+ * - about: a link that leads to further details about this particular occurrence of the problem.
43+ */
44+ public function testAboutMustBeSet ()
45+ {
46+ $ object = new \stdClass ();
47+ $ object ->foobar = new \stdClass ();
48+
49+ $ this ->setExpectedException ('Art4\JsonApiClient\Exception\ValidationException ' );
50+
51+ $ link = new ErrorLink ($ object );
52+ }
53+
3754 /**
3855 * @test 'about' property can be a link object
3956 *
Original file line number Diff line number Diff line change @@ -135,4 +135,21 @@ public function testCreateWithObjectWithoutIdThrowsException()
135135
136136 $ identifier = new Identifier ($ object );
137137 }
138+
139+ /**
140+ * @test get() on an undefined value throws Exception
141+ */
142+ public function testGetWithUndefinedValueThrowsException ()
143+ {
144+ $ object = new \stdClass ();
145+ $ object ->type = 'posts ' ;
146+ $ object ->id = 9 ;
147+
148+ $ identifier = new Identifier ($ object );
149+ $ this ->assertFalse ($ identifier ->has ('foobar ' ));
150+
151+ $ this ->setExpectedException ('Art4\JsonApiClient\Exception\AccessException ' );
152+
153+ $ identifier ->get ('foobar ' );
154+ }
138155}
You can’t perform that action at this time.
0 commit comments