Skip to content
This repository was archived by the owner on May 1, 2019. It is now read-only.

Commit f96b808

Browse files
committed
Merge pull request #418 from localheinz/fix/null
Fix: Return null if nothing was found by Mapper\Module
2 parents 5470412 + 0e1bff2 commit f96b808

5 files changed

Lines changed: 11 additions & 5 deletions

File tree

module/ZfModule/src/ZfModule/Mapper/Module.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,8 @@ public function findBy($key, $value)
146146
$select = $this->getSelect();
147147
$select->where([$key => $value]);
148148

149-
$entity = $this->select($select)->current();
149+
$entity = $this->select($select)->current() ?: null;
150+
150151
$this->getEventManager()->trigger('find', $this, ['entity' => $entity]);
151152

152153
return $entity;

module/ZfModule/src/ZfModule/Service/Module.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ public function currentUserModules()
131131
return false;
132132
}
133133

134-
if (false === $this->moduleMapper->findByUrl($repository->html_url)) {
134+
if (!$this->moduleMapper->findByUrl($repository->html_url)) {
135135
return false;
136136
}
137137

module/ZfModule/test/ZfModuleTest/Integration/Controller/IndexControllerTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -927,7 +927,7 @@ public function testRemoveActionThrowsUnexpectedValueExceptionWhenRepositoryNotP
927927
->expects($this->once())
928928
->method('findByUrl')
929929
->with($this->equalTo($unregisteredModule->html_url))
930-
->willReturn(false)
930+
->willReturn(null)
931931
;
932932

933933
$this->getApplicationServiceLocator()

module/ZfModule/test/ZfModuleTest/Integration/Mapper/ModuleTest.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,11 @@ public function testFindByLikeFindsInProperty($property)
9494
$this->assertCount(1, $resultSet);
9595
}
9696

97+
public function testFindByReturnsNullIfNothingWasFound()
98+
{
99+
$this->assertNull($this->mapper->findBy('name', 'foo'));
100+
}
101+
97102
/**
98103
* @return array
99104
*/

module/ZfModule/test/ZfModuleTest/Service/ModuleTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -221,7 +221,7 @@ public function testListUserModulesDoesNotListModulesFromApiNotFoundInDatabase()
221221
->expects($this->once())
222222
->method('findByUrl')
223223
->with($this->equalTo($repository->html_url))
224-
->willReturn(false)
224+
->willReturn(null)
225225
;
226226

227227
$currentUserService = $this->getMockBuilder(Api\CurrentUser::class)->getMock();
@@ -381,7 +381,7 @@ public function testRegisterInsertsModule()
381381
->expects($this->once())
382382
->method('findByUrl')
383383
->with($this->equalTo($repository->html_url))
384-
->willReturn(false)
384+
->willReturn(null)
385385
;
386386

387387
$moduleMapper

0 commit comments

Comments
 (0)