Skip to content

Commit 83a59cd

Browse files
committed
Fix node update tests
1 parent a5d9faf commit 83a59cd

File tree

10 files changed

+224
-360
lines changed

10 files changed

+224
-360
lines changed

app/Repositories/Wings/DaemonConfigurationRepository.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ public function getSystemInformation(): array
3434
* @return \Psr\Http\Message\ResponseInterface
3535
* @throws \Pterodactyl\Exceptions\Http\Connection\DaemonConnectionException
3636
*/
37-
public function update(?Node $node)
37+
public function update(Node $node)
3838
{
3939
try {
4040
return $this->getHttpClient()->post(

app/Services/Helpers/SoftwareVersionService.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
use Exception;
66
use GuzzleHttp\Client;
7-
use Cake\Chronos\Chronos;
7+
use Carbon\CarbonImmutable;
88
use Illuminate\Support\Arr;
99
use Illuminate\Contracts\Cache\Repository as CacheRepository;
1010
use Pterodactyl\Exceptions\Service\Helper\CdnVersionFetchingException;
@@ -120,7 +120,7 @@ public function isLatestDaemon($version)
120120
*/
121121
protected function cacheVersionData()
122122
{
123-
return $this->cache->remember(self::VERSION_CACHE_KEY, Chronos::now()->addMinutes(config()->get('pterodactyl.cdn.cache_time', 60)), function () {
123+
return $this->cache->remember(self::VERSION_CACHE_KEY, CarbonImmutable::now()->addMinutes(config()->get('pterodactyl.cdn.cache_time', 60)), function () {
124124
try {
125125
$response = $this->client->request('GET', config()->get('pterodactyl.cdn.url'));
126126

app/Services/Nodes/NodeCreationService.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
use Ramsey\Uuid\Uuid;
66
use Illuminate\Support\Str;
77
use Pterodactyl\Models\Node;
8-
use Illuminate\Encryption\Encrypter;
8+
use Illuminate\Contracts\Encryption\Encrypter;
99
use Pterodactyl\Contracts\Repository\NodeRepositoryInterface;
1010

1111
class NodeCreationService
@@ -16,14 +16,14 @@ class NodeCreationService
1616
protected $repository;
1717

1818
/**
19-
* @var \Illuminate\Encryption\Encrypter
19+
* @var \Illuminate\Contracts\Encryption\Encrypter
2020
*/
2121
private $encrypter;
2222

2323
/**
2424
* CreationService constructor.
2525
*
26-
* @param \Illuminate\Encryption\Encrypter $encrypter
26+
* @param \Illuminate\Contracts\Encryption\Encrypter $encrypter
2727
* @param \Pterodactyl\Contracts\Repository\NodeRepositoryInterface $repository
2828
*/
2929
public function __construct(Encrypter $encrypter, NodeRepositoryInterface $repository)

tests/Unit/Services/Eggs/EggConfigurationServiceTest.php

Lines changed: 0 additions & 90 deletions
This file was deleted.

tests/Unit/Services/Eggs/Variables/VariableCreationServiceTest.php

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@
99
use Illuminate\Contracts\Validation\Factory;
1010
use Pterodactyl\Services\Eggs\Variables\VariableCreationService;
1111
use Pterodactyl\Contracts\Repository\EggVariableRepositoryInterface;
12+
use Pterodactyl\Exceptions\Service\Egg\Variable\BadValidationRuleException;
13+
use Pterodactyl\Exceptions\Service\Egg\Variable\ReservedVariableNameException;
1214

1315
class VariableCreationServiceTest extends TestCase
1416
{
@@ -91,10 +93,11 @@ public function testNullOptionValueIsPassedAsArray()
9193
* @param string $variable
9294
*
9395
* @dataProvider reservedNamesProvider
94-
* @expectedException \Pterodactyl\Exceptions\Service\Egg\Variable\ReservedVariableNameException
9596
*/
9697
public function testExceptionIsThrownIfEnvironmentVariableIsInListOfReservedNames(string $variable)
9798
{
99+
$this->expectException(ReservedVariableNameException::class);
100+
98101
$this->getService()->handle(1, ['env_variable' => $variable]);
99102
}
100103

@@ -114,12 +117,12 @@ public function testEggIdPassedInDataIsNotApplied()
114117

115118
/**
116119
* Test that validation errors due to invalid rules are caught and handled properly.
117-
*
118-
* @expectedException \Pterodactyl\Exceptions\Service\Egg\Variable\BadValidationRuleException
119-
* @expectedExceptionMessage The validation rule "hodor_door" is not a valid rule for this application.
120120
*/
121121
public function testInvalidValidationRulesResultInException()
122122
{
123+
$this->expectException(BadValidationRuleException::class);
124+
$this->expectExceptionMessage('The validation rule "hodor_door" is not a valid rule for this application.');
125+
123126
$data = ['env_variable' => 'TEST_VAR_123', 'rules' => 'string|hodorDoor'];
124127

125128
$this->validator->shouldReceive('make')->once()
@@ -135,12 +138,12 @@ public function testInvalidValidationRulesResultInException()
135138

136139
/**
137140
* Test that an exception not stemming from a bad rule is not caught.
138-
*
139-
* @expectedException \BadMethodCallException
140-
* @expectedExceptionMessage Received something, but no expectations were specified.
141141
*/
142142
public function testExceptionNotCausedByBadRuleIsNotCaught()
143143
{
144+
$this->expectException(BadMethodCallException::class);
145+
$this->expectExceptionMessage('Received something, but no expectations were specified.');
146+
144147
$data = ['env_variable' => 'TEST_VAR_123', 'rules' => 'string'];
145148

146149
$this->validator->shouldReceive('make')->once()

tests/Unit/Services/Eggs/Variables/VariableUpdateServiceTest.php

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@
1111
use Pterodactyl\Exceptions\DisplayException;
1212
use Pterodactyl\Services\Eggs\Variables\VariableUpdateService;
1313
use Pterodactyl\Contracts\Repository\EggVariableRepositoryInterface;
14+
use Pterodactyl\Exceptions\Service\Egg\Variable\BadValidationRuleException;
15+
use Pterodactyl\Exceptions\Service\Egg\Variable\ReservedVariableNameException;
1416

1517
class VariableUpdateServiceTest extends TestCase
1618
{
@@ -159,21 +161,22 @@ public function testExceptionIsThrownIfEnvironmentVariableIsNotUnique()
159161
* Test that all of the reserved variables defined in the model trigger an exception.
160162
*
161163
* @dataProvider reservedNamesProvider
162-
* @expectedException \Pterodactyl\Exceptions\Service\Egg\Variable\ReservedVariableNameException
163164
*/
164165
public function testExceptionIsThrownIfEnvironmentVariableIsInListOfReservedNames(string $variable)
165166
{
167+
$this->expectException(ReservedVariableNameException::class);
168+
166169
$this->getService()->handle($this->model, ['env_variable' => $variable]);
167170
}
168171

169172
/**
170173
* Test that validation errors due to invalid rules are caught and handled properly.
171-
*
172-
* @expectedException \Pterodactyl\Exceptions\Service\Egg\Variable\BadValidationRuleException
173-
* @expectedExceptionMessage The validation rule "hodor_door" is not a valid rule for this application.
174174
*/
175175
public function testInvalidValidationRulesResultInException()
176176
{
177+
$this->expectException(BadValidationRuleException::class);
178+
$this->expectExceptionMessage('The validation rule "hodor_door" is not a valid rule for this application.');
179+
177180
$data = ['env_variable' => 'TEST_VAR_123', 'rules' => 'string|hodorDoor'];
178181

179182
$this->repository->shouldReceive('setColumns->findCountWhere')->once()->andReturn(0);
@@ -191,12 +194,12 @@ public function testInvalidValidationRulesResultInException()
191194

192195
/**
193196
* Test that an exception not stemming from a bad rule is not caught.
194-
*
195-
* @expectedException \BadMethodCallException
196-
* @expectedExceptionMessage Received something, but no expectations were specified.
197197
*/
198198
public function testExceptionNotCausedByBadRuleIsNotCaught()
199199
{
200+
$this->expectException(BadMethodCallException::class);
201+
$this->expectExceptionMessage('Received something, but no expectations were specified.');
202+
200203
$data = ['rules' => 'string'];
201204

202205
$this->validator->shouldReceive('make')->once()

0 commit comments

Comments
 (0)