From c6112b423478e44b2ed2bbb55b5691483358b004 Mon Sep 17 00:00:00 2001 From: Dane Everitt Date: Mon, 3 Sep 2018 14:59:00 -0700 Subject: [PATCH] Fix tests --- app/Services/Nodes/NodeUpdateService.php | 9 +--- .../Services/Nodes/NodeUpdateServiceTest.php | 45 ++++--------------- 2 files changed, 10 insertions(+), 44 deletions(-) diff --git a/app/Services/Nodes/NodeUpdateService.php b/app/Services/Nodes/NodeUpdateService.php index aaf0faed4..16cc982de 100644 --- a/app/Services/Nodes/NodeUpdateService.php +++ b/app/Services/Nodes/NodeUpdateService.php @@ -1,11 +1,4 @@ . - * - * This software is licensed under the terms of the MIT license. - * https://opensource.org/licenses/MIT - */ namespace Pterodactyl\Services\Nodes; @@ -57,7 +50,7 @@ class NodeUpdateService * * @param \Pterodactyl\Models\Node $node * @param array $data - * @return \Pterodactyl\Models\Node|mixed + * @return \Pterodactyl\Models\Node * * @throws \Pterodactyl\Exceptions\DisplayException * @throws \Pterodactyl\Exceptions\Model\DataValidationException diff --git a/tests/Unit/Services/Nodes/NodeUpdateServiceTest.php b/tests/Unit/Services/Nodes/NodeUpdateServiceTest.php index 12f2867ca..97f551330 100644 --- a/tests/Unit/Services/Nodes/NodeUpdateServiceTest.php +++ b/tests/Unit/Services/Nodes/NodeUpdateServiceTest.php @@ -1,11 +1,4 @@ . - * - * This software is licensed under the terms of the MIT license. - * https://opensource.org/licenses/MIT - */ namespace Tests\Unit\Services\Nodes; @@ -63,17 +56,17 @@ class NodeUpdateServiceTest extends TestCase ->expects($this->once())->willReturn('random_string'); $this->connection->shouldReceive('beginTransaction')->withNoArgs()->once()->andReturnNull(); - $this->repository->shouldReceive('withoutFreshModel->update')->with($model->id, [ + $this->repository->shouldReceive('update')->with($model->id, [ 'name' => 'NewName', 'daemonSecret' => 'random_string', - ])->andReturn(true); + ])->andReturn($model); $this->configRepository->shouldReceive('setNode')->with($model)->once()->andReturnSelf() ->shouldReceive('update')->withNoArgs()->once()->andReturn(new Response); $this->connection->shouldReceive('commit')->withNoArgs()->once()->andReturnNull(); - $response = $this->getService()->returnUpdatedModel(false)->handle($model, ['name' => 'NewName', 'reset_secret' => true]); - $this->assertTrue($response); + $response = $this->getService()->handle($model, ['name' => 'NewName', 'reset_secret' => true]); + $this->assertInstanceOf(Node::class, $response); } /** @@ -83,37 +76,17 @@ class NodeUpdateServiceTest extends TestCase { $model = factory(Node::class)->make(); - $this->connection->shouldReceive('beginTransaction')->withNoArgs()->once()->andReturnNull(); - $this->repository->shouldReceive('withoutFreshModel->update')->with($model->id, [ - 'name' => 'NewName', - ])->andReturn(true); - - $this->configRepository->shouldReceive('setNode')->with($model)->once()->andReturnSelf() - ->shouldReceive('update')->withNoArgs()->once()->andReturn(new Response); - $this->connection->shouldReceive('commit')->withNoArgs()->once()->andReturnNull(); - - $response = $this->getService()->returnUpdatedModel(false)->handle($model, ['name' => 'NewName']); - $this->assertTrue($response); - } - - public function testUpdatedModelIsReturned() - { - $model = factory(Node::class)->make(); - $updated = clone $model; - $updated->name = 'NewName'; - $this->connection->shouldReceive('beginTransaction')->withNoArgs()->once()->andReturnNull(); $this->repository->shouldReceive('update')->with($model->id, [ - 'name' => $updated->name, - ])->andReturn($updated); + 'name' => 'NewName', + ])->andReturn($model); $this->configRepository->shouldReceive('setNode')->with($model)->once()->andReturnSelf() ->shouldReceive('update')->withNoArgs()->once()->andReturn(new Response); $this->connection->shouldReceive('commit')->withNoArgs()->once()->andReturnNull(); - $response = $this->getService()->returnUpdatedModel()->handle($model, ['name' => $updated->name]); + $response = $this->getService()->handle($model, ['name' => 'NewName']); $this->assertInstanceOf(Node::class, $response); - $this->assertSame($updated, $response); } /** @@ -127,7 +100,7 @@ class NodeUpdateServiceTest extends TestCase $model = factory(Node::class)->make(); $this->connection->shouldReceive('beginTransaction')->withNoArgs()->once()->andReturnNull(); - $this->repository->shouldReceive('withoutFreshModel->update')->andReturn(new Response); + $this->repository->shouldReceive('update')->andReturn($model); $this->configRepository->shouldReceive('setNode->update')->once()->andThrow($this->getExceptionMock()); $this->connection->shouldReceive('commit')->withNoArgs()->once()->andReturnNull(); @@ -146,7 +119,7 @@ class NodeUpdateServiceTest extends TestCase $model = factory(Node::class)->make(); $this->connection->shouldReceive('beginTransaction')->withNoArgs()->once()->andReturnNull(); - $this->repository->shouldReceive('withoutFreshModel->update')->andReturn(new Response); + $this->repository->shouldReceive('update')->andReturn($model); $this->configRepository->shouldReceive('setNode->update')->once()->andThrow($this->getExceptionMock());