Skip to content

Commit cf0036b

Browse files
author
Florent
committed
using exception instead of null return (preventing potential NPE)
1 parent b858179 commit cf0036b

File tree

2 files changed

+16
-2
lines changed

2 files changed

+16
-2
lines changed

DataMapper/UserMapper.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ public function findById($id)
7070
{
7171
$result = $this->_adapter->find($id);
7272
if (0 == count($result)) {
73-
return;
73+
throw new \InvalidArgumentException("User #$id not found");
7474
}
7575
$row = $result->current();
7676

Tests/DataMapper/UserMapperTest.php

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,4 +87,18 @@ public function testRestoreMulti(User $existing)
8787
$this->assertEquals([$existing], $user);
8888
}
8989

90-
}
90+
/**
91+
* @expectedException InvalidArgumentException
92+
* @expectedExceptionMessage User #404 not found
93+
*/
94+
public function testNotFound()
95+
{
96+
$this->dbal->expects($this->once())
97+
->method('find')
98+
->with(404)
99+
->will($this->returnValue([]));
100+
101+
$user = $this->mapper->findById(404);
102+
}
103+
104+
}

0 commit comments

Comments
 (0)