Skip to content

Commit c6112b4

Browse files
committed
Fix tests
1 parent 3bb9bf0 commit c6112b4

File tree

2 files changed

+10
-44
lines changed

2 files changed

+10
-44
lines changed

app/Services/Nodes/NodeUpdateService.php

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,4 @@
11
<?php
2-
/**
3-
* Pterodactyl - Panel
4-
* Copyright (c) 2015 - 2017 Dane Everitt <dane@daneeveritt.com>.
5-
*
6-
* This software is licensed under the terms of the MIT license.
7-
* https://opensource.org/licenses/MIT
8-
*/
92

103
namespace Pterodactyl\Services\Nodes;
114

@@ -57,7 +50,7 @@ public function __construct(
5750
*
5851
* @param \Pterodactyl\Models\Node $node
5952
* @param array $data
60-
* @return \Pterodactyl\Models\Node|mixed
53+
* @return \Pterodactyl\Models\Node
6154
*
6255
* @throws \Pterodactyl\Exceptions\DisplayException
6356
* @throws \Pterodactyl\Exceptions\Model\DataValidationException

tests/Unit/Services/Nodes/NodeUpdateServiceTest.php

Lines changed: 9 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,4 @@
11
<?php
2-
/**
3-
* Pterodactyl - Panel
4-
* Copyright (c) 2015 - 2017 Dane Everitt <dane@daneeveritt.com>.
5-
*
6-
* This software is licensed under the terms of the MIT license.
7-
* https://opensource.org/licenses/MIT
8-
*/
92

103
namespace Tests\Unit\Services\Nodes;
114

@@ -63,17 +56,17 @@ public function testNodeIsUpdatedAndDaemonSecretIsReset()
6356
->expects($this->once())->willReturn('random_string');
6457

6558
$this->connection->shouldReceive('beginTransaction')->withNoArgs()->once()->andReturnNull();
66-
$this->repository->shouldReceive('withoutFreshModel->update')->with($model->id, [
59+
$this->repository->shouldReceive('update')->with($model->id, [
6760
'name' => 'NewName',
6861
'daemonSecret' => 'random_string',
69-
])->andReturn(true);
62+
])->andReturn($model);
7063

7164
$this->configRepository->shouldReceive('setNode')->with($model)->once()->andReturnSelf()
7265
->shouldReceive('update')->withNoArgs()->once()->andReturn(new Response);
7366
$this->connection->shouldReceive('commit')->withNoArgs()->once()->andReturnNull();
7467

75-
$response = $this->getService()->returnUpdatedModel(false)->handle($model, ['name' => 'NewName', 'reset_secret' => true]);
76-
$this->assertTrue($response);
68+
$response = $this->getService()->handle($model, ['name' => 'NewName', 'reset_secret' => true]);
69+
$this->assertInstanceOf(Node::class, $response);
7770
}
7871

7972
/**
@@ -83,37 +76,17 @@ public function testNodeIsUpdatedAndDaemonSecretIsNotChanged()
8376
{
8477
$model = factory(Node::class)->make();
8578

86-
$this->connection->shouldReceive('beginTransaction')->withNoArgs()->once()->andReturnNull();
87-
$this->repository->shouldReceive('withoutFreshModel->update')->with($model->id, [
88-
'name' => 'NewName',
89-
])->andReturn(true);
90-
91-
$this->configRepository->shouldReceive('setNode')->with($model)->once()->andReturnSelf()
92-
->shouldReceive('update')->withNoArgs()->once()->andReturn(new Response);
93-
$this->connection->shouldReceive('commit')->withNoArgs()->once()->andReturnNull();
94-
95-
$response = $this->getService()->returnUpdatedModel(false)->handle($model, ['name' => 'NewName']);
96-
$this->assertTrue($response);
97-
}
98-
99-
public function testUpdatedModelIsReturned()
100-
{
101-
$model = factory(Node::class)->make();
102-
$updated = clone $model;
103-
$updated->name = 'NewName';
104-
10579
$this->connection->shouldReceive('beginTransaction')->withNoArgs()->once()->andReturnNull();
10680
$this->repository->shouldReceive('update')->with($model->id, [
107-
'name' => $updated->name,
108-
])->andReturn($updated);
81+
'name' => 'NewName',
82+
])->andReturn($model);
10983

11084
$this->configRepository->shouldReceive('setNode')->with($model)->once()->andReturnSelf()
11185
->shouldReceive('update')->withNoArgs()->once()->andReturn(new Response);
11286
$this->connection->shouldReceive('commit')->withNoArgs()->once()->andReturnNull();
11387

114-
$response = $this->getService()->returnUpdatedModel()->handle($model, ['name' => $updated->name]);
88+
$response = $this->getService()->handle($model, ['name' => 'NewName']);
11589
$this->assertInstanceOf(Node::class, $response);
116-
$this->assertSame($updated, $response);
11790
}
11891

11992
/**
@@ -127,7 +100,7 @@ public function testExceptionRelatedToConnection()
127100
$model = factory(Node::class)->make();
128101

129102
$this->connection->shouldReceive('beginTransaction')->withNoArgs()->once()->andReturnNull();
130-
$this->repository->shouldReceive('withoutFreshModel->update')->andReturn(new Response);
103+
$this->repository->shouldReceive('update')->andReturn($model);
131104

132105
$this->configRepository->shouldReceive('setNode->update')->once()->andThrow($this->getExceptionMock());
133106
$this->connection->shouldReceive('commit')->withNoArgs()->once()->andReturnNull();
@@ -146,7 +119,7 @@ public function testExceptionNotRelatedToConnection()
146119
$model = factory(Node::class)->make();
147120

148121
$this->connection->shouldReceive('beginTransaction')->withNoArgs()->once()->andReturnNull();
149-
$this->repository->shouldReceive('withoutFreshModel->update')->andReturn(new Response);
122+
$this->repository->shouldReceive('update')->andReturn($model);
150123

151124
$this->configRepository->shouldReceive('setNode->update')->once()->andThrow($this->getExceptionMock());
152125

0 commit comments

Comments
 (0)