Skip to content

Commit 38a3d99

Browse files
committed
Test more Exception messages
1 parent ca2c74b commit 38a3d99

File tree

3 files changed

+30
-7
lines changed

3 files changed

+30
-7
lines changed

tests/unit/Resource/CollectionTest.php

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ public function testCreateWithEmptyArray()
3434
$this->assertTrue(count($collection->asArray()) === 0);
3535
$this->assertSame($collection->getKeys(), array());
3636
$this->assertFalse($collection->has(0));
37-
37+
3838
// Test get() with various key types
3939
$this->assertFalse($collection->has(new \stdClass()));
4040
$this->assertFalse($collection->has(array()));
@@ -181,7 +181,10 @@ public function testCreateWithoutObjectInArrayThrowsException($input)
181181
return;
182182
}
183183

184-
$this->setExpectedException('Art4\JsonApiClient\Exception\ValidationException');
184+
$this->setExpectedException(
185+
'Art4\JsonApiClient\Exception\ValidationException',
186+
'Resources inside a collection MUST be objects, "' . gettype($input) . '" given.'
187+
);
185188

186189
$collection = new Collection(array($input), $this->manager);
187190
}
@@ -197,7 +200,10 @@ public function testGetResourcesWithEmptyCollectionThrowsException()
197200

198201
$this->assertFalse($collection->has(0));
199202

200-
$this->setExpectedException('Art4\JsonApiClient\Exception\AccessException');
203+
$this->setExpectedException(
204+
'Art4\JsonApiClient\Exception\AccessException',
205+
'"0" doesn\'t exist in this resource.'
206+
);
201207

202208
$collection->get(0);
203209
}

tests/unit/Resource/IdentifierTest.php

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,10 @@ public function testTypeCannotBeAnObjectOrArray($input)
8787

8888
if ( gettype($input) === 'object' or gettype($input) === 'array' )
8989
{
90-
$this->setExpectedException('Art4\JsonApiClient\Exception\ValidationException');
90+
$this->setExpectedException(
91+
'Art4\JsonApiClient\Exception\ValidationException',
92+
'Resource type cannot be an array or object'
93+
);
9194
}
9295

9396
$identifier = new Identifier($object, $this->manager);
@@ -108,7 +111,10 @@ public function testIdCannotBeAnObjectOrArray($input)
108111

109112
if ( gettype($input) === 'object' or gettype($input) === 'array' )
110113
{
111-
$this->setExpectedException('Art4\JsonApiClient\Exception\ValidationException');
114+
$this->setExpectedException(
115+
'Art4\JsonApiClient\Exception\ValidationException',
116+
'Resource Id cannot be an array or object'
117+
);
112118
}
113119

114120
$identifier = new Identifier($object, $this->manager);
@@ -124,7 +130,15 @@ public function testIdCannotBeAnObjectOrArray($input)
124130
*/
125131
public function testCreateWithDataproviderThrowsException($input)
126132
{
127-
$this->setExpectedException('Art4\JsonApiClient\Exception\ValidationException');
133+
if ( gettype($input) === 'object' )
134+
{
135+
return;
136+
}
137+
138+
$this->setExpectedException(
139+
'Art4\JsonApiClient\Exception\ValidationException',
140+
'Resource has to be an object, "' . gettype($input) . '" given.'
141+
);
128142

129143
$identifier = new Identifier($input, $this->manager);
130144
}

tests/unit/Resource/NullResourceTest.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,10 @@ public function testCreateWithDataProvider($input)
4747
*/
4848
public function testGetThrowsException()
4949
{
50-
$this->setExpectedException('Art4\JsonApiClient\Exception\AccessException', 'A NullResource has no values.');
50+
$this->setExpectedException(
51+
'Art4\JsonApiClient\Exception\AccessException',
52+
'A NullResource has no values.'
53+
);
5154

5255
$resource = new NullResource(null, $this->manager);
5356
$resource->get('something');

0 commit comments

Comments
 (0)