Skip to content

Commit a527949

Browse files
committed
Add more location tests, more travis CI fix attempts
1 parent 579cc86 commit a527949

File tree

5 files changed

+77
-14
lines changed

5 files changed

+77
-14
lines changed

.env.travis

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
APP_ENV=testing
22
APP_DEBUG=true
3-
APP_KEY=SomeRandomString32SomeRandomString32
3+
APP_KEY=aaaaabbbbbcccccdddddeeeeefffff12
44

5-
DB_CONNECTION=tests
6-
DB_TEST_USERNAME=root
7-
DB_TEST_PASSWORD=
5+
TEST_DB_CONNECTION=tests
6+
TEST_DB_TEST_USERNAME=root
7+
TEST_DB_TEST_PASSWORD=
8+
TEST_DB_HOST=127.0.0.1
89

910
CACHE_DRIVER=array
1011
SESSION_DRIVER=array

.travis.yml

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,7 @@ dist: trusty
33
php:
44
- '7.0'
55
- '7.1'
6-
- nightly
7-
sudo: required
6+
sudo: false
87
cache:
98
directories:
109
- $HOME/.composer/cache
@@ -15,9 +14,9 @@ before_install:
1514
before_script:
1615
- phpenv config-rm xdebug.ini
1716
- cp .env.travis .env
18-
- composer install --no-interaction --no-scripts --prefer-dist --no-suggest
19-
- php artisan migrate --force -v
20-
- php artisan db:seed --force -v
17+
- composer install --no-interaction --prefer-dist --no-suggest --verbose
18+
- php artisan migrate -v
19+
- php artisan db:seed -v
2120
script:
2221
- vendor/bin/phpunit --coverage-clover=coverage.xml
2322
notifications:

config/database.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -47,11 +47,11 @@
4747

4848
'tests' => [
4949
'driver' => 'mysql',
50-
'host' => env('DB_HOST', 'localhost'),
51-
'port' => env('DB_PORT', '3306'),
52-
'database' => env('DB_DATABASE', 'travis'),
53-
'username' => env('DB_USERNAME', 'root'),
54-
'password' => env('DB_PASSWORD', ''),
50+
'host' => env('TEST_DB_HOST', 'localhost'),
51+
'port' => env('TEST_DB_PORT', '3306'),
52+
'database' => env('TEST_DB_DATABASE', 'travis'),
53+
'username' => env('TEST_DB_USERNAME', 'root'),
54+
'password' => env('TEST_DB_PASSWORD', ''),
5555
'charset' => 'utf8',
5656
'collation' => 'utf8_unicode_ci',
5757
'prefix' => '',

database/factories/ModelFactory.php

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,3 +38,22 @@
3838
'long' => $faker->catchPhrase,
3939
];
4040
});
41+
42+
$factory->define(Pterodactyl\Models\Node::class, function (Faker\Generator $faker) {
43+
return [
44+
'public' => true,
45+
'name' => $faker->firstName,
46+
'fqdn' => $faker->ipv4,
47+
'scheme' => 'http',
48+
'behind_proxy' => false,
49+
'memory' => 1024,
50+
'memory_overallocate' => 0,
51+
'disk' => 10240,
52+
'disk_overallocate' => 0,
53+
'upload_size' => 100,
54+
'daemonSecret' => $faker->uuid,
55+
'daemonListen' => 8080,
56+
'daemonSFTP' => 2022,
57+
'daemonBase' => '/srv/daemon',
58+
];
59+
});

tests/Feature/Services/LocationServiceTest.php

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@
2525
namespace Tests\Feature\Services;
2626

2727
use Illuminate\Validation\ValidationException;
28+
use Pterodactyl\Exceptions\DisplayException;
29+
use Pterodactyl\Models\Node;
2830
use Tests\TestCase;
2931
use Pterodactyl\Models\Location;
3032
use Pterodactyl\Services\LocationService;
@@ -201,4 +203,46 @@ public function testShouldThrowExceptionIfInvalidModelIdIsProvided()
201203
{
202204
$this->service->update(0, []);
203205
}
206+
207+
/**
208+
* Test that a location can be deleted normally when no nodes are attached.
209+
*/
210+
public function testShouldDeleteExistingLocation()
211+
{
212+
$location = factory(Location::class)->create();
213+
214+
$this->assertDatabaseHas('locations', [
215+
'id' => $location->id,
216+
]);
217+
218+
$model = $this->service->delete($location);
219+
220+
$this->assertTrue($model);
221+
$this->assertDatabaseMissing('locations', [
222+
'id' => $location->id,
223+
]);
224+
}
225+
226+
/**
227+
* Test that a location cannot be deleted if a node is attached to it.
228+
*
229+
* @expectedException \Pterodactyl\Exceptions\DisplayException
230+
*/
231+
public function testShouldFailToDeleteExistingLocationWithAttachedNodes()
232+
{
233+
$location = factory(Location::class)->create();
234+
$node = factory(Node::class)->create(['location_id' => $location->id]);
235+
236+
$this->assertDatabaseHas('locations', ['id' => $location->id]);
237+
$this->assertDatabaseHas('nodes', ['id' => $node->id]);
238+
239+
try {
240+
$this->service->delete($location->id);
241+
} catch (\Exception $ex) {
242+
$this->assertInstanceOf(DisplayException::class, $ex);
243+
$this->assertNotEmpty($ex->getMessage());
244+
245+
throw $ex;
246+
}
247+
}
204248
}

0 commit comments

Comments
 (0)