File tree 3 files changed +48
-4
lines changed
3 files changed +48
-4
lines changed Original file line number Diff line number Diff line change 3
3
namespace Art4 \JsonApiClient \Tests ;
4
4
5
5
use Art4 \JsonApiClient \Attributes ;
6
+ use Art4 \JsonApiClient \Tests \Fixtures \JsonValueTrait ;
6
7
7
8
class AttributesTest extends \PHPUnit_Framework_TestCase
8
9
{
10
+ use JsonValueTrait;
11
+
9
12
/**
10
13
* @test create with object
11
14
*/
@@ -44,13 +47,20 @@ public function testCreateWithObject()
44
47
}
45
48
46
49
/**
47
- * @test create with empty object
50
+ * @dataProvider jsonValuesProvider
48
51
*/
49
- public function testCreateWithEmptyObject ( )
52
+ public function testCreateWithDataProvider ( $ input )
50
53
{
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
+ }
52
61
53
- $ this ->assertInstanceOf ('Art4\JsonApiClient\Attributes ' , new Attributes ($ object ));
62
+ $ this ->setExpectedException ('Art4\JsonApiClient\Exception\ValidationException ' );
63
+ $ error = new Attributes ($ input );
54
64
}
55
65
56
66
/**
Original file line number Diff line number Diff line change @@ -34,6 +34,23 @@ public function testOnlyAboutPropertyExists()
34
34
$ this ->assertSame ($ link ->get ('about ' ), 'http://example.org/about ' );
35
35
}
36
36
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
+
37
54
/**
38
55
* @test 'about' property can be a link object
39
56
*
Original file line number Diff line number Diff line change @@ -135,4 +135,21 @@ public function testCreateWithObjectWithoutIdThrowsException()
135
135
136
136
$ identifier = new Identifier ($ object );
137
137
}
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
+ }
138
155
}
You can’t perform that action at this time.
0 commit comments