mirror of
https://github.com/DesignPatternsPHP/DesignPatternsPHP.git
synced 2025-06-27 03:33:26 +02:00
using exception instead of null return (preventing potential NPE)
This commit is contained in:
@ -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();
|
||||
|
||||
|
@ -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);
|
||||
}
|
||||
|
||||
}
|
Reference in New Issue
Block a user