using exception instead of null return (preventing potential NPE)

This commit is contained in:
Florent
2013-07-08 09:50:49 +02:00
parent b858179dd9
commit cf0036babb
2 changed files with 16 additions and 2 deletions

View File

@ -70,7 +70,7 @@ class UserMapper
{
$result = $this->_adapter->find($id);
if (0 == count($result)) {
return;
throw new \InvalidArgumentException("User #$id not found");
}
$row = $result->current();

View File

@ -87,4 +87,18 @@ class UserMapperTest extends \PHPUnit_Framework_TestCase
$this->assertEquals([$existing], $user);
}
/**
* @expectedException InvalidArgumentException
* @expectedExceptionMessage User #404 not found
*/
public function testNotFound()
{
$this->dbal->expects($this->once())
->method('find')
->with(404)
->will($this->returnValue([]));
$user = $this->mapper->findById(404);
}
}