Skip to content

Commit

Permalink
Extra checks before using response and added tests for new entity
Browse files Browse the repository at this point in the history
  • Loading branch information
stephangroen committed Dec 15, 2015
1 parent 45744ff commit f2ddfae
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 5 deletions.
14 changes: 9 additions & 5 deletions src/Picqer/Financials/Moneybird/Model.php
Original file line number Diff line number Diff line change
Expand Up @@ -260,15 +260,19 @@ public function selfFromResponse($response)

foreach ($this->getSingleNestedEntities() as $key => $value)
{
$entityName = 'Picqer\Financials\Moneybird\Entities\\' . $value;
$this->$key = new $entityName($this->connection, $response[$key]);
if (isset($response[$key])) {
$entityName = 'Picqer\Financials\Moneybird\Entities\\' . $value;
$this->$key = new $entityName($this->connection, $response[$key]);
}
}

foreach ($this->getMultipleNestedEntities() as $key => $value)
{
$entityName = 'Picqer\Financials\Moneybird\Entities\\' . $value['entity'];
$instaniatedEntity = new $entityName($this->connection);
$this->$key = $instaniatedEntity->collectionFromResult($response[$key]);
if (isset($response[$key])) {
$entityName = 'Picqer\Financials\Moneybird\Entities\\' . $value['entity'];
$instaniatedEntity = new $entityName($this->connection);
$this->$key = $instaniatedEntity->collectionFromResult($response[$key]);
}
}

return $this;
Expand Down
5 changes: 5 additions & 0 deletions tests/EntityTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,11 @@ public function testContactEntity()
$this->performEntityTest('\Picqer\Financials\Moneybird\Entities\Contact');
}

public function testContactCustomFieldEntity()
{
$this->performEntityTest('\Picqer\Financials\Moneybird\Entities\ContactCustomField');
}

public function testCustomFieldEntity()
{
$this->performEntityTest('\Picqer\Financials\Moneybird\Entities\CustomField');
Expand Down

0 comments on commit f2ddfae

Please sign in to comment.