Skip to content

Commit 49ff3a4

Browse files
rafaelucenapatrickbrouwers
authored andcommitted
[Fix] SubstituteBindings to use findOneBy() (#346)
* fix substituteImplicitBindings using findOneBy() The function findBy() will bring back an array of results, when, for the implicit bind to work, only one entity is expected. * fix substituteImplicitBindings using findOneBy() Tests fixes
1 parent e5271e8 commit 49ff3a4

File tree

2 files changed

+2
-2
lines changed

2 files changed

+2
-2
lines changed

src/Middleware/SubstituteBindings.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ protected function substituteImplicitBindings(Route $route)
7171
if ($parameter->getClass()->implementsInterface(UrlRoutable::class)) {
7272
$name = call_user_func([$class, 'getRouteKeyName']);
7373

74-
$entity = $repository->findBy([
74+
$entity = $repository->findOneBy([
7575
$name => $id
7676
]);
7777
} else {

tests/Middleware/SubstituteBindingsTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,7 @@ public function test_not_id_binding()
161161
$entity = new BindableEntityWithInterface();
162162
$entity->id = 1;
163163
$entity->name = 'NAMEVALUE';
164-
$this->repository->shouldReceive('findBy')->once()->with(['name' => 'NAMEVALUE'])->andReturn($entity);
164+
$this->repository->shouldReceive('findOneBy')->with(['name' => 'NAMEVALUE'])->andReturn($entity);
165165

166166
$this->assertEquals(1, $router->dispatch(Request::create('foo/NAMEVALUE', 'GET'))->getContent());
167167
}

0 commit comments

Comments
 (0)