Skip to content

Commit

Permalink
fix not found exception messages.
Browse files Browse the repository at this point in the history
fix fetchOne should be protected.
  • Loading branch information
cmsx committed Feb 7, 2016
1 parent 814edc9 commit ed06f6e
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 11 deletions.
20 changes: 12 additions & 8 deletions src/Zuora.php
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,11 @@ public function getOne($table, array $columns, \Closure $filtered = null)
$filtered($query);
}

return $this->fetchOne($query);
if ($result = $this->fetchOne($query)) {
return $result;
}

throw new NotFoundException($table.' not found');
}

/**
Expand All @@ -94,7 +98,11 @@ public function getOneById($table, $columns, $id)
$query = new QueryBuilder($table, $columns);
$query->where('id', '=', $id);

return $this->fetchOne($query);
if ($result = $this->fetchOne($query)) {
return $result;
}

throw new NotFoundException(sprintf('%s with id "%s" does not exists', $table, $id));
}

/**
Expand Down Expand Up @@ -468,16 +476,12 @@ protected function getIdFromArg($object)
}

/**
* @throws NotFoundException
* @return array|bool
*/
public function fetchOne(QueryBuilder $query)
protected function fetchOne(QueryBuilder $query)
{
$result = $this->api->query($query->toZoql(), 1);

if (empty($result->result->records)) {
throw new NotFoundException('Object not found');
}

return $result->result->records;
}
}
6 changes: 3 additions & 3 deletions tests/ZuoraTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ public function testGetOneReturnsProduct()
/**
* @group integration
* @expectedException \Spira\ZuoraSdk\Exception\NotFoundException
* @expectedExceptionMessage Object not found
* @expectedExceptionMessage Product not found
*/
public function testGetOneNonExistantThrowsException()
{
Expand All @@ -113,11 +113,11 @@ public function testGetOneNonExistantThrowsException()
/**
* @group integration
* @expectedException \Spira\ZuoraSdk\Exception\NotFoundException
* @expectedExceptionMessage Object not found
* @expectedExceptionMessage Product with id "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa" does not exists
*/
public function testGetOneByNonExistantIdThrowsException()
{
$this->makeZuora()->getOneById('Product', ['Id', 'Name'], uniqid());
$this->makeZuora()->getOneById('Product', ['Id', 'Name'], str_repeat('a', 32));
}

protected function getWhereLambda()
Expand Down

0 comments on commit ed06f6e

Please sign in to comment.