From a527949939fd2eda768f58a649de76846271fe73 Mon Sep 17 00:00:00 2001 From: Dane Everitt Date: Fri, 16 Jun 2017 00:29:19 -0500 Subject: [PATCH] Add more location tests, more travis CI fix attempts --- .env.travis | 9 ++-- .travis.yml | 9 ++-- config/database.php | 10 ++--- database/factories/ModelFactory.php | 19 ++++++++ .../Feature/Services/LocationServiceTest.php | 44 +++++++++++++++++++ 5 files changed, 77 insertions(+), 14 deletions(-) diff --git a/.env.travis b/.env.travis index c3bd08014..cd94ca8eb 100644 --- a/.env.travis +++ b/.env.travis @@ -1,10 +1,11 @@ APP_ENV=testing APP_DEBUG=true -APP_KEY=SomeRandomString32SomeRandomString32 +APP_KEY=aaaaabbbbbcccccdddddeeeeefffff12 -DB_CONNECTION=tests -DB_TEST_USERNAME=root -DB_TEST_PASSWORD= +TEST_DB_CONNECTION=tests +TEST_DB_TEST_USERNAME=root +TEST_DB_TEST_PASSWORD= +TEST_DB_HOST=127.0.0.1 CACHE_DRIVER=array SESSION_DRIVER=array diff --git a/.travis.yml b/.travis.yml index d4669f046..5fbbb1136 100644 --- a/.travis.yml +++ b/.travis.yml @@ -3,8 +3,7 @@ dist: trusty php: - '7.0' - '7.1' - - nightly -sudo: required +sudo: false cache: directories: - $HOME/.composer/cache @@ -15,9 +14,9 @@ before_install: before_script: - phpenv config-rm xdebug.ini - cp .env.travis .env - - composer install --no-interaction --no-scripts --prefer-dist --no-suggest - - php artisan migrate --force -v - - php artisan db:seed --force -v + - composer install --no-interaction --prefer-dist --no-suggest --verbose + - php artisan migrate -v + - php artisan db:seed -v script: - vendor/bin/phpunit --coverage-clover=coverage.xml notifications: diff --git a/config/database.php b/config/database.php index 00d447623..01fa16234 100644 --- a/config/database.php +++ b/config/database.php @@ -47,11 +47,11 @@ return [ 'tests' => [ 'driver' => 'mysql', - 'host' => env('DB_HOST', 'localhost'), - 'port' => env('DB_PORT', '3306'), - 'database' => env('DB_DATABASE', 'travis'), - 'username' => env('DB_USERNAME', 'root'), - 'password' => env('DB_PASSWORD', ''), + 'host' => env('TEST_DB_HOST', 'localhost'), + 'port' => env('TEST_DB_PORT', '3306'), + 'database' => env('TEST_DB_DATABASE', 'travis'), + 'username' => env('TEST_DB_USERNAME', 'root'), + 'password' => env('TEST_DB_PASSWORD', ''), 'charset' => 'utf8', 'collation' => 'utf8_unicode_ci', 'prefix' => '', diff --git a/database/factories/ModelFactory.php b/database/factories/ModelFactory.php index ee2adc3e5..be96cd024 100644 --- a/database/factories/ModelFactory.php +++ b/database/factories/ModelFactory.php @@ -38,3 +38,22 @@ $factory->define(Pterodactyl\Models\Location::class, function (Faker\Generator $ 'long' => $faker->catchPhrase, ]; }); + +$factory->define(Pterodactyl\Models\Node::class, function (Faker\Generator $faker) { + return [ + 'public' => true, + 'name' => $faker->firstName, + 'fqdn' => $faker->ipv4, + 'scheme' => 'http', + 'behind_proxy' => false, + 'memory' => 1024, + 'memory_overallocate' => 0, + 'disk' => 10240, + 'disk_overallocate' => 0, + 'upload_size' => 100, + 'daemonSecret' => $faker->uuid, + 'daemonListen' => 8080, + 'daemonSFTP' => 2022, + 'daemonBase' => '/srv/daemon', + ]; +}); diff --git a/tests/Feature/Services/LocationServiceTest.php b/tests/Feature/Services/LocationServiceTest.php index f57ce1474..fbf8f8f1d 100644 --- a/tests/Feature/Services/LocationServiceTest.php +++ b/tests/Feature/Services/LocationServiceTest.php @@ -25,6 +25,8 @@ namespace Tests\Feature\Services; use Illuminate\Validation\ValidationException; +use Pterodactyl\Exceptions\DisplayException; +use Pterodactyl\Models\Node; use Tests\TestCase; use Pterodactyl\Models\Location; use Pterodactyl\Services\LocationService; @@ -201,4 +203,46 @@ class LocationServiceTest extends TestCase { $this->service->update(0, []); } + + /** + * Test that a location can be deleted normally when no nodes are attached. + */ + public function testShouldDeleteExistingLocation() + { + $location = factory(Location::class)->create(); + + $this->assertDatabaseHas('locations', [ + 'id' => $location->id, + ]); + + $model = $this->service->delete($location); + + $this->assertTrue($model); + $this->assertDatabaseMissing('locations', [ + 'id' => $location->id, + ]); + } + + /** + * Test that a location cannot be deleted if a node is attached to it. + * + * @expectedException \Pterodactyl\Exceptions\DisplayException + */ + public function testShouldFailToDeleteExistingLocationWithAttachedNodes() + { + $location = factory(Location::class)->create(); + $node = factory(Node::class)->create(['location_id' => $location->id]); + + $this->assertDatabaseHas('locations', ['id' => $location->id]); + $this->assertDatabaseHas('nodes', ['id' => $node->id]); + + try { + $this->service->delete($location->id); + } catch (\Exception $ex) { + $this->assertInstanceOf(DisplayException::class, $ex); + $this->assertNotEmpty($ex->getMessage()); + + throw $ex; + } + } }