Skip to content

Make exceptions more precise #72

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Oct 27, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions src/Document.php
Original file line number Diff line number Diff line change
Expand Up @@ -108,11 +108,11 @@ public function setApiMeta(iterable $meta): void
public function setIncluded(ResourceObject ...$resources): void
{
if (null === $this->data) {
throw new \LogicException('Document with no data cannot contain included resources');
throw new \DomainException('Document with no data cannot contain included resources');
}
foreach ($resources as $resource) {
if (isset($this->included[(string) $resource->toIdentifier()])) {
throw new \LogicException("Resource {$resource->toIdentifier()} is already included");
throw new \DomainException("Resource {$resource->toIdentifier()} is already included");
}
$this->included[(string) $resource->toIdentifier()] = $resource;
}
Expand Down Expand Up @@ -150,7 +150,7 @@ private function enforceFullLinkage(): void
continue 2;
}
}
throw new \LogicException("Full linkage is required for {$included->toIdentifier()}");
throw new \DomainException("Full linkage is required for {$included->toIdentifier()}");
}
}
}
8 changes: 4 additions & 4 deletions src/Document/Resource/ResourceObject.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,27 +40,27 @@ public function setMeta(iterable $meta)
public function setAttribute(string $name, $value)
{
if ($this->isReservedName($name)) {
throw new \InvalidArgumentException("Can not use a reserved name '$name'");
throw new \DomainException("Can not use a reserved name '$name'");
}
if (! isValidMemberName($name)) {
throw new \OutOfBoundsException("Invalid member name '$name'");
}
if (isset($this->relationships[$name])) {
throw new \LogicException("Field '$name' already exists in relationships");
throw new \DomainException("Field '$name' already exists in relationships");
}
$this->attributes[$name] = $value;
}

public function setRelationship(string $name, Relationship $relationship)
{
if ($this->isReservedName($name)) {
throw new \InvalidArgumentException("Can not use a reserved name '$name'");
throw new \DomainException("Can not use a reserved name '$name'");
}
if (! isValidMemberName($name)) {
throw new \OutOfBoundsException("Invalid member name '$name'");
}
if (isset($this->attributes[$name])) {
throw new \LogicException("Field '$name' already exists in attributes");
throw new \DomainException("Field '$name' already exists in attributes");
}
$this->relationships[$name] = $relationship;
}
Expand Down
6 changes: 3 additions & 3 deletions test/Document/CompoundDocumentTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ public function testOfficialDocsExample()
}

/**
* @expectedException \LogicException
* @expectedException \DomainException
* @expectedExceptionMessage Full linkage is required for apples:1
* @dataProvider documentsWithoutFullLinkage
* @param Document $doc
Expand Down Expand Up @@ -269,7 +269,7 @@ public function testIncludedResourceMayBeIdentifiedByAnotherLinkedResource()

/**
* A compound document MUST NOT include more than one resource object for each type and id pair.
* @expectedException \LogicException
* @expectedException \DomainException
* @expectedExceptionMessage Resource apples:1 is already included
*/
public function testCanNotBeManyIncludedResourcesWithEqualIdentifiers()
Expand All @@ -283,7 +283,7 @@ public function testCanNotBeManyIncludedResourcesWithEqualIdentifiers()

/**
* If a document does not contain a top-level data key, the included member MUST NOT be present either.
* @expectedException \LogicException
* @expectedException \DomainException
* @expectedExceptionMessage Document with no data cannot contain included resources
*/
public function testIncludedMustOnlyBePresentWithData()
Expand Down
8 changes: 4 additions & 4 deletions test/Document/Resource/ResourceFieldsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
class ResourceFieldsTest extends TestCase
{
/**
* @expectedException \LogicException
* @expectedException \DomainException
* @expectedExceptionMessage Field 'foo' already exists in attributes
*/
public function testCanNotSetRelationshipIfAttributeExists()
Expand All @@ -32,7 +32,7 @@ public function testCanNotSetRelationshipIfAttributeExists()
}

/**
* @expectedException \LogicException
* @expectedException \DomainException
* @expectedExceptionMessage Field 'foo' already exists in relationships
*/
public function testCanNotSetAttributeIfRelationshipExists()
Expand All @@ -44,7 +44,7 @@ public function testCanNotSetAttributeIfRelationshipExists()

/**
* @param string $name
* @expectedException \InvalidArgumentException
* @expectedException \DomainException
* @expectedExceptionMessage Can not use a reserved name
* @dataProvider reservedAttributeNames
*/
Expand All @@ -56,7 +56,7 @@ public function testAttributeCanNotHaveReservedNames(string $name)

/**
* @param string $name
* @expectedException \InvalidArgumentException
* @expectedException \DomainException
* @expectedExceptionMessage Can not use a reserved name
* @dataProvider reservedAttributeNames
*/
Expand Down