diff --git a/app/Models/Allocation.php b/app/Models/Allocation.php index 81e59652..f987223f 100644 --- a/app/Models/Allocation.php +++ b/app/Models/Allocation.php @@ -2,6 +2,8 @@ namespace Pterodactyl\Models; +use Illuminate\Database\Eloquent\Factories\HasFactory; + /** * @property int $id * @property int $node_id @@ -21,6 +23,8 @@ namespace Pterodactyl\Models; */ class Allocation extends Model { + use HasFactory; + /** * The resource name for this model when it is transformed into an * API representation using fractal. diff --git a/app/Models/ApiKey.php b/app/Models/ApiKey.php index 072a74f9..c382cf04 100644 --- a/app/Models/ApiKey.php +++ b/app/Models/ApiKey.php @@ -3,6 +3,7 @@ namespace Pterodactyl\Models; use Pterodactyl\Services\Acl\Api\AdminAcl; +use Illuminate\Database\Eloquent\Factories\HasFactory; /** * @property int $id @@ -18,6 +19,12 @@ use Pterodactyl\Services\Acl\Api\AdminAcl; */ class ApiKey extends Model { + use HasFactory; + + /** + * The resource name for this model when it is transformed into an + * API representation using fractal. + */ const RESOURCE_NAME = 'api_key'; /** diff --git a/app/Models/Database.php b/app/Models/Database.php index 8e66219f..d02a1931 100644 --- a/app/Models/Database.php +++ b/app/Models/Database.php @@ -2,6 +2,8 @@ namespace Pterodactyl\Models; +use Illuminate\Database\Eloquent\Factories\HasFactory; + /** * @property int $id * @property int $server_id @@ -19,6 +21,8 @@ namespace Pterodactyl\Models; */ class Database extends Model { + use HasFactory; + /** * The resource name for this model when it is transformed into an * API representation using fractal. diff --git a/app/Models/DatabaseHost.php b/app/Models/DatabaseHost.php index 750ca0de..655e160f 100644 --- a/app/Models/DatabaseHost.php +++ b/app/Models/DatabaseHost.php @@ -2,8 +2,12 @@ namespace Pterodactyl\Models; +use Illuminate\Database\Eloquent\Factories\HasFactory; + class DatabaseHost extends Model { + use HasFactory; + /** * The resource name for this model when it is transformed into an * API representation using fractal. diff --git a/app/Models/Egg.php b/app/Models/Egg.php index 03d5fa5f..d448a0de 100644 --- a/app/Models/Egg.php +++ b/app/Models/Egg.php @@ -2,6 +2,8 @@ namespace Pterodactyl\Models; +use Illuminate\Database\Eloquent\Factories\HasFactory; + /** * @property int $id * @property string $uuid @@ -46,6 +48,8 @@ namespace Pterodactyl\Models; */ class Egg extends Model { + use HasFactory; + /** * The resource name for this model when it is transformed into an * API representation using fractal. diff --git a/app/Models/EggVariable.php b/app/Models/EggVariable.php index 2adc3513..b248414a 100644 --- a/app/Models/EggVariable.php +++ b/app/Models/EggVariable.php @@ -2,6 +2,8 @@ namespace Pterodactyl\Models; +use Illuminate\Database\Eloquent\Factories\HasFactory; + /** * @property int $id * @property int $egg_id @@ -25,6 +27,8 @@ namespace Pterodactyl\Models; */ class EggVariable extends Model { + use HasFactory; + /** * The resource name for this model when it is transformed into an * API representation using fractal. diff --git a/app/Models/Location.php b/app/Models/Location.php index 74fed181..db4e973a 100644 --- a/app/Models/Location.php +++ b/app/Models/Location.php @@ -2,6 +2,8 @@ namespace Pterodactyl\Models; +use Illuminate\Database\Eloquent\Factories\HasFactory; + /** * @property int $id * @property string $short @@ -14,6 +16,8 @@ namespace Pterodactyl\Models; */ class Location extends Model { + use HasFactory; + /** * The resource name for this model when it is transformed into an * API representation using fractal. diff --git a/app/Models/Nest.php b/app/Models/Nest.php index 770c5baf..e038bece 100644 --- a/app/Models/Nest.php +++ b/app/Models/Nest.php @@ -2,6 +2,8 @@ namespace Pterodactyl\Models; +use Illuminate\Database\Eloquent\Factories\HasFactory; + /** * @property int $id * @property string $uuid @@ -16,6 +18,8 @@ namespace Pterodactyl\Models; */ class Nest extends Model { + use HasFactory; + /** * The resource name for this model when it is transformed into an * API representation using fractal. diff --git a/app/Models/Node.php b/app/Models/Node.php index 8258ae86..1925501f 100644 --- a/app/Models/Node.php +++ b/app/Models/Node.php @@ -6,6 +6,7 @@ use Symfony\Component\Yaml\Yaml; use Illuminate\Container\Container; use Illuminate\Notifications\Notifiable; use Illuminate\Contracts\Encryption\Encrypter; +use Illuminate\Database\Eloquent\Factories\HasFactory; /** * @property int $id @@ -38,6 +39,7 @@ use Illuminate\Contracts\Encryption\Encrypter; */ class Node extends Model { + use HasFactory; use Notifiable; /** diff --git a/app/Models/Schedule.php b/app/Models/Schedule.php index de047563..ef928522 100644 --- a/app/Models/Schedule.php +++ b/app/Models/Schedule.php @@ -6,6 +6,7 @@ use Cron\CronExpression; use Carbon\CarbonImmutable; use Illuminate\Container\Container; use Pterodactyl\Contracts\Extensions\HashidsInterface; +use Illuminate\Database\Eloquent\Factories\HasFactory; /** * @property int $id @@ -29,6 +30,8 @@ use Pterodactyl\Contracts\Extensions\HashidsInterface; */ class Schedule extends Model { + use HasFactory; + /** * The resource name for this model when it is transformed into an * API representation using fractal. diff --git a/app/Models/Server.php b/app/Models/Server.php index aace86d0..f01902fc 100644 --- a/app/Models/Server.php +++ b/app/Models/Server.php @@ -5,6 +5,7 @@ namespace Pterodactyl\Models; use Illuminate\Notifications\Notifiable; use Illuminate\Database\Query\JoinClause; use Znck\Eloquent\Traits\BelongsToThrough; +use Illuminate\Database\Eloquent\Factories\HasFactory; /** * @property int $id @@ -54,6 +55,7 @@ use Znck\Eloquent\Traits\BelongsToThrough; class Server extends Model { use BelongsToThrough; + use HasFactory; use Notifiable; /** diff --git a/app/Models/Subuser.php b/app/Models/Subuser.php index ab85b85d..a1f73038 100644 --- a/app/Models/Subuser.php +++ b/app/Models/Subuser.php @@ -3,6 +3,7 @@ namespace Pterodactyl\Models; use Illuminate\Notifications\Notifiable; +use Illuminate\Database\Eloquent\Factories\HasFactory; /** * @property int $id @@ -17,6 +18,7 @@ use Illuminate\Notifications\Notifiable; */ class Subuser extends Model { + use HasFactory; use Notifiable; /** diff --git a/app/Models/Task.php b/app/Models/Task.php index f241b071..69558f12 100644 --- a/app/Models/Task.php +++ b/app/Models/Task.php @@ -5,6 +5,7 @@ namespace Pterodactyl\Models; use Illuminate\Container\Container; use Znck\Eloquent\Traits\BelongsToThrough; use Pterodactyl\Contracts\Extensions\HashidsInterface; +use Illuminate\Database\Eloquent\Factories\HasFactory; /** * @property int $id @@ -25,6 +26,7 @@ use Pterodactyl\Contracts\Extensions\HashidsInterface; class Task extends Model { use BelongsToThrough; + use HasFactory; /** * The resource name for this model when it is transformed into an diff --git a/app/Models/User.php b/app/Models/User.php index 24ef981f..2583d501 100644 --- a/app/Models/User.php +++ b/app/Models/User.php @@ -11,6 +11,7 @@ use Illuminate\Database\Eloquent\Builder; use Illuminate\Auth\Passwords\CanResetPassword; use Pterodactyl\Traits\Helpers\AvailableLanguages; use Illuminate\Foundation\Auth\Access\Authorizable; +use Illuminate\Database\Eloquent\Factories\HasFactory; use Illuminate\Contracts\Auth\Authenticatable as AuthenticatableContract; use Illuminate\Contracts\Auth\Access\Authorizable as AuthorizableContract; use Illuminate\Contracts\Auth\CanResetPassword as CanResetPasswordContract; @@ -49,6 +50,7 @@ class User extends Model implements use Authorizable; use AvailableLanguages; use CanResetPassword; + use HasFactory; use Notifiable; const USER_LEVEL_USER = 0; diff --git a/database/factories/NodeFactory.php b/database/factories/NodeFactory.php index a1e0970f..cadfa11c 100644 --- a/database/factories/NodeFactory.php +++ b/database/factories/NodeFactory.php @@ -23,7 +23,7 @@ class NodeFactory extends Factory public function definition(): array { return [ - 'uuid' => Uuid::uuid4()->toString(), + 'uuid' => $this->faker->unique()->uuid, 'public' => true, 'name' => $this->faker->firstName, 'fqdn' => $this->faker->ipv4, diff --git a/database/factories/UserFactory.php b/database/factories/UserFactory.php index 6bd0866c..23a9c5ca 100644 --- a/database/factories/UserFactory.php +++ b/database/factories/UserFactory.php @@ -26,7 +26,7 @@ class UserFactory extends Factory return [ 'external_id' => $this->faker->unique()->isbn10, - 'uuid' => $this->faker->uuid, + 'uuid' => $this->faker->unique()->uuid, 'username' => $this->faker->userName, 'email' => $this->faker->safeEmail, 'name_first' => $this->faker->firstName, diff --git a/phpunit.xml b/phpunit.xml index e4e18e41..ec20b314 100644 --- a/phpunit.xml +++ b/phpunit.xml @@ -1,37 +1,28 @@ - - - - ./tests/Browser/Processes - - - ./tests/Integration - - - ./tests/Unit - - - - - ./app - - - - - - - - - - - + + + + ./app + + + + + ./tests/Browser/Processes + + + ./tests/Integration + + + ./tests/Unit + + + + + + + + + + + diff --git a/tests/Browser/BrowserTestCase.php b/tests/Browser/BrowserTestCase.php index 6972a41d..42387579 100644 --- a/tests/Browser/BrowserTestCase.php +++ b/tests/Browser/BrowserTestCase.php @@ -115,7 +115,7 @@ abstract class BrowserTestCase extends TestCase */ protected function user(array $attributes = []): User { - return factory(User::class)->create(array_merge([ + return User::factory()->create(array_merge([ 'password' => Hash::make(static::$userPassword), ], $attributes)); } diff --git a/tests/Integration/Api/Application/ApplicationApiIntegrationTestCase.php b/tests/Integration/Api/Application/ApplicationApiIntegrationTestCase.php index 2c150f16..0d33c74e 100644 --- a/tests/Integration/Api/Application/ApplicationApiIntegrationTestCase.php +++ b/tests/Integration/Api/Application/ApplicationApiIntegrationTestCase.php @@ -92,7 +92,7 @@ abstract class ApplicationApiIntegrationTestCase extends IntegrationTestCase */ protected function createApiUser(): User { - return factory(User::class)->create([ + return User::factory()->create([ 'root_admin' => true, ]); } @@ -106,7 +106,7 @@ abstract class ApplicationApiIntegrationTestCase extends IntegrationTestCase */ protected function createApiKey(User $user, array $permissions = []): ApiKey { - return factory(ApiKey::class)->create(array_merge([ + return ApiKey::factory()->create(array_merge([ 'user_id' => $user->id, 'key_type' => ApiKey::TYPE_APPLICATION, 'r_servers' => AdminAcl::READ | AdminAcl::WRITE, diff --git a/tests/Integration/Api/Application/Location/LocationControllerTest.php b/tests/Integration/Api/Application/Location/LocationControllerTest.php index 222dc284..150e01be 100644 --- a/tests/Integration/Api/Application/Location/LocationControllerTest.php +++ b/tests/Integration/Api/Application/Location/LocationControllerTest.php @@ -16,7 +16,7 @@ class LocationControllerTest extends ApplicationApiIntegrationTestCase */ public function testGetLocations() { - $locations = factory(Location::class)->times(2)->create(); + $locations = Location::factory()->times(2)->create(); $response = $this->getJson('/api/application/locations'); $response->assertStatus(Response::HTTP_OK); @@ -70,7 +70,7 @@ class LocationControllerTest extends ApplicationApiIntegrationTestCase */ public function testGetSingleLocation() { - $location = factory(Location::class)->create(); + $location = Location::factory()->create(); $response = $this->getJson('/api/application/locations/' . $location->id); $response->assertStatus(Response::HTTP_OK); @@ -93,7 +93,7 @@ class LocationControllerTest extends ApplicationApiIntegrationTestCase */ public function testRelationshipsCanBeLoaded() { - $location = factory(Location::class)->create(); + $location = Location::factory()->create(); $server = $this->createServerModel(['user_id' => $this->getApiUser()->id, 'location_id' => $location->id]); $response = $this->getJson('/api/application/locations/' . $location->id . '?include=servers,nodes'); @@ -143,8 +143,8 @@ class LocationControllerTest extends ApplicationApiIntegrationTestCase { $this->createNewDefaultApiKey($this->getApiUser(), ['r_nodes' => 0]); - $location = factory(Location::class)->create(); - factory(Node::class)->create(['location_id' => $location->id]); + $location = Location::factory()->create(); + Node::factory()->create(['location_id' => $location->id]); $response = $this->getJson('/api/application/locations/' . $location->id . '?include=nodes'); $response->assertStatus(Response::HTTP_OK); @@ -187,7 +187,7 @@ class LocationControllerTest extends ApplicationApiIntegrationTestCase */ public function testErrorReturnedIfNoPermission() { - $location = factory(Location::class)->create(); + $location = Location::factory()->create(); $this->createNewDefaultApiKey($this->getApiUser(), ['r_locations' => 0]); $response = $this->getJson('/api/application/locations/' . $location->id); diff --git a/tests/Integration/Api/Application/Users/ExternalUserControllerTest.php b/tests/Integration/Api/Application/Users/ExternalUserControllerTest.php index f28e15a9..983710b1 100644 --- a/tests/Integration/Api/Application/Users/ExternalUserControllerTest.php +++ b/tests/Integration/Api/Application/Users/ExternalUserControllerTest.php @@ -13,7 +13,7 @@ class ExternalUserControllerTest extends ApplicationApiIntegrationTestCase */ public function testGetRemoteUser() { - $user = factory(User::class)->create(); + $user = User::factory()->create(); $response = $this->getJson('/api/application/users/external/' . $user->external_id); $response->assertStatus(Response::HTTP_OK); @@ -60,7 +60,7 @@ class ExternalUserControllerTest extends ApplicationApiIntegrationTestCase */ public function testErrorReturnedIfNoPermission() { - $user = factory(User::class)->create(); + $user = User::factory()->create(); $this->createNewDefaultApiKey($this->getApiUser(), ['r_users' => 0]); $response = $this->getJson('/api/application/users/external/' . $user->external_id); diff --git a/tests/Integration/Api/Application/Users/UserControllerTest.php b/tests/Integration/Api/Application/Users/UserControllerTest.php index 128d9b60..9d600132 100644 --- a/tests/Integration/Api/Application/Users/UserControllerTest.php +++ b/tests/Integration/Api/Application/Users/UserControllerTest.php @@ -16,7 +16,7 @@ class UserControllerTest extends ApplicationApiIntegrationTestCase */ public function testGetUsers() { - $user = factory(User::class)->create(); + $user = User::factory()->create(); $response = $this->getJson('/api/application/users'); $response->assertStatus(Response::HTTP_OK); @@ -85,7 +85,7 @@ class UserControllerTest extends ApplicationApiIntegrationTestCase */ public function testGetSingleUser() { - $user = factory(User::class)->create(); + $user = User::factory()->create(); $response = $this->getJson('/api/application/users/' . $user->id); $response->assertStatus(Response::HTTP_OK); @@ -119,7 +119,7 @@ class UserControllerTest extends ApplicationApiIntegrationTestCase */ public function testRelationshipsCanBeLoaded() { - $user = factory(User::class)->create(); + $user = User::factory()->create(); $server = $this->createServerModel(['user_id' => $user->id]); $response = $this->getJson('/api/application/users/' . $user->id . '?include=servers'); @@ -152,7 +152,7 @@ class UserControllerTest extends ApplicationApiIntegrationTestCase { $this->createNewDefaultApiKey($this->getApiUser(), ['r_servers' => 0]); - $user = factory(User::class)->create(); + $user = User::factory()->create(); $this->createServerModel(['user_id' => $user->id]); $response = $this->getJson('/api/application/users/' . $user->id . '?include=servers'); @@ -194,7 +194,7 @@ class UserControllerTest extends ApplicationApiIntegrationTestCase */ public function testErrorReturnedIfNoPermission() { - $user = factory(User::class)->create(); + $user = User::factory()->create(); $this->createNewDefaultApiKey($this->getApiUser(), ['r_users' => 0]); $response = $this->getJson('/api/application/users/' . $user->id); @@ -250,7 +250,7 @@ class UserControllerTest extends ApplicationApiIntegrationTestCase */ public function testUpdateUser() { - $user = factory(User::class)->create(); + $user = User::factory()->create(); $response = $this->patchJson('/api/application/users/' . $user->id, [ 'username' => 'new.test.name', @@ -279,7 +279,7 @@ class UserControllerTest extends ApplicationApiIntegrationTestCase */ public function testDeleteUser() { - $user = factory(User::class)->create(); + $user = User::factory()->create(); $this->assertDatabaseHas('users', ['id' => $user->id]); $response = $this->delete('/api/application/users/' . $user->id); @@ -302,7 +302,7 @@ class UserControllerTest extends ApplicationApiIntegrationTestCase $this->createNewDefaultApiKey($this->getApiUser(), ['r_users' => AdminAcl::READ]); if (str_contains($url, '{id}')) { - $user = factory(User::class)->create(); + $user = User::factory()->create(); $url = str_replace('{id}', $user->id, $url); } diff --git a/tests/Integration/Api/Client/AccountControllerTest.php b/tests/Integration/Api/Client/AccountControllerTest.php index 6534bd50..3ed689ef 100644 --- a/tests/Integration/Api/Client/AccountControllerTest.php +++ b/tests/Integration/Api/Client/AccountControllerTest.php @@ -15,7 +15,7 @@ class AccountControllerTest extends ClientApiIntegrationTestCase public function testAccountDetailsAreReturned() { /** @var \Pterodactyl\Models\User $user */ - $user = factory(User::class)->create(); + $user = User::factory()->create(); $response = $this->actingAs($user)->get('/api/client/account'); @@ -39,7 +39,7 @@ class AccountControllerTest extends ClientApiIntegrationTestCase public function testEmailIsUpdated() { /** @var \Pterodactyl\Models\User $user */ - $user = factory(User::class)->create(); + $user = User::factory()->create(); $response = $this->actingAs($user)->putJson('/api/client/account/email', [ 'email' => 'hodor@example.com', @@ -58,7 +58,7 @@ class AccountControllerTest extends ClientApiIntegrationTestCase public function testEmailIsNotUpdatedWhenPasswordIsInvalid() { /** @var \Pterodactyl\Models\User $user */ - $user = factory(User::class)->create(); + $user = User::factory()->create(); $response = $this->actingAs($user)->putJson('/api/client/account/email', [ 'email' => 'hodor@example.com', @@ -77,7 +77,7 @@ class AccountControllerTest extends ClientApiIntegrationTestCase public function testEmailIsNotUpdatedWhenNotValid() { /** @var \Pterodactyl\Models\User $user */ - $user = factory(User::class)->create(); + $user = User::factory()->create(); $response = $this->actingAs($user)->putJson('/api/client/account/email', [ 'email' => '', @@ -104,7 +104,7 @@ class AccountControllerTest extends ClientApiIntegrationTestCase public function testPasswordIsUpdated() { /** @var \Pterodactyl\Models\User $user */ - $user = factory(User::class)->create(); + $user = User::factory()->create(); $mock = Mockery::mock(AuthManager::class); $mock->expects('logoutOtherDevices')->with('New_Password1'); @@ -127,7 +127,7 @@ class AccountControllerTest extends ClientApiIntegrationTestCase public function testPasswordIsNotUpdatedIfCurrentPasswordIsInvalid() { /** @var \Pterodactyl\Models\User $user */ - $user = factory(User::class)->create(); + $user = User::factory()->create(); $response = $this->actingAs($user)->putJson('/api/client/account/password', [ 'current_password' => 'invalid', @@ -146,7 +146,7 @@ class AccountControllerTest extends ClientApiIntegrationTestCase */ public function testErrorIsReturnedForInvalidRequestData() { - $user = factory(User::class)->create(); + $user = User::factory()->create(); $this->actingAs($user)->putJson('/api/client/account/password', [ 'current_password' => 'password', @@ -170,7 +170,7 @@ class AccountControllerTest extends ClientApiIntegrationTestCase public function testErrorIsReturnedIfPasswordIsNotConfirmed() { /** @var \Pterodactyl\Models\User $user */ - $user = factory(User::class)->create(); + $user = User::factory()->create(); $response = $this->actingAs($user)->putJson('/api/client/account/password', [ 'current_password' => 'password', diff --git a/tests/Integration/Api/Client/ApiKeyControllerTest.php b/tests/Integration/Api/Client/ApiKeyControllerTest.php index f4c19f4f..77bb8e1a 100644 --- a/tests/Integration/Api/Client/ApiKeyControllerTest.php +++ b/tests/Integration/Api/Client/ApiKeyControllerTest.php @@ -24,9 +24,9 @@ class ApiKeyControllerTest extends ClientApiIntegrationTestCase public function testApiKeysAreReturned() { /** @var \Pterodactyl\Models\User $user */ - $user = factory(User::class)->create(); + $user = User::factory()->create(); /** @var \Pterodactyl\Models\ApiKey $key */ - $key = factory(ApiKey::class)->create([ + $key = ApiKey::factory()->create([ 'user_id' => $user->id, 'key_type' => ApiKey::TYPE_ACCOUNT, ]); @@ -59,13 +59,13 @@ class ApiKeyControllerTest extends ClientApiIntegrationTestCase public function testApiKeyCanBeCreatedForAccount() { /** @var \Pterodactyl\Models\User $user */ - $user = factory(User::class)->create(); + $user = User::factory()->create(); // Small sub-test to ensure we're always comparing the number of keys to the // specific logged in account, and not just the total number of keys stored in // the database. - factory(ApiKey::class)->times(10)->create([ - 'user_id' => factory(User::class)->create()->id, + ApiKey::factory()->times(10)->create([ + 'user_id' => User::factory()->create()->id, 'key_type' => ApiKey::TYPE_ACCOUNT, ]); @@ -103,8 +103,8 @@ class ApiKeyControllerTest extends ClientApiIntegrationTestCase public function testNoMoreThanFiveApiKeysCanBeCreatedForAnAccount() { /** @var \Pterodactyl\Models\User $user */ - $user = factory(User::class)->create(); - factory(ApiKey::class)->times(5)->create([ + $user = User::factory()->create(); + ApiKey::factory()->times(5)->create([ 'user_id' => $user->id, 'key_type' => ApiKey::TYPE_ACCOUNT, ]); @@ -127,7 +127,7 @@ class ApiKeyControllerTest extends ClientApiIntegrationTestCase public function testValidationErrorIsReturnedForBadRequests() { /** @var \Pterodactyl\Models\User $user */ - $user = factory(User::class)->create(); + $user = User::factory()->create(); $response = $this->actingAs($user)->postJson('/api/client/account/api-keys', [ 'description' => '', @@ -154,9 +154,9 @@ class ApiKeyControllerTest extends ClientApiIntegrationTestCase public function testApiKeyCanBeDeleted() { /** @var \Pterodactyl\Models\User $user */ - $user = factory(User::class)->create(); + $user = User::factory()->create(); /** @var \Pterodactyl\Models\ApiKey $key */ - $key = factory(ApiKey::class)->create([ + $key = ApiKey::factory()->create([ 'user_id' => $user->id, 'key_type' => ApiKey::TYPE_ACCOUNT, ]); @@ -173,9 +173,9 @@ class ApiKeyControllerTest extends ClientApiIntegrationTestCase public function testNonExistentApiKeyDeletionReturns404Error() { /** @var \Pterodactyl\Models\User $user */ - $user = factory(User::class)->create(); + $user = User::factory()->create(); /** @var \Pterodactyl\Models\ApiKey $key */ - $key = factory(ApiKey::class)->create([ + $key = ApiKey::factory()->create([ 'user_id' => $user->id, 'key_type' => ApiKey::TYPE_ACCOUNT, ]); @@ -193,11 +193,11 @@ class ApiKeyControllerTest extends ClientApiIntegrationTestCase public function testApiKeyBelongingToAnotherUserCannotBeDeleted() { /** @var \Pterodactyl\Models\User $user */ - $user = factory(User::class)->create(); + $user = User::factory()->create(); /** @var \Pterodactyl\Models\User $user2 */ - $user2 = factory(User::class)->create(); + $user2 = User::factory()->create(); /** @var \Pterodactyl\Models\ApiKey $key */ - $key = factory(ApiKey::class)->create([ + $key = ApiKey::factory()->create([ 'user_id' => $user2->id, 'key_type' => ApiKey::TYPE_ACCOUNT, ]); @@ -215,9 +215,9 @@ class ApiKeyControllerTest extends ClientApiIntegrationTestCase public function testApplicationApiKeyCannotBeDeleted() { /** @var \Pterodactyl\Models\User $user */ - $user = factory(User::class)->create(); + $user = User::factory()->create(); /** @var \Pterodactyl\Models\ApiKey $key */ - $key = factory(ApiKey::class)->create([ + $key = ApiKey::factory()->create([ 'user_id' => $user->id, 'key_type' => ApiKey::TYPE_APPLICATION, ]); diff --git a/tests/Integration/Api/Client/ClientApiIntegrationTestCase.php b/tests/Integration/Api/Client/ClientApiIntegrationTestCase.php index b7795905..7fe3cbd3 100644 --- a/tests/Integration/Api/Client/ClientApiIntegrationTestCase.php +++ b/tests/Integration/Api/Client/ClientApiIntegrationTestCase.php @@ -84,7 +84,7 @@ abstract class ClientApiIntegrationTestCase extends IntegrationTestCase protected function generateTestAccount(array $permissions = []): array { /** @var \Pterodactyl\Models\User $user */ - $user = factory(User::class)->create(); + $user = User::factory()->create(); if (empty($permissions)) { return [$user, $this->createServerModel(['user_id' => $user->id])]; diff --git a/tests/Integration/Api/Client/ClientControllerTest.php b/tests/Integration/Api/Client/ClientControllerTest.php index fc8c2c1e..fa10c082 100644 --- a/tests/Integration/Api/Client/ClientControllerTest.php +++ b/tests/Integration/Api/Client/ClientControllerTest.php @@ -19,7 +19,7 @@ class ClientControllerTest extends ClientApiIntegrationTestCase public function testOnlyLoggedInUsersServersAreReturned() { /** @var \Pterodactyl\Models\User[] $users */ - $users = factory(User::class)->times(3)->create(); + $users = User::factory()->times(3)->create(); /** @var \Pterodactyl\Models\Server[] $servers */ $servers = [ @@ -46,7 +46,7 @@ class ClientControllerTest extends ClientApiIntegrationTestCase public function testServersAreFilteredUsingNameAndUuidInformation() { /** @var \Pterodactyl\Models\User[] $users */ - $users = factory(User::class)->times(2)->create(); + $users = User::factory()->times(2)->create(); $users[0]->update(['root_admin' => true]); /** @var \Pterodactyl\Models\Server[] $servers */ @@ -106,8 +106,8 @@ class ClientControllerTest extends ClientApiIntegrationTestCase [$user, $server] = $this->generateTestAccount(); $server2 = $this->createServerModel(['user_id' => $user->id, 'node_id' => $server->node_id]); - $allocation = factory(Allocation::class)->create(['node_id' => $server->node_id, 'server_id' => $server->id, 'ip' => '192.168.1.1', 'port' => 25565]); - $allocation2 = factory(Allocation::class)->create(['node_id' => $server->node_id, 'server_id' => $server2->id, 'ip' => '192.168.1.1', 'port' => 25570]); + $allocation = Allocation::factory()->create(['node_id' => $server->node_id, 'server_id' => $server->id, 'ip' => '192.168.1.1', 'port' => 25565]); + $allocation2 = Allocation::factory()->create(['node_id' => $server->node_id, 'server_id' => $server2->id, 'ip' => '192.168.1.1', 'port' => 25570]); $server->update(['allocation_id' => $allocation->id]); $server2->update(['allocation_id' => $allocation2->id]); @@ -144,7 +144,7 @@ class ClientControllerTest extends ClientApiIntegrationTestCase public function testServersUserIsASubuserOfAreReturned() { /** @var \Pterodactyl\Models\User[] $users */ - $users = factory(User::class)->times(3)->create(); + $users = User::factory()->times(3)->create(); $servers = [ $this->createServerModel(['user_id' => $users[0]->id]), $this->createServerModel(['user_id' => $users[1]->id]), @@ -175,7 +175,7 @@ class ClientControllerTest extends ClientApiIntegrationTestCase public function testFilterOnlyOwnerServers() { /** @var \Pterodactyl\Models\User[] $users */ - $users = factory(User::class)->times(3)->create(); + $users = User::factory()->times(3)->create(); $servers = [ $this->createServerModel(['user_id' => $users[0]->id]), $this->createServerModel(['user_id' => $users[1]->id]), @@ -204,7 +204,7 @@ class ClientControllerTest extends ClientApiIntegrationTestCase public function testPermissionsAreReturned() { /** @var \Pterodactyl\Models\User $user */ - $user = factory(User::class)->create(); + $user = User::factory()->create(); $this->actingAs($user) ->getJson('/api/client/permissions') @@ -224,7 +224,7 @@ class ClientControllerTest extends ClientApiIntegrationTestCase public function testOnlyAdminLevelServersAreReturned() { /** @var \Pterodactyl\Models\User[] $users */ - $users = factory(User::class)->times(4)->create(); + $users = User::factory()->times(4)->create(); $users[0]->update(['root_admin' => true]); $servers = [ @@ -259,7 +259,7 @@ class ClientControllerTest extends ClientApiIntegrationTestCase public function testAllServersAreReturnedToAdmin() { /** @var \Pterodactyl\Models\User[] $users */ - $users = factory(User::class)->times(4)->create(); + $users = User::factory()->times(4)->create(); $users[0]->update(['root_admin' => true]); $servers = [ @@ -292,7 +292,7 @@ class ClientControllerTest extends ClientApiIntegrationTestCase public function testNoServersAreReturnedIfAdminFilterIsPassedByRegularUser($type) { /** @var \Pterodactyl\Models\User[] $users */ - $users = factory(User::class)->times(3)->create(); + $users = User::factory()->times(3)->create(); $this->createServerModel(['user_id' => $users[0]->id]); $this->createServerModel(['user_id' => $users[1]->id]); @@ -315,7 +315,7 @@ class ClientControllerTest extends ClientApiIntegrationTestCase $server->allocation->notes = 'Test notes'; $server->allocation->save(); - factory(Allocation::class)->times(2)->create([ + Allocation::factory()->times(2)->create([ 'node_id' => $server->node_id, 'server_id' => $server->id, ]); diff --git a/tests/Integration/Api/Client/Server/Allocation/DeleteAllocationTest.php b/tests/Integration/Api/Client/Server/Allocation/DeleteAllocationTest.php index 5b14c1a7..d249f550 100644 --- a/tests/Integration/Api/Client/Server/Allocation/DeleteAllocationTest.php +++ b/tests/Integration/Api/Client/Server/Allocation/DeleteAllocationTest.php @@ -22,7 +22,7 @@ class DeleteAllocationTest extends ClientApiIntegrationTestCase [$user, $server] = $this->generateTestAccount($permission); /** @var \Pterodactyl\Models\Allocation $allocation */ - $allocation = factory(Allocation::class)->create([ + $allocation = Allocation::factory()->create([ 'server_id' => $server->id, 'node_id' => $server->node_id, 'notes' => 'hodor', @@ -42,7 +42,7 @@ class DeleteAllocationTest extends ClientApiIntegrationTestCase [$user, $server] = $this->generateTestAccount([Permission::ACTION_ALLOCATION_CREATE]); /** @var \Pterodactyl\Models\Allocation $allocation */ - $allocation = factory(Allocation::class)->create([ + $allocation = Allocation::factory()->create([ 'server_id' => $server->id, 'node_id' => $server->node_id, 'notes' => 'hodor', diff --git a/tests/Integration/Api/Client/Server/NetworkAllocationControllerTest.php b/tests/Integration/Api/Client/Server/NetworkAllocationControllerTest.php index 185375e8..a6df3508 100644 --- a/tests/Integration/Api/Client/Server/NetworkAllocationControllerTest.php +++ b/tests/Integration/Api/Client/Server/NetworkAllocationControllerTest.php @@ -32,7 +32,7 @@ class NetworkAllocationControllerTest extends ClientApiIntegrationTestCase public function testServerAllocationsAreNotReturnedWithoutPermission() { [$user, $server] = $this->generateTestAccount(); - $user2 = factory(User::class)->create(); + $user2 = User::factory()->create(); $server->owner_id = $user2->id; $server->save(); @@ -85,7 +85,7 @@ class NetworkAllocationControllerTest extends ClientApiIntegrationTestCase public function testAllocationNotesCannotBeUpdatedByInvalidUsers() { [$user, $server] = $this->generateTestAccount(); - $user2 = factory(User::class)->create(); + $user2 = User::factory()->create(); $server->owner_id = $user2->id; $server->save(); @@ -105,7 +105,7 @@ class NetworkAllocationControllerTest extends ClientApiIntegrationTestCase { [$user, $server] = $this->generateTestAccount($permissions); $allocation = $server->allocation; - $allocation2 = factory(Allocation::class)->create(['node_id' => $server->node_id, 'server_id' => $server->id]); + $allocation2 = Allocation::factory()->create(['node_id' => $server->node_id, 'server_id' => $server->id]); $server->allocation_id = $allocation->id; $server->save(); @@ -121,7 +121,7 @@ class NetworkAllocationControllerTest extends ClientApiIntegrationTestCase public function testPrimaryAllocationCannotBeModifiedByInvalidUser() { [$user, $server] = $this->generateTestAccount(); - $user2 = factory(User::class)->create(); + $user2 = User::factory()->create(); $server->owner_id = $user2->id; $server->save(); diff --git a/tests/Integration/Api/Client/Server/Schedule/DeleteServerScheduleTest.php b/tests/Integration/Api/Client/Server/Schedule/DeleteServerScheduleTest.php index cff7591b..cf41dc5e 100644 --- a/tests/Integration/Api/Client/Server/Schedule/DeleteServerScheduleTest.php +++ b/tests/Integration/Api/Client/Server/Schedule/DeleteServerScheduleTest.php @@ -20,8 +20,8 @@ class DeleteServerScheduleTest extends ClientApiIntegrationTestCase { [$user, $server] = $this->generateTestAccount($permissions); - $schedule = factory(Schedule::class)->create(['server_id' => $server->id]); - $task = factory(Task::class)->create(['schedule_id' => $schedule->id]); + $schedule = Schedule::factory()->create(['server_id' => $server->id]); + $task = Task::factory()->create(['schedule_id' => $schedule->id]); $this->actingAs($user) ->deleteJson("/api/client/servers/{$server->uuid}/schedules/{$schedule->id}") @@ -52,7 +52,7 @@ class DeleteServerScheduleTest extends ClientApiIntegrationTestCase [$user, $server] = $this->generateTestAccount(); [, $server2] = $this->generateTestAccount(['user_id' => $user->id]); - $schedule = factory(Schedule::class)->create(['server_id' => $server2->id]); + $schedule = Schedule::factory()->create(['server_id' => $server2->id]); $this->actingAs($user) ->deleteJson("/api/client/servers/{$server->uuid}/schedules/{$schedule->id}") @@ -69,7 +69,7 @@ class DeleteServerScheduleTest extends ClientApiIntegrationTestCase { [$user, $server] = $this->generateTestAccount([Permission::ACTION_SCHEDULE_UPDATE]); - $schedule = factory(Schedule::class)->create(['server_id' => $server->id]); + $schedule = Schedule::factory()->create(['server_id' => $server->id]); $this->actingAs($user) ->deleteJson("/api/client/servers/{$server->uuid}/schedules/{$schedule->id}") diff --git a/tests/Integration/Api/Client/Server/Schedule/ExecuteScheduleTest.php b/tests/Integration/Api/Client/Server/Schedule/ExecuteScheduleTest.php index d83faae3..c40966c2 100644 --- a/tests/Integration/Api/Client/Server/Schedule/ExecuteScheduleTest.php +++ b/tests/Integration/Api/Client/Server/Schedule/ExecuteScheduleTest.php @@ -25,7 +25,7 @@ class ExecuteScheduleTest extends ClientApiIntegrationTestCase Bus::fake(); /** @var \Pterodactyl\Models\Schedule $schedule */ - $schedule = factory(Schedule::class)->create([ + $schedule = Schedule::factory()->create([ 'server_id' => $server->id, ]); @@ -35,7 +35,7 @@ class ExecuteScheduleTest extends ClientApiIntegrationTestCase $response->assertJsonPath('errors.0.detail', 'Cannot process schedule for task execution: no tasks are registered.'); /** @var \Pterodactyl\Models\Task $task */ - $task = factory(Task::class)->create([ + $task = Task::factory()->create([ 'schedule_id' => $schedule->id, 'sequence_id' => 1, 'time_offset' => 2, @@ -60,7 +60,7 @@ class ExecuteScheduleTest extends ClientApiIntegrationTestCase [$user, $server] = $this->generateTestAccount(); /** @var \Pterodactyl\Models\Schedule $schedule */ - $schedule = factory(Schedule::class)->create([ + $schedule = Schedule::factory()->create([ 'server_id' => $server->id, 'is_active' => false, ]); @@ -80,7 +80,7 @@ class ExecuteScheduleTest extends ClientApiIntegrationTestCase [$user, $server] = $this->generateTestAccount([Permission::ACTION_SCHEDULE_CREATE]); /** @var \Pterodactyl\Models\Schedule $schedule */ - $schedule = factory(Schedule::class)->create(['server_id' => $server->id]); + $schedule = Schedule::factory()->create(['server_id' => $server->id]); $this->actingAs($user)->postJson($this->link($schedule, '/execute'))->assertForbidden(); } diff --git a/tests/Integration/Api/Client/Server/Schedule/GetServerSchedulesTest.php b/tests/Integration/Api/Client/Server/Schedule/GetServerSchedulesTest.php index 67be3fd8..9ee44061 100644 --- a/tests/Integration/Api/Client/Server/Schedule/GetServerSchedulesTest.php +++ b/tests/Integration/Api/Client/Server/Schedule/GetServerSchedulesTest.php @@ -32,9 +32,9 @@ class GetServerSchedulesTest extends ClientApiIntegrationTestCase [$user, $server] = $this->generateTestAccount($permissions); /** @var \Pterodactyl\Models\Schedule $schedule */ - $schedule = factory(Schedule::class)->create(['server_id' => $server->id]); + $schedule = Schedule::factory()->create(['server_id' => $server->id]); /** @var \Pterodactyl\Models\Task $task */ - $task = factory(Task::class)->create(['schedule_id' => $schedule->id, 'sequence_id' => 1, 'time_offset' => 0]); + $task = Task::factory()->create(['schedule_id' => $schedule->id, 'sequence_id' => 1, 'time_offset' => 0]); $response = $this->actingAs($user) ->getJson( @@ -66,7 +66,7 @@ class GetServerSchedulesTest extends ClientApiIntegrationTestCase [$user, $server] = $this->generateTestAccount(); [, $server2] = $this->generateTestAccount(['user_id' => $user->id]); - $schedule = factory(Schedule::class)->create(['server_id' => $server2->id]); + $schedule = Schedule::factory()->create(['server_id' => $server2->id]); $this->actingAs($user) ->getJson("/api/client/servers/{$server->uuid}/schedules/{$schedule->id}") @@ -84,7 +84,7 @@ class GetServerSchedulesTest extends ClientApiIntegrationTestCase ->getJson("/api/client/servers/{$server->uuid}/schedules") ->assertForbidden(); - $schedule = factory(Schedule::class)->create(['server_id' => $server->id]); + $schedule = Schedule::factory()->create(['server_id' => $server->id]); $this->actingAs($user) ->getJson("/api/client/servers/{$server->uuid}/schedules/{$schedule->id}") diff --git a/tests/Integration/Api/Client/Server/Schedule/UpdateServerScheduleTest.php b/tests/Integration/Api/Client/Server/Schedule/UpdateServerScheduleTest.php index ec60a413..1ce4523e 100644 --- a/tests/Integration/Api/Client/Server/Schedule/UpdateServerScheduleTest.php +++ b/tests/Integration/Api/Client/Server/Schedule/UpdateServerScheduleTest.php @@ -34,7 +34,7 @@ class UpdateServerScheduleTest extends ClientApiIntegrationTestCase [$user, $server] = $this->generateTestAccount($permissions); /** @var \Pterodactyl\Models\Schedule $schedule */ - $schedule = factory(Schedule::class)->create(['server_id' => $server->id]); + $schedule = Schedule::factory()->create(['server_id' => $server->id]); $expected = Utilities::getScheduleNextRunDate('5', '*', '*', '*'); $response = $this->actingAs($user) @@ -59,7 +59,7 @@ class UpdateServerScheduleTest extends ClientApiIntegrationTestCase [$user, $server] = $this->generateTestAccount(); [, $server2] = $this->generateTestAccount(['user_id' => $user->id]); - $schedule = factory(Schedule::class)->create(['server_id' => $server2->id]); + $schedule = Schedule::factory()->create(['server_id' => $server2->id]); $this->actingAs($user) ->postJson("/api/client/servers/{$server->uuid}/schedules/{$schedule->id}") @@ -74,7 +74,7 @@ class UpdateServerScheduleTest extends ClientApiIntegrationTestCase { [$user, $server] = $this->generateTestAccount([Permission::ACTION_SCHEDULE_CREATE]); - $schedule = factory(Schedule::class)->create(['server_id' => $server->id]); + $schedule = Schedule::factory()->create(['server_id' => $server->id]); $this->actingAs($user) ->postJson("/api/client/servers/{$server->uuid}/schedules/{$schedule->id}") @@ -92,7 +92,7 @@ class UpdateServerScheduleTest extends ClientApiIntegrationTestCase [$user, $server] = $this->generateTestAccount(); /** @var \Pterodactyl\Models\Schedule $schedule */ - $schedule = factory(Schedule::class)->create([ + $schedule = Schedule::factory()->create([ 'server_id' => $server->id, 'is_active' => true, 'is_processing' => true, diff --git a/tests/Integration/Api/Client/Server/ScheduleTask/CreateServerScheduleTaskTest.php b/tests/Integration/Api/Client/Server/ScheduleTask/CreateServerScheduleTaskTest.php index 9f263acd..959cf7dd 100644 --- a/tests/Integration/Api/Client/Server/ScheduleTask/CreateServerScheduleTaskTest.php +++ b/tests/Integration/Api/Client/Server/ScheduleTask/CreateServerScheduleTaskTest.php @@ -21,7 +21,7 @@ class CreateServerScheduleTaskTest extends ClientApiIntegrationTestCase [$user, $server] = $this->generateTestAccount($permissions); /** @var \Pterodactyl\Models\Schedule $schedule */ - $schedule = factory(Schedule::class)->create(['server_id' => $server->id]); + $schedule = Schedule::factory()->create(['server_id' => $server->id]); $this->assertEmpty($schedule->tasks); $response = $this->actingAs($user)->postJson($this->link($schedule, '/tasks'), [ @@ -51,7 +51,7 @@ class CreateServerScheduleTaskTest extends ClientApiIntegrationTestCase [$user, $server] = $this->generateTestAccount(); /** @var \Pterodactyl\Models\Schedule $schedule */ - $schedule = factory(Schedule::class)->create(['server_id' => $server->id]); + $schedule = Schedule::factory()->create(['server_id' => $server->id]); $response = $this->actingAs($user)->postJson($this->link($schedule, '/tasks'))->assertStatus(Response::HTTP_UNPROCESSABLE_ENTITY); @@ -96,7 +96,7 @@ class CreateServerScheduleTaskTest extends ClientApiIntegrationTestCase [$user, $server] = $this->generateTestAccount(); /** @var \Pterodactyl\Models\Schedule $schedule */ - $schedule = factory(Schedule::class)->create(['server_id' => $server->id]); + $schedule = Schedule::factory()->create(['server_id' => $server->id]); $this->actingAs($user)->postJson($this->link($schedule, '/tasks'), [ 'action' => 'backup', @@ -121,8 +121,8 @@ class CreateServerScheduleTaskTest extends ClientApiIntegrationTestCase [$user, $server] = $this->generateTestAccount(); /** @var \Pterodactyl\Models\Schedule $schedule */ - $schedule = factory(Schedule::class)->create(['server_id' => $server->id]); - factory(Task::class)->times(2)->create(['schedule_id' => $schedule->id]); + $schedule = Schedule::factory()->create(['server_id' => $server->id]); + Task::factory()->times(2)->create(['schedule_id' => $schedule->id]); $this->actingAs($user)->postJson($this->link($schedule, '/tasks'), [ 'action' => 'command', @@ -144,7 +144,7 @@ class CreateServerScheduleTaskTest extends ClientApiIntegrationTestCase [, $server2] = $this->generateTestAccount(['user_id' => $user->id]); /** @var \Pterodactyl\Models\Schedule $schedule */ - $schedule = factory(Schedule::class)->create(['server_id' => $server2->id]); + $schedule = Schedule::factory()->create(['server_id' => $server2->id]); $this->actingAs($user) ->postJson("/api/client/servers/{$server->uuid}/schedules/{$schedule->id}/tasks") @@ -160,7 +160,7 @@ class CreateServerScheduleTaskTest extends ClientApiIntegrationTestCase [$user, $server] = $this->generateTestAccount([Permission::ACTION_SCHEDULE_CREATE]); /** @var \Pterodactyl\Models\Schedule $schedule */ - $schedule = factory(Schedule::class)->create(['server_id' => $server->id]); + $schedule = Schedule::factory()->create(['server_id' => $server->id]); $this->actingAs($user) ->postJson($this->link($schedule, '/tasks')) diff --git a/tests/Integration/Api/Client/Server/ScheduleTask/DeleteScheduleTaskTest.php b/tests/Integration/Api/Client/Server/ScheduleTask/DeleteScheduleTaskTest.php index ef3e1dee..dc9b3fd4 100644 --- a/tests/Integration/Api/Client/Server/ScheduleTask/DeleteScheduleTaskTest.php +++ b/tests/Integration/Api/Client/Server/ScheduleTask/DeleteScheduleTaskTest.php @@ -19,8 +19,8 @@ class DeleteScheduleTaskTest extends ClientApiIntegrationTestCase $server2 = $this->createServerModel(); [$user] = $this->generateTestAccount(); - $schedule = factory(Schedule::class)->create(['server_id' => $server2->id]); - $task = factory(Task::class)->create(['schedule_id' => $schedule->id]); + $schedule = Schedule::factory()->create(['server_id' => $server2->id]); + $task = Task::factory()->create(['schedule_id' => $schedule->id]); $this->actingAs($user)->deleteJson($this->link($task))->assertNotFound(); } @@ -33,9 +33,9 @@ class DeleteScheduleTaskTest extends ClientApiIntegrationTestCase { [$user, $server] = $this->generateTestAccount(); - $schedule = factory(Schedule::class)->create(['server_id' => $server->id]); - $schedule2 = factory(Schedule::class)->create(['server_id' => $server->id]); - $task = factory(Task::class)->create(['schedule_id' => $schedule->id]); + $schedule = Schedule::factory()->create(['server_id' => $server->id]); + $schedule2 = Schedule::factory()->create(['server_id' => $server->id]); + $task = Task::factory()->create(['schedule_id' => $schedule->id]); $this->actingAs($user)->deleteJson("/api/client/servers/{$server->uuid}/schedules/{$schedule2->id}/tasks/{$task->id}")->assertNotFound(); } @@ -47,12 +47,12 @@ class DeleteScheduleTaskTest extends ClientApiIntegrationTestCase { [$user, $server] = $this->generateTestAccount([Permission::ACTION_SCHEDULE_CREATE]); - $schedule = factory(Schedule::class)->create(['server_id' => $server->id]); - $task = factory(Task::class)->create(['schedule_id' => $schedule->id]); + $schedule = Schedule::factory()->create(['server_id' => $server->id]); + $task = Task::factory()->create(['schedule_id' => $schedule->id]); $this->actingAs($user)->deleteJson($this->link($task))->assertForbidden(); - $user2 = factory(User::class)->create(); + $user2 = User::factory()->create(); $this->actingAs($user2)->deleteJson($this->link($task))->assertNotFound(); } @@ -65,12 +65,12 @@ class DeleteScheduleTaskTest extends ClientApiIntegrationTestCase { [$user, $server] = $this->generateTestAccount(); - $schedule = factory(Schedule::class)->create(['server_id' => $server->id]); + $schedule = Schedule::factory()->create(['server_id' => $server->id]); $tasks = [ - factory(Task::class)->create(['schedule_id' => $schedule->id, 'sequence_id' => 1]), - factory(Task::class)->create(['schedule_id' => $schedule->id, 'sequence_id' => 2]), - factory(Task::class)->create(['schedule_id' => $schedule->id, 'sequence_id' => 3]), - factory(Task::class)->create(['schedule_id' => $schedule->id, 'sequence_id' => 4]), + Task::factory()->create(['schedule_id' => $schedule->id, 'sequence_id' => 1]), + Task::factory()->create(['schedule_id' => $schedule->id, 'sequence_id' => 2]), + Task::factory()->create(['schedule_id' => $schedule->id, 'sequence_id' => 3]), + Task::factory()->create(['schedule_id' => $schedule->id, 'sequence_id' => 4]), ]; $response = $this->actingAs($user)->deleteJson($this->link($tasks[1])); diff --git a/tests/Integration/Api/Client/Server/Startup/GetStartupAndVariablesTest.php b/tests/Integration/Api/Client/Server/Startup/GetStartupAndVariablesTest.php index 6daa0595..8ea74ffc 100644 --- a/tests/Integration/Api/Client/Server/Startup/GetStartupAndVariablesTest.php +++ b/tests/Integration/Api/Client/Server/Startup/GetStartupAndVariablesTest.php @@ -55,7 +55,7 @@ class GetStartupAndVariablesTest extends ClientApiIntegrationTestCase [$user, $server] = $this->generateTestAccount([Permission::ACTION_WEBSOCKET_CONNECT]); $this->actingAs($user)->getJson($this->link($server) . "/startup")->assertForbidden(); - $user2 = factory(User::class)->create(); + $user2 = User::factory()->create(); $this->actingAs($user2)->getJson($this->link($server) . "/startup")->assertNotFound(); } diff --git a/tests/Integration/Api/Client/Server/Startup/UpdateStartupVariableTest.php b/tests/Integration/Api/Client/Server/Startup/UpdateStartupVariableTest.php index 3ed1a89c..d439a926 100644 --- a/tests/Integration/Api/Client/Server/Startup/UpdateStartupVariableTest.php +++ b/tests/Integration/Api/Client/Server/Startup/UpdateStartupVariableTest.php @@ -147,7 +147,7 @@ class UpdateStartupVariableTest extends ClientApiIntegrationTestCase [$user, $server] = $this->generateTestAccount([Permission::ACTION_WEBSOCKET_CONNECT]); $this->actingAs($user)->putJson($this->link($server) . "/startup/variable")->assertForbidden(); - $user2 = factory(User::class)->create(); + $user2 = User::factory()->create(); $this->actingAs($user2)->putJson($this->link($server) . "/startup/variable")->assertNotFound(); } diff --git a/tests/Integration/Api/Client/Server/Subuser/CreateServerSubuserTest.php b/tests/Integration/Api/Client/Server/Subuser/CreateServerSubuserTest.php index 3a1f8bc6..c9bfc4d4 100644 --- a/tests/Integration/Api/Client/Server/Subuser/CreateServerSubuserTest.php +++ b/tests/Integration/Api/Client/Server/Subuser/CreateServerSubuserTest.php @@ -113,7 +113,7 @@ class CreateServerSubuserTest extends ClientApiIntegrationTestCase [$user, $server] = $this->generateTestAccount(); /** @var \Pterodactyl\Models\User $existing */ - $existing = factory(User::class)->create(['email' => $this->faker->email]); + $existing = User::factory()->create(['email' => $this->faker->email]); $response = $this->actingAs($user)->postJson($this->link($server) . "/users", [ 'email' => $existing->email, diff --git a/tests/Integration/Api/Client/Server/Subuser/DeleteSubuserTest.php b/tests/Integration/Api/Client/Server/Subuser/DeleteSubuserTest.php index 5810c73b..ad394de2 100644 --- a/tests/Integration/Api/Client/Server/Subuser/DeleteSubuserTest.php +++ b/tests/Integration/Api/Client/Server/Subuser/DeleteSubuserTest.php @@ -30,13 +30,13 @@ class DeleteSubuserTest extends ClientApiIntegrationTestCase [$user, $server] = $this->generateTestAccount(); /** @var \Pterodactyl\Models\User $differentUser */ - $differentUser = factory(User::class)->create(); + $differentUser = User::factory()->create(); // Generate a UUID that lines up with a user in the database if it were to be cast to an int. $uuid = $differentUser->id . str_repeat('a', strlen((string)$differentUser->id)) . substr(Uuid::uuid4()->toString(), 8); /** @var \Pterodactyl\Models\User $subuser */ - $subuser = factory(User::class)->create(['uuid' => $uuid]); + $subuser = User::factory()->create(['uuid' => $uuid]); Subuser::query()->forceCreate([ 'user_id' => $subuser->id, @@ -52,7 +52,7 @@ class DeleteSubuserTest extends ClientApiIntegrationTestCase // anything in the database. $uuid = '18180000' . substr(Uuid::uuid4()->toString(), 8); /** @var \Pterodactyl\Models\User $subuser */ - $subuser = factory(User::class)->create(['uuid' => $uuid]); + $subuser = User::factory()->create(['uuid' => $uuid]); Subuser::query()->forceCreate([ 'user_id' => $subuser->id, diff --git a/tests/Integration/Api/Client/TwoFactorControllerTest.php b/tests/Integration/Api/Client/TwoFactorControllerTest.php index 1c9b467f..fe62d6ff 100644 --- a/tests/Integration/Api/Client/TwoFactorControllerTest.php +++ b/tests/Integration/Api/Client/TwoFactorControllerTest.php @@ -18,7 +18,7 @@ class TwoFactorControllerTest extends ClientApiIntegrationTestCase public function testTwoFactorImageDataIsReturned() { /** @var \Pterodactyl\Models\User $user */ - $user = factory(User::class)->create(['use_totp' => false]); + $user = User::factory()->create(['use_totp' => false]); $this->assertFalse($user->use_totp); $this->assertEmpty($user->totp_secret); @@ -42,7 +42,7 @@ class TwoFactorControllerTest extends ClientApiIntegrationTestCase public function testErrorIsReturnedWhenTwoFactorIsAlreadyEnabled() { /** @var \Pterodactyl\Models\User $user */ - $user = factory(User::class)->create(['use_totp' => true]); + $user = User::factory()->create(['use_totp' => true]); $response = $this->actingAs($user)->getJson('/api/client/account/two-factor'); @@ -57,7 +57,7 @@ class TwoFactorControllerTest extends ClientApiIntegrationTestCase public function testValidationErrorIsReturnedIfInvalidDataIsPassedToEnabled2FA() { /** @var \Pterodactyl\Models\User $user */ - $user = factory(User::class)->create(['use_totp' => false]); + $user = User::factory()->create(['use_totp' => false]); $response = $this->actingAs($user)->postJson('/api/client/account/two-factor', [ 'code' => '', @@ -74,7 +74,7 @@ class TwoFactorControllerTest extends ClientApiIntegrationTestCase public function testTwoFactorCanBeEnabledOnAccount() { /** @var \Pterodactyl\Models\User $user */ - $user = factory(User::class)->create(['use_totp' => false]); + $user = User::factory()->create(['use_totp' => false]); // Make the initial call to get the account setup for 2FA. $this->actingAs($user)->getJson('/api/client/account/two-factor')->assertOk(); @@ -126,7 +126,7 @@ class TwoFactorControllerTest extends ClientApiIntegrationTestCase Carbon::setTestNow(Carbon::now()); /** @var \Pterodactyl\Models\User $user */ - $user = factory(User::class)->create(['use_totp' => true]); + $user = User::factory()->create(['use_totp' => true]); $response = $this->actingAs($user)->deleteJson('/api/client/account/two-factor', [ 'password' => 'invalid', @@ -157,7 +157,7 @@ class TwoFactorControllerTest extends ClientApiIntegrationTestCase Carbon::setTestNow(Carbon::now()); /** @var \Pterodactyl\Models\User $user */ - $user = factory(User::class)->create(['use_totp' => false]); + $user = User::factory()->create(['use_totp' => false]); $response = $this->actingAs($user)->deleteJson('/api/client/account/two-factor', [ 'password' => 'password', diff --git a/tests/Integration/Http/Controllers/Admin/UserControllerTest.php b/tests/Integration/Http/Controllers/Admin/UserControllerTest.php index a29844ca..5e271a8c 100644 --- a/tests/Integration/Http/Controllers/Admin/UserControllerTest.php +++ b/tests/Integration/Http/Controllers/Admin/UserControllerTest.php @@ -23,8 +23,8 @@ class UserControllerTest extends IntegrationTestCase { $unique = Str::random(16); $users = [ - factory(User::class)->create(['username' => $unique . '_1']), - factory(User::class)->create(['username' => $unique . '_2']), + User::factory()->create(['username' => $unique . '_1']), + User::factory()->create(['username' => $unique . '_2']), ]; $servers = [ diff --git a/tests/Integration/Services/Allocations/FindAssignableAllocationServiceTest.php b/tests/Integration/Services/Allocations/FindAssignableAllocationServiceTest.php index ce49a187..84d91fa9 100644 --- a/tests/Integration/Services/Allocations/FindAssignableAllocationServiceTest.php +++ b/tests/Integration/Services/Allocations/FindAssignableAllocationServiceTest.php @@ -32,7 +32,7 @@ class FindAssignableAllocationServiceTest extends IntegrationTestCase { $server = $this->createServerModel(); - $created = factory(Allocation::class)->create([ + $created = Allocation::factory()->create([ 'node_id' => $server->node_id, 'ip' => $server->allocation->ip, ]); @@ -74,7 +74,7 @@ class FindAssignableAllocationServiceTest extends IntegrationTestCase config()->set('pterodactyl.client_features.allocations.range_start', 5000); config()->set('pterodactyl.client_features.allocations.range_end', 5001); - factory(Allocation::class)->create([ + Allocation::factory()->create([ 'server_id' => $server2->id, 'node_id' => $server->node_id, 'ip' => $server->allocation->ip, @@ -93,7 +93,7 @@ class FindAssignableAllocationServiceTest extends IntegrationTestCase config()->set('pterodactyl.client_features.allocations.range_end', 5005); for ($i = 5000; $i <= 5005; $i++) { - factory(Allocation::class)->create([ + Allocation::factory()->create([ 'ip' => $server->allocation->ip, 'port' => $i, 'node_id' => $server->node_id, @@ -115,7 +115,7 @@ class FindAssignableAllocationServiceTest extends IntegrationTestCase { $server = $this->createServerModel(); - factory(Allocation::class)->times(5)->create(['node_id' => $server->node_id]); + Allocation::factory()->times(5)->create(['node_id' => $server->node_id]); $this->expectException(NoAutoAllocationSpaceAvailableException::class); $this->expectExceptionMessage('Cannot assign additional allocation: no more space available on node.'); diff --git a/tests/Integration/Services/Databases/DatabaseManagementServiceTest.php b/tests/Integration/Services/Databases/DatabaseManagementServiceTest.php index b5e1565a..4b12ac67 100644 --- a/tests/Integration/Services/Databases/DatabaseManagementServiceTest.php +++ b/tests/Integration/Services/Databases/DatabaseManagementServiceTest.php @@ -63,9 +63,9 @@ class DatabaseManagementServiceTest extends IntegrationTestCase public function testDatabaseCannotBeCreatedIfServerHasReachedLimit() { $server = $this->createServerModel(['database_limit' => 2]); - $host = factory(DatabaseHost::class)->create(['node_id' => $server->node_id]); + $host = DatabaseHost::factory()->create(['node_id' => $server->node_id]); - factory(Database::class)->times(2)->create(['server_id' => $server->id, 'database_host_id' => $host->id]); + Database::factory()->times(2)->create(['server_id' => $server->id, 'database_host_id' => $host->id]); $this->expectException(TooManyDatabasesException::class); @@ -96,9 +96,9 @@ class DatabaseManagementServiceTest extends IntegrationTestCase $server = $this->createServerModel(); $name = DatabaseManagementService::generateUniqueDatabaseName('soemthing', $server->id); - $host = factory(DatabaseHost::class)->create(['node_id' => $server->node_id]); - $host2 = factory(DatabaseHost::class)->create(['node_id' => $server->node_id]); - factory(Database::class)->create([ + $host = DatabaseHost::factory()->create(['node_id' => $server->node_id]); + $host2 = DatabaseHost::factory()->create(['node_id' => $server->node_id]); + Database::factory()->create([ 'database' => $name, 'database_host_id' => $host->id, 'server_id' => $server->id, @@ -125,7 +125,7 @@ class DatabaseManagementServiceTest extends IntegrationTestCase $server = $this->createServerModel(); $name = DatabaseManagementService::generateUniqueDatabaseName('soemthing', $server->id); - $host = factory(DatabaseHost::class)->create(['node_id' => $server->node_id]); + $host = DatabaseHost::factory()->create(['node_id' => $server->node_id]); $this->repository->expects('createDatabase')->with($name); @@ -183,7 +183,7 @@ class DatabaseManagementServiceTest extends IntegrationTestCase $server = $this->createServerModel(); $name = DatabaseManagementService::generateUniqueDatabaseName('soemthing', $server->id); - $host = factory(DatabaseHost::class)->create(['node_id' => $server->node_id]); + $host = DatabaseHost::factory()->create(['node_id' => $server->node_id]); $this->repository->expects('createDatabase')->with($name)->andThrows(new BadMethodCallException); $this->repository->expects('dropDatabase')->with($name); diff --git a/tests/Integration/Services/Databases/DeployServerDatabaseServiceTest.php b/tests/Integration/Services/Databases/DeployServerDatabaseServiceTest.php index cc66ffe8..1628dcfc 100644 --- a/tests/Integration/Services/Databases/DeployServerDatabaseServiceTest.php +++ b/tests/Integration/Services/Databases/DeployServerDatabaseServiceTest.php @@ -65,8 +65,8 @@ class DeployServerDatabaseServiceTest extends IntegrationTestCase { $server = $this->createServerModel(); - $node = factory(Node::class)->create(['location_id' => $server->location->id]); - factory(DatabaseHost::class)->create(['node_id' => $node->id]); + $node = Node::factory()->create(['location_id' => $server->location->id]); + DatabaseHost::factory()->create(['node_id' => $node->id]); config()->set('pterodactyl.client_features.databases.allow_random', false); @@ -100,9 +100,9 @@ class DeployServerDatabaseServiceTest extends IntegrationTestCase { $server = $this->createServerModel(); - $node = factory(Node::class)->create(['location_id' => $server->location->id]); - factory(DatabaseHost::class)->create(['node_id' => $node->id]); - $host = factory(DatabaseHost::class)->create(['node_id' => $server->node_id]); + $node = Node::factory()->create(['location_id' => $server->location->id]); + DatabaseHost::factory()->create(['node_id' => $node->id]); + $host = DatabaseHost::factory()->create(['node_id' => $server->node_id]); $this->managementService->expects('create')->with($server, [ 'database_host_id' => $host->id, @@ -127,8 +127,8 @@ class DeployServerDatabaseServiceTest extends IntegrationTestCase { $server = $this->createServerModel(); - $node = factory(Node::class)->create(['location_id' => $server->location->id]); - $host = factory(DatabaseHost::class)->create(['node_id' => $node->id]); + $node = Node::factory()->create(['location_id' => $server->location->id]); + $host = DatabaseHost::factory()->create(['node_id' => $node->id]); $this->managementService->expects('create')->with($server, [ 'database_host_id' => $host->id, diff --git a/tests/Integration/Services/Deployment/FindViableNodesServiceTest.php b/tests/Integration/Services/Deployment/FindViableNodesServiceTest.php index abc0bd9a..d5fcb448 100644 --- a/tests/Integration/Services/Deployment/FindViableNodesServiceTest.php +++ b/tests/Integration/Services/Deployment/FindViableNodesServiceTest.php @@ -71,24 +71,24 @@ class FindViableNodesServiceTest extends IntegrationTestCase public function testExpectedNodeIsReturnedForLocation() { /** @var \Pterodactyl\Models\Location[] $locations */ - $locations = factory(Location::class)->times(2)->create(); + $locations = Location::factory()->times(2)->create(); /** @var \Pterodactyl\Models\Node[] $nodes */ $nodes = [ // This node should never be returned once we've completed the initial test which // runs without a location filter. - factory(Node::class)->create([ + Node::factory()->create([ 'location_id' => $locations[0]->id, 'memory' => 2048, 'disk' => 1024 * 100, ]), - factory(Node::class)->create([ + Node::factory()->create([ 'location_id' => $locations[1]->id, 'memory' => 1024, 'disk' => 10240, 'disk_overallocate' => 10, ]), - factory(Node::class)->create([ + Node::factory()->create([ 'location_id' => $locations[1]->id, 'memory' => 1024 * 4, 'memory_overallocate' => 50, diff --git a/tests/Integration/Services/Schedules/ProcessScheduleServiceTest.php b/tests/Integration/Services/Schedules/ProcessScheduleServiceTest.php index 93c793d6..b36332ee 100644 --- a/tests/Integration/Services/Schedules/ProcessScheduleServiceTest.php +++ b/tests/Integration/Services/Schedules/ProcessScheduleServiceTest.php @@ -23,7 +23,7 @@ class ProcessScheduleServiceTest extends IntegrationTestCase public function testScheduleWithNoTasksReturnsException() { $server = $this->createServerModel(); - $schedule = factory(Schedule::class)->create(['server_id' => $server->id]); + $schedule = Schedule::factory()->create(['server_id' => $server->id]); $this->expectException(DisplayException::class); $this->expectExceptionMessage('Cannot process schedule for task execution: no tasks are registered.'); @@ -39,13 +39,13 @@ class ProcessScheduleServiceTest extends IntegrationTestCase $server = $this->createServerModel(); /** @var \Pterodactyl\Models\Schedule $schedule */ - $schedule = factory(Schedule::class)->create([ + $schedule = Schedule::factory()->create([ 'server_id' => $server->id, 'cron_minute' => 'hodor', // this will break the getNextRunDate() function. ]); /** @var \Pterodactyl\Models\Task $task */ - $task = factory(Task::class)->create(['schedule_id' => $schedule->id, 'sequence_id' => 1]); + $task = Task::factory()->create(['schedule_id' => $schedule->id, 'sequence_id' => 1]); $this->expectException(InvalidArgumentException::class); @@ -68,10 +68,10 @@ class ProcessScheduleServiceTest extends IntegrationTestCase $server = $this->createServerModel(); /** @var \Pterodactyl\Models\Schedule $schedule */ - $schedule = factory(Schedule::class)->create(['server_id' => $server->id]); + $schedule = Schedule::factory()->create(['server_id' => $server->id]); /** @var \Pterodactyl\Models\Task $task */ - $task = factory(Task::class)->create(['schedule_id' => $schedule->id, 'time_offset' => 10, 'sequence_id' => 1]); + $task = Task::factory()->create(['schedule_id' => $schedule->id, 'time_offset' => 10, 'sequence_id' => 1]); $this->getService()->handle($schedule, $now); @@ -100,12 +100,12 @@ class ProcessScheduleServiceTest extends IntegrationTestCase $server = $this->createServerModel(); /** @var \Pterodactyl\Models\Schedule $schedule */ - $schedule = factory(Schedule::class)->create(['server_id' => $server->id]); + $schedule = Schedule::factory()->create(['server_id' => $server->id]); /** @var \Pterodactyl\Models\Task $task */ - $task2 = factory(Task::class)->create(['schedule_id' => $schedule->id, 'sequence_id' => 4]); - $task = factory(Task::class)->create(['schedule_id' => $schedule->id, 'sequence_id' => 2]); - $task3 = factory(Task::class)->create(['schedule_id' => $schedule->id, 'sequence_id' => 3]); + $task2 = Task::factory()->create(['schedule_id' => $schedule->id, 'sequence_id' => 4]); + $task = Task::factory()->create(['schedule_id' => $schedule->id, 'sequence_id' => 2]); + $task3 = Task::factory()->create(['schedule_id' => $schedule->id, 'sequence_id' => 3]); $this->getService()->handle($schedule); @@ -131,9 +131,9 @@ class ProcessScheduleServiceTest extends IntegrationTestCase $server = $this->createServerModel(); /** @var \Pterodactyl\Models\Schedule $schedule */ - $schedule = factory(Schedule::class)->create(['server_id' => $server->id, 'last_run_at' => null]); + $schedule = Schedule::factory()->create(['server_id' => $server->id, 'last_run_at' => null]); /** @var \Pterodactyl\Models\Task $task */ - $task = factory(Task::class)->create(['schedule_id' => $schedule->id, 'sequence_id' => 1]); + $task = Task::factory()->create(['schedule_id' => $schedule->id, 'sequence_id' => 1]); $dispatcher->expects('dispatchNow')->andThrows(new Exception('Test thrown exception')); diff --git a/tests/Integration/Services/Servers/BuildModificationServiceTest.php b/tests/Integration/Services/Servers/BuildModificationServiceTest.php index 4444cc85..a3939776 100644 --- a/tests/Integration/Services/Servers/BuildModificationServiceTest.php +++ b/tests/Integration/Services/Servers/BuildModificationServiceTest.php @@ -36,7 +36,7 @@ class BuildModificationServiceTest extends IntegrationTestCase $server2 = $this->createServerModel(); /** @var \Pterodactyl\Models\Allocation[] $allocations */ - $allocations = factory(Allocation::class)->times(4)->create(['node_id' => $server->node_id, 'notes' => 'Random notes']); + $allocations = Allocation::factory()->times(4)->create(['node_id' => $server->node_id, 'notes' => 'Random notes']); $initialAllocationId = $server->allocation_id; $allocations[0]->update(['server_id' => $server->id, 'notes' => 'Test notes']); @@ -83,7 +83,7 @@ class BuildModificationServiceTest extends IntegrationTestCase { $server = $this->createServerModel(); /** @var \Pterodactyl\Models\Allocation[] $allocations */ - $allocations = factory(Allocation::class)->times(4)->create(['node_id' => $server->node_id]); + $allocations = Allocation::factory()->times(4)->create(['node_id' => $server->node_id]); $allocations[0]->update(['server_id' => $server->id]); @@ -156,7 +156,7 @@ class BuildModificationServiceTest extends IntegrationTestCase { $server = $this->createServerModel(); /** @var \Pterodactyl\Models\Allocation[] $allocations */ - $allocation = factory(Allocation::class)->create(['node_id' => $server->node_id, 'server_id' => $server->id]); + $allocation = Allocation::factory()->create(['node_id' => $server->node_id, 'server_id' => $server->id]); $this->daemonServerRepository->expects('setServer->update')->andReturnUndefined(); @@ -179,7 +179,7 @@ class BuildModificationServiceTest extends IntegrationTestCase { $server = $this->createServerModel(); /** @var \Pterodactyl\Models\Allocation[] $allocations */ - $allocation = factory(Allocation::class)->create(['node_id' => $server->node_id]); + $allocation = Allocation::factory()->create(['node_id' => $server->node_id]); $this->daemonServerRepository->expects('setServer->update')->andReturnUndefined(); @@ -198,8 +198,8 @@ class BuildModificationServiceTest extends IntegrationTestCase { $server = $this->createServerModel(); /** @var \Pterodactyl\Models\Allocation[] $allocations */ - $allocation = factory(Allocation::class)->create(['node_id' => $server->node_id, 'server_id' => $server->id]); - $allocation2 = factory(Allocation::class)->create(['node_id' => $server->node_id]); + $allocation = Allocation::factory()->create(['node_id' => $server->node_id, 'server_id' => $server->id]); + $allocation2 = Allocation::factory()->create(['node_id' => $server->node_id]); $this->daemonServerRepository->expects('setServer->update')->andReturnUndefined(); @@ -220,7 +220,7 @@ class BuildModificationServiceTest extends IntegrationTestCase { $server = $this->createServerModel(); /** @var \Pterodactyl\Models\Allocation[] $allocations */ - $allocation = factory(Allocation::class)->create(['node_id' => $server->node_id]); + $allocation = Allocation::factory()->create(['node_id' => $server->node_id]); $this->daemonServerRepository->expects('setServer->update')->andThrows(new DisplayException('Test')); diff --git a/tests/Integration/Services/Servers/ServerCreationServiceTest.php b/tests/Integration/Services/Servers/ServerCreationServiceTest.php index daf198f2..abe26e7b 100644 --- a/tests/Integration/Services/Servers/ServerCreationServiceTest.php +++ b/tests/Integration/Services/Servers/ServerCreationServiceTest.php @@ -48,15 +48,15 @@ class ServerCreationServiceTest extends IntegrationTestCase public function testServerIsCreatedWithDeploymentObject() { /** @var \Pterodactyl\Models\User $user */ - $user = factory(User::class)->create(); + $user = User::factory()->create(); /** @var \Pterodactyl\Models\Node $node */ - $node = factory(Node::class)->create([ - 'location_id' => factory(Location::class)->create()->id, + $node = Node::factory()->create([ + 'location_id' => Location::factory()->create()->id, ]); /** @var \Pterodactyl\Models\Allocation[]|\Illuminate\Database\Eloquent\Collection $allocations */ - $allocations = factory(Allocation::class)->times(5)->create([ + $allocations = Allocation::factory()->times(5)->create([ 'node_id' => $node->id, ]); @@ -156,15 +156,15 @@ class ServerCreationServiceTest extends IntegrationTestCase public function testErrorEncounteredByWingsCausesServerToBeDeleted() { /** @var \Pterodactyl\Models\User $user */ - $user = factory(User::class)->create(); + $user = User::factory()->create(); /** @var \Pterodactyl\Models\Node $node */ - $node = factory(Node::class)->create([ - 'location_id' => factory(Location::class)->create()->id, + $node = Node::factory()->create([ + 'location_id' => Location::factory()->create()->id, ]); /** @var \Pterodactyl\Models\Allocation $allocation */ - $allocation = factory(Allocation::class)->create([ + $allocation = Allocation::factory()->create([ 'node_id' => $node->id, ]); diff --git a/tests/Integration/Services/Servers/ServerDeletionServiceTest.php b/tests/Integration/Services/Servers/ServerDeletionServiceTest.php index bcc4cce2..80e7b470 100644 --- a/tests/Integration/Services/Servers/ServerDeletionServiceTest.php +++ b/tests/Integration/Services/Servers/ServerDeletionServiceTest.php @@ -113,10 +113,10 @@ class ServerDeletionServiceTest extends IntegrationTestCase public function testExceptionWhileDeletingStopsProcess() { $server = $this->createServerModel(); - $host = factory(DatabaseHost::class)->create(); + $host = DatabaseHost::factory()->create(); /** @var \Pterodactyl\Models\Database $db */ - $db = factory(Database::class)->create(['database_host_id' => $host->id, 'server_id' => $server->id]); + $db = Database::factory()->create(['database_host_id' => $host->id, 'server_id' => $server->id]); $server->refresh(); @@ -138,10 +138,10 @@ class ServerDeletionServiceTest extends IntegrationTestCase public function testExceptionWhileDeletingDatabasesDoesNotAbortIfForceDeleted() { $server = $this->createServerModel(); - $host = factory(DatabaseHost::class)->create(); + $host = DatabaseHost::factory()->create(); /** @var \Pterodactyl\Models\Database $db */ - $db = factory(Database::class)->create(['database_host_id' => $host->id, 'server_id' => $server->id]); + $db = Database::factory()->create(['database_host_id' => $host->id, 'server_id' => $server->id]); $server->refresh(); diff --git a/tests/Traits/Http/RequestMockHelpers.php b/tests/Traits/Http/RequestMockHelpers.php index f33ff71e..e85f199b 100644 --- a/tests/Traits/Http/RequestMockHelpers.php +++ b/tests/Traits/Http/RequestMockHelpers.php @@ -50,7 +50,7 @@ trait RequestMockHelpers */ public function generateRequestUserModel(array $args = []): User { - $user = factory(User::class)->make($args); + $user = User::factory()->make($args); $this->setRequestUserModel($user); return $user; @@ -100,7 +100,7 @@ trait RequestMockHelpers */ protected function setRequestUser(User $user = null): User { - $user = $user instanceof User ? $user : factory(User::class)->make(); + $user = $user instanceof User ? $user : User::factory()->make(); $this->request->shouldReceive('user')->withNoArgs()->andReturn($user); return $user; diff --git a/tests/Unit/Http/Middleware/AdminAuthenticateTest.php b/tests/Unit/Http/Middleware/AdminAuthenticateTest.php index efe6e821..c56ac4d4 100644 --- a/tests/Unit/Http/Middleware/AdminAuthenticateTest.php +++ b/tests/Unit/Http/Middleware/AdminAuthenticateTest.php @@ -13,7 +13,7 @@ class AdminAuthenticateTest extends MiddlewareTestCase */ public function testAdminsAreAuthenticated() { - $user = factory(User::class)->make(['root_admin' => 1]); + $user = User::factory()->make(['root_admin' => 1]); $this->request->shouldReceive('user')->withNoArgs()->twice()->andReturn($user); @@ -39,7 +39,7 @@ class AdminAuthenticateTest extends MiddlewareTestCase { $this->expectException(AccessDeniedHttpException::class); - $user = factory(User::class)->make(['root_admin' => 0]); + $user = User::factory()->make(['root_admin' => 0]); $this->request->shouldReceive('user')->withNoArgs()->twice()->andReturn($user); diff --git a/tests/Unit/Http/Middleware/Api/AuthenticateIPAccessTest.php b/tests/Unit/Http/Middleware/Api/AuthenticateIPAccessTest.php index 54562631..76fe2355 100644 --- a/tests/Unit/Http/Middleware/Api/AuthenticateIPAccessTest.php +++ b/tests/Unit/Http/Middleware/Api/AuthenticateIPAccessTest.php @@ -14,7 +14,7 @@ class AuthenticateIPAccessTest extends MiddlewareTestCase */ public function testWithNoIPRestrictions() { - $model = factory(ApiKey::class)->make(['allowed_ips' => []]); + $model = ApiKey::factory()->make(['allowed_ips' => []]); $this->setRequestAttribute('api_key', $model); $this->getMiddleware()->handle($this->request, $this->getClosureAssertions()); @@ -26,7 +26,7 @@ class AuthenticateIPAccessTest extends MiddlewareTestCase */ public function testWithValidIP() { - $model = factory(ApiKey::class)->make(['allowed_ips' => ['127.0.0.1']]); + $model = ApiKey::factory()->make(['allowed_ips' => ['127.0.0.1']]); $this->setRequestAttribute('api_key', $model); $this->request->shouldReceive('ip')->withNoArgs()->once()->andReturn('127.0.0.1'); @@ -39,7 +39,7 @@ class AuthenticateIPAccessTest extends MiddlewareTestCase */ public function testValidIPAgainstCIDRRange() { - $model = factory(ApiKey::class)->make(['allowed_ips' => ['192.168.1.1/28']]); + $model = ApiKey::factory()->make(['allowed_ips' => ['192.168.1.1/28']]); $this->setRequestAttribute('api_key', $model); $this->request->shouldReceive('ip')->withNoArgs()->once()->andReturn('192.168.1.15'); @@ -55,7 +55,7 @@ class AuthenticateIPAccessTest extends MiddlewareTestCase { $this->expectException(AccessDeniedHttpException::class); - $model = factory(ApiKey::class)->make(['allowed_ips' => ['127.0.0.1']]); + $model = ApiKey::factory()->make(['allowed_ips' => ['127.0.0.1']]); $this->setRequestAttribute('api_key', $model); $this->request->shouldReceive('ip')->withNoArgs()->twice()->andReturn('127.0.0.2'); diff --git a/tests/Unit/Http/Middleware/Api/AuthenticateKeyTest.php b/tests/Unit/Http/Middleware/Api/AuthenticateKeyTest.php index 79715e4c..c0159e67 100644 --- a/tests/Unit/Http/Middleware/Api/AuthenticateKeyTest.php +++ b/tests/Unit/Http/Middleware/Api/AuthenticateKeyTest.php @@ -79,7 +79,7 @@ class AuthenticateKeyTest extends MiddlewareTestCase */ public function testValidToken() { - $model = factory(ApiKey::class)->make(); + $model = ApiKey::factory()->make(); $this->request->shouldReceive('bearerToken')->withNoArgs()->twice()->andReturn($model->identifier . 'decrypted'); $this->repository->shouldReceive('findFirstWhere')->with([ @@ -102,7 +102,7 @@ class AuthenticateKeyTest extends MiddlewareTestCase */ public function testValidTokenWithUserKey() { - $model = factory(ApiKey::class)->make(); + $model = ApiKey::factory()->make(); $this->request->shouldReceive('bearerToken')->withNoArgs()->twice()->andReturn($model->identifier . 'decrypted'); $this->repository->shouldReceive('findFirstWhere')->with([ @@ -126,7 +126,7 @@ class AuthenticateKeyTest extends MiddlewareTestCase */ public function testAccessWithoutToken() { - $user = factory(User::class)->make(['id' => 123]); + $user = User::factory()->make(['id' => 123]); $this->request->shouldReceive('user')->andReturn($user); $this->request->shouldReceive('bearerToken')->withNoArgs()->twice()->andReturnNull(); @@ -147,7 +147,7 @@ class AuthenticateKeyTest extends MiddlewareTestCase { $this->expectException(AccessDeniedHttpException::class); - $model = factory(ApiKey::class)->make(); + $model = ApiKey::factory()->make(); $this->request->shouldReceive('bearerToken')->withNoArgs()->twice()->andReturn($model->identifier . 'asdf'); $this->repository->shouldReceive('findFirstWhere')->with([ diff --git a/tests/Unit/Http/Middleware/Api/Daemon/DaemonAuthenticateTest.php b/tests/Unit/Http/Middleware/Api/Daemon/DaemonAuthenticateTest.php index 35699eb6..dff1c154 100644 --- a/tests/Unit/Http/Middleware/Api/Daemon/DaemonAuthenticateTest.php +++ b/tests/Unit/Http/Middleware/Api/Daemon/DaemonAuthenticateTest.php @@ -92,7 +92,7 @@ class DaemonAuthenticateTest extends MiddlewareTestCase $this->expectException(AccessDeniedHttpException::class); /** @var \Pterodactyl\Models\Node $model */ - $model = factory(Node::class)->make(); + $model = Node::factory()->make(); $this->request->expects('route->getName')->withNoArgs()->andReturn('random.route'); $this->request->expects('bearerToken')->withNoArgs()->andReturn($model->daemon_token_id . '.random_string_123'); @@ -125,7 +125,7 @@ class DaemonAuthenticateTest extends MiddlewareTestCase public function testSuccessfulMiddlewareProcess() { /** @var \Pterodactyl\Models\Node $model */ - $model = factory(Node::class)->make(); + $model = Node::factory()->make(); $this->request->expects('route->getName')->withNoArgs()->andReturn('random.route'); $this->request->expects('bearerToken')->withNoArgs()->andReturn($model->daemon_token_id . '.' . decrypt($model->daemon_token)); diff --git a/tests/Unit/Http/Middleware/LanguageMiddlewareTest.php b/tests/Unit/Http/Middleware/LanguageMiddlewareTest.php index ad22bdca..ac7b0832 100644 --- a/tests/Unit/Http/Middleware/LanguageMiddlewareTest.php +++ b/tests/Unit/Http/Middleware/LanguageMiddlewareTest.php @@ -40,7 +40,7 @@ class LanguageMiddlewareTest extends MiddlewareTestCase */ public function testLanguageIsSetWithAuthenticatedUser() { - $user = factory(User::class)->make(['language' => 'de']); + $user = User::factory()->make(['language' => 'de']); $this->request->shouldReceive('user')->withNoArgs()->andReturn($user); $this->appMock->shouldReceive('setLocale')->with('de')->once()->andReturnNull(); diff --git a/tests/Unit/Http/Middleware/MaintenanceMiddlewareTest.php b/tests/Unit/Http/Middleware/MaintenanceMiddlewareTest.php index 68b971e6..38003368 100644 --- a/tests/Unit/Http/Middleware/MaintenanceMiddlewareTest.php +++ b/tests/Unit/Http/Middleware/MaintenanceMiddlewareTest.php @@ -31,8 +31,8 @@ class MaintenanceMiddlewareTest extends MiddlewareTestCase */ public function testHandle() { - $server = factory(Server::class)->make(); - $node = factory(Node::class)->make(['maintenance' => 0]); + $server = Server::factory()->make(); + $node = Node::factory()->make(['maintenance' => 0]); $server->setRelation('node', $node); $this->setRequestAttribute('server', $server); @@ -45,8 +45,8 @@ class MaintenanceMiddlewareTest extends MiddlewareTestCase */ public function testHandleInMaintenanceMode() { - $server = factory(Server::class)->make(); - $node = factory(Node::class)->make(['maintenance_mode' => 1]); + $server = Server::factory()->make(); + $node = Node::factory()->make(['maintenance_mode' => 1]); $server->setRelation('node', $node); $this->setRequestAttribute('server', $server); diff --git a/tests/Unit/Http/Middleware/Server/AccessingValidServerTest.php b/tests/Unit/Http/Middleware/Server/AccessingValidServerTest.php index 5cedbd9b..8ecdcae6 100644 --- a/tests/Unit/Http/Middleware/Server/AccessingValidServerTest.php +++ b/tests/Unit/Http/Middleware/Server/AccessingValidServerTest.php @@ -49,7 +49,7 @@ class AccessingValidServerTest extends MiddlewareTestCase $this->expectException(AccessDeniedHttpException::class); $this->expectExceptionMessage('Server is suspended and cannot be accessed.'); - $model = factory(Server::class)->make(['suspended' => 1]); + $model = Server::factory()->make(['suspended' => 1]); $this->request->shouldReceive('route->parameter')->with('server')->once()->andReturn('123456'); $this->request->shouldReceive('expectsJson')->withNoArgs()->once()->andReturn(true); @@ -67,7 +67,7 @@ class AccessingValidServerTest extends MiddlewareTestCase $this->expectException(ConflictHttpException::class); $this->expectExceptionMessage('Server is still completing the installation process.'); - $model = factory(Server::class)->make(['installed' => 0]); + $model = Server::factory()->make(['installed' => 0]); $this->request->shouldReceive('route->parameter')->with('server')->once()->andReturn('123456'); $this->request->shouldReceive('expectsJson')->withNoArgs()->once()->andReturn(true); @@ -101,7 +101,7 @@ class AccessingValidServerTest extends MiddlewareTestCase */ public function testValidServerProcess() { - $model = factory(Server::class)->make(); + $model = Server::factory()->make(); $this->request->shouldReceive('route->parameter')->with('server')->once()->andReturn('123456'); $this->request->shouldReceive('expectsJson')->withNoArgs()->once()->andReturn(false); @@ -126,9 +126,9 @@ class AccessingValidServerTest extends MiddlewareTestCase $this->refreshApplication(); return [ - [factory(Server::class)->make(['suspended' => 1]), 'errors.suspended', 403], - [factory(Server::class)->make(['installed' => 0]), 'errors.installing', 409], - [factory(Server::class)->make(['installed' => 2]), 'errors.installing', 409], + [Server::factory()->make(['suspended' => 1]), 'errors.suspended', 403], + [Server::factory()->make(['installed' => 0]), 'errors.installing', 409], + [Server::factory()->make(['installed' => 2]), 'errors.installing', 409], ]; } diff --git a/tests/Unit/Services/Acl/Api/AdminAclTest.php b/tests/Unit/Services/Acl/Api/AdminAclTest.php index 325af82c..ca8aa1eb 100644 --- a/tests/Unit/Services/Acl/Api/AdminAclTest.php +++ b/tests/Unit/Services/Acl/Api/AdminAclTest.php @@ -23,7 +23,7 @@ class AdminAclTest extends TestCase */ public function testCheck() { - $model = factory(ApiKey::class)->make(['r_servers' => AdminAcl::READ | AdminAcl::WRITE]); + $model = ApiKey::factory()->make(['r_servers' => AdminAcl::READ | AdminAcl::WRITE]); $this->assertTrue(AdminAcl::check($model, AdminAcl::RESOURCE_SERVERS, AdminAcl::WRITE)); } diff --git a/tests/Unit/Services/Api/KeyCreationServiceTest.php b/tests/Unit/Services/Api/KeyCreationServiceTest.php index 3f04f24e..fee5a559 100644 --- a/tests/Unit/Services/Api/KeyCreationServiceTest.php +++ b/tests/Unit/Services/Api/KeyCreationServiceTest.php @@ -40,7 +40,7 @@ class KeyCreationServiceTest extends TestCase */ public function testKeyIsCreated() { - $model = factory(ApiKey::class)->make(); + $model = ApiKey::factory()->make(); $this->getFunctionMock('\\Pterodactyl\\Services\\Api', 'str_random') ->expects($this->exactly(2))->willReturnCallback(function ($length) { @@ -68,7 +68,7 @@ class KeyCreationServiceTest extends TestCase */ public function testIdentifierAndTokenAreOnlySetByFunction() { - $model = factory(ApiKey::class)->make(); + $model = ApiKey::factory()->make(); $this->getFunctionMock('\\Pterodactyl\\Services\\Api', 'str_random') ->expects($this->exactly(2))->willReturnCallback(function ($length) { @@ -95,7 +95,7 @@ class KeyCreationServiceTest extends TestCase */ public function testPermissionsAreRetrievedForApplicationKeys() { - $model = factory(ApiKey::class)->make(); + $model = ApiKey::factory()->make(); $this->getFunctionMock('\\Pterodactyl\\Services\\Api', 'str_random') ->expects($this->exactly(2))->willReturnCallback(function ($length) { @@ -125,7 +125,7 @@ class KeyCreationServiceTest extends TestCase */ public function testPermissionsAreNotRetrievedForNonApplicationKeys($keyType) { - $model = factory(ApiKey::class)->make(); + $model = ApiKey::factory()->make(); $this->getFunctionMock('\\Pterodactyl\\Services\\Api', 'str_random') ->expects($this->exactly(2))->willReturnCallback(function ($length) {