From 4da7922de607f42fc75b1132b47eae37b778ffd6 Mon Sep 17 00:00:00 2001 From: Dane Everitt Date: Sat, 5 Aug 2017 17:23:02 -0500 Subject: [PATCH] Code cleanup to use new findCountWhere function --- app/Services/Servers/DeletionService.php | 2 -- app/Services/Users/DeletionService.php | 4 ++-- app/Services/Users/UpdateService.php | 4 +--- tests/Unit/Services/Users/DeletionServiceTest.php | 9 ++++++--- 4 files changed, 9 insertions(+), 10 deletions(-) diff --git a/app/Services/Servers/DeletionService.php b/app/Services/Servers/DeletionService.php index 5d63ed094..869f17e3b 100644 --- a/app/Services/Servers/DeletionService.php +++ b/app/Services/Servers/DeletionService.php @@ -141,13 +141,11 @@ class DeletionService } $this->database->beginTransaction(); - $this->databaseRepository->withColumns('id')->findWhere([['server_id', '=', $server->id]])->each(function ($item) { $this->databaseManagementService->delete($item->id); }); $this->repository->delete($server->id); - $this->database->commit(); } } diff --git a/app/Services/Users/DeletionService.php b/app/Services/Users/DeletionService.php index 3d3077859..2c97c203d 100644 --- a/app/Services/Users/DeletionService.php +++ b/app/Services/Users/DeletionService.php @@ -78,8 +78,8 @@ class DeletionService $user = $user->id; } - $servers = $this->serverRepository->findWhere([['owner_id', '=', $user]]); - if (count($servers) > 0) { + $servers = $this->serverRepository->withColumns('id')->findCountWhere([['owner_id', '=', $user]]); + if ($servers > 0) { throw new DisplayException($this->translator->trans('admin/user.exceptions.user_has_servers')); } diff --git a/app/Services/Users/UpdateService.php b/app/Services/Users/UpdateService.php index 6df7dc583..5c1234676 100644 --- a/app/Services/Users/UpdateService.php +++ b/app/Services/Users/UpdateService.php @@ -68,8 +68,6 @@ class UpdateService $data['password'] = $this->hasher->make($data['password']); } - $user = $this->repository->update($id, $data); - - return $user; + return $this->repository->update($id, $data); } } diff --git a/tests/Unit/Services/Users/DeletionServiceTest.php b/tests/Unit/Services/Users/DeletionServiceTest.php index 85f7400b8..f067a7e00 100644 --- a/tests/Unit/Services/Users/DeletionServiceTest.php +++ b/tests/Unit/Services/Users/DeletionServiceTest.php @@ -81,7 +81,8 @@ class DeletionServiceTest extends TestCase */ public function testUserIsDeletedIfNoServersAreAttachedToAccount() { - $this->serverRepository->shouldReceive('findWhere')->with([['owner_id', '=', $this->user->id]])->once()->andReturn([]); + $this->serverRepository->shouldReceive('withColumns')->with('id')->once()->andReturnSelf() + ->shouldReceive('findCountWhere')->with([['owner_id', '=', $this->user->id]])->once()->andReturn(0); $this->repository->shouldReceive('delete')->with($this->user->id)->once()->andReturn(true); $this->assertTrue( @@ -97,7 +98,8 @@ class DeletionServiceTest extends TestCase */ public function testExceptionIsThrownIfServersAreAttachedToAccount() { - $this->serverRepository->shouldReceive('findWhere')->with([['owner_id', '=', $this->user->id]])->once()->andReturn(['item']); + $this->serverRepository->shouldReceive('withColumns')->with('id')->once()->andReturnSelf() + ->shouldReceive('findCountWhere')->with([['owner_id', '=', $this->user->id]])->once()->andReturn(1); $this->translator->shouldReceive('trans')->with('admin/user.exceptions.user_has_servers')->once()->andReturnNull(); $this->service->handle($this->user->id); @@ -108,7 +110,8 @@ class DeletionServiceTest extends TestCase */ public function testModelCanBePassedInPlaceOfUserId() { - $this->serverRepository->shouldReceive('findWhere')->with([['owner_id', '=', $this->user->id]])->once()->andReturn([]); + $this->serverRepository->shouldReceive('withColumns')->with('id')->once()->andReturnSelf() + ->shouldReceive('findCountWhere')->with([['owner_id', '=', $this->user->id]])->once()->andReturn(0); $this->repository->shouldReceive('delete')->with($this->user->id)->once()->andReturn(true); $this->assertTrue(