From e1eb42059fa056b1c0f9ee7cefe6b7159f7ed205 Mon Sep 17 00:00:00 2001 From: Saeed Vaziry Date: Sat, 2 Sep 2023 16:41:42 +0200 Subject: [PATCH 1/3] code style fix add command tests --- .github/workflows/style-check.yml | 54 ++++++++ .github/workflows/tests.yml | 23 +--- app/Actions/Database/CreateBackup.php | 2 +- app/Actions/FirewallRule/CreateRule.php | 1 - .../SourceControl/ConnectSourceControl.php | 10 +- .../StorageProvider/CreateStorageProvider.php | 12 +- app/Console/Commands/CreateUserCommand.php | 3 +- app/Contracts/StorageProvider.php | 1 - app/Enums/ServerType.php | 1 + app/Helpers/SSH.php | 6 +- app/Http/Kernel.php | 2 +- .../Databases/DatabaseBackupFiles.php | 6 +- .../Livewire/Databases/DatabaseBackups.php | 2 +- .../Installation/ContinueInstallation.php | 2 + app/Jobs/Installation/UninstallPHPMyAdmin.php | 4 +- app/Jobs/Site/Deploy.php | 4 +- app/Jobs/Site/DeployKey.php | 2 +- app/Listeners/BroadcastListener.php | 2 +- app/Models/Site.php | 2 +- app/Providers/EventServiceProvider.php | 1 - .../Database/BackupDatabaseCommand.php | 2 +- app/SSHCommands/Database/CreateCommand.php | 2 +- .../Database/CreateUserCommand.php | 2 +- app/SSHCommands/Database/DeleteCommand.php | 2 +- .../Database/DeleteUserCommand.php | 2 +- app/SSHCommands/Database/LinkCommand.php | 2 +- .../Database/RestoreDatabaseCommand.php | 2 +- app/SSHCommands/Database/UnlinkCommand.php | 2 +- app/SSHCommands/Firewall/AddRuleCommand.php | 2 +- .../Firewall/RemoveRuleCommand.php | 2 +- app/SSHCommands/Nginx/InstallNginxCommand.php | 1 - app/SSHCommands/PHP/InstallPHPCommand.php | 1 - app/SSHCommands/PHP/UninstallPHPCommand.php | 1 - ... => DeleteNginxPHPMyAdminVHostCommand.php} | 2 +- app/SSHCommands/SSL/RemoveSSLCommand.php | 2 +- .../{RunScript.php => RunScriptCommand.php} | 4 +- app/ServerProviders/AWS.php | 1 - app/ServerProviders/DigitalOcean.php | 1 - app/ServerProviders/Hetzner.php | 1 - app/ServerProviders/Linode.php | 3 +- app/ServerProviders/Vultr.php | 1 - app/ServerTypes/Database.php | 3 - app/SourceControlProviders/Bitbucket.php | 5 +- app/SourceControlProviders/Github.php | 4 +- app/SourceControlProviders/Gitlab.php | 4 +- app/StorageProviders/Dropbox.php | 4 +- config/app.php | 2 +- config/core.php | 3 +- database/factories/BackupFactory.php | 2 +- database/factories/ServerLogFactory.php | 1 - database/factories/ServiceFactory.php | 2 - database/factories/SiteFactory.php | 2 +- database/factories/SshKeyFactory.php | 1 - ..._21_210213_update_firewall_rules_table.php | 3 +- ...43530_add_ssh_key_field_to_sites_table.php | 3 +- ...63805_add_url_to_source_controls_table.php | 3 +- ...8_add_profile_to_source_controls_table.php | 3 +- ...8_add_source_control_id_to_sites_table.php | 3 +- ..._095440_update_storage_providers_table.php | 3 +- ...2023_08_17_231824_update_backups_table.php | 3 +- ...08_25_183201_update_backup_files_table.php | 3 +- database/seeders/DatabaseSeeder.php | 10 +- resources/commands/php/change-default-php.sh | 2 +- resources/commands/system/run-script.sh | 4 +- tests/Feature/Http/ApplicationTest.php | 4 +- tests/Feature/Http/CronjobTest.php | 2 +- tests/Feature/Http/DatabaseBackupTest.php | 6 +- tests/Feature/Http/FirewallTest.php | 8 +- tests/Feature/Http/PHP.php | 2 +- tests/Feature/Http/QueuesTest.php | 2 +- tests/Feature/Http/ServerKeysTest.php | 6 +- tests/Feature/Http/ServicesTest.php | 2 +- tests/Feature/Http/SourceControlsTest.php | 5 +- tests/Feature/Http/StorageProvidersTest.php | 4 +- .../CronJob/UpdateCronJobsCommandTest.php | 18 +++ .../Database/BackupDatabaseCommandTest.php | 20 +++ .../Database/CreateCommandTest.php | 18 +++ .../Database/CreateUserCommandTest.php | 18 +++ .../Database/DeleteCommandTest.php | 16 +++ .../Database/DeleteUserCommandTest.php | 18 +++ .../Database/InstallMariadbCommandTest.php | 31 +++++ .../Database/InstallMysqlCommandTest.php | 61 ++++++++++ .../SSHCommands/Database/LinkCommandTest.php | 28 +++++ .../Database/UnlinkCommandTest.php | 24 ++++ .../Firewall/AddRuleCommandTest.php | 30 +++++ .../Firewall/InstallUfwCommandTest.php | 46 +++++++ .../Firewall/RemoveRuleCommandTest.php | 31 +++++ .../Installation/InstallNodejsCommandTest.php | 24 ++++ .../Installation/InstallRedisCommandTest.php | 26 ++++ .../InstallRequirementsCommandTest.php | 22 ++++ .../ChangeNginxPHPVersionCommandTest.php | 28 +++++ .../Nginx/CreateNginxVHostCommandTest.php | 46 +++++++ .../Nginx/DeleteNginxSiteCommandTest.php | 26 ++++ .../Nginx/InstallNginxCommandTest.php | 115 ++++++++++++++++++ .../Nginx/UpdateNginxRedirectsCommandTest.php | 26 ++++ .../Nginx/UpdateNginxVHostCommandTest.php | 26 ++++ .../PHP/ChangeDefaultPHPCommandTest.php | 30 +++++ .../SSHCommands/PHP/GetPHPIniCommandTest.php | 20 +++ .../PHP/InstallComposerCommandTest.php | 26 ++++ .../SSHCommands/PHP/InstallPHPCommandTest.php | 32 +++++ .../PHP/InstallPHPExtensionCommandTest.php | 24 ++++ .../PHP/UninstallPHPCommandTest.php | 24 ++++ .../CreateNginxPHPMyAdminVHostCommandTest.php | 36 ++++++ .../DeleteNginxPHPMyAdminVHostCommandTest.php | 30 +++++ .../DownloadPHPMyAdminCommandTest.php | 40 ++++++ .../SSL/CreateCustomSSLCommandTest.php | 32 +++++ .../SSL/CreateLetsencryptSSLCommandTest.php | 22 ++++ .../SSL/InstallCertbotCommandTest.php | 20 +++ .../SSHCommands/SSL/RemoveSSLCommandTest.php | 20 +++ .../Service/RestartServiceCommandTest.php | 22 ++++ .../Service/ServiceStatusCommandTest.php | 20 +++ .../Service/StartServiceCommandTest.php | 22 ++++ .../Service/StopServiceCommandTest.php | 22 ++++ .../DownloadFromDropboxCommandTest.php | 23 ++++ .../Storage/UploadToDropboxCommandTest.php | 25 ++++ .../Supervisor/CreateWorkerCommandTest.php | 40 ++++++ .../Supervisor/DeleteWorkerCommandTest.php | 38 ++++++ .../InstallSupervisorCommandTest.php | 24 ++++ .../Supervisor/RestartWorkerCommandTest.php | 22 ++++ .../Supervisor/StartWorkerCommandTest.php | 22 ++++ .../Supervisor/StopWorkerCommandTest.php | 22 ++++ .../System/CreateUserCommandTest.php | 30 +++++ .../System/DeleteSshKeyCommandTest.php | 20 +++ .../System/DeploySshKeyCommandTest.php | 22 ++++ .../System/EditFileCommandTest.php | 22 ++++ .../System/GenerateSshKeyCommandTest.php | 20 +++ .../System/GetPublicKeyCommandTest.php | 20 +++ .../System/ReadFileCommandTest.php | 20 +++ .../System/ReadSshKeyCommandTest.php | 20 +++ .../SSHCommands/System/RebootCommandTest.php | 22 ++++ .../System/RunScriptCommandTest.php | 26 ++++ .../SSHCommands/System/UpgradeCommandTest.php | 26 ++++ .../Website/CloneRepositoryCommandTest.php | 46 +++++++ .../Website/ComposerInstallCommandTest.php | 26 ++++ .../Website/UpdateBranchCommandTest.php | 26 ++++ 135 files changed, 1859 insertions(+), 135 deletions(-) create mode 100644 .github/workflows/style-check.yml rename app/SSHCommands/PHPMyAdmin/{DeleteNginxPHPMyAdminVHost.php => DeleteNginxPHPMyAdminVHostCommand.php} (89%) rename app/SSHCommands/System/{RunScript.php => RunScriptCommand.php} (82%) create mode 100644 tests/Feature/SSHCommands/CronJob/UpdateCronJobsCommandTest.php create mode 100644 tests/Feature/SSHCommands/Database/BackupDatabaseCommandTest.php create mode 100644 tests/Feature/SSHCommands/Database/CreateCommandTest.php create mode 100644 tests/Feature/SSHCommands/Database/CreateUserCommandTest.php create mode 100644 tests/Feature/SSHCommands/Database/DeleteCommandTest.php create mode 100644 tests/Feature/SSHCommands/Database/DeleteUserCommandTest.php create mode 100644 tests/Feature/SSHCommands/Database/InstallMariadbCommandTest.php create mode 100644 tests/Feature/SSHCommands/Database/InstallMysqlCommandTest.php create mode 100644 tests/Feature/SSHCommands/Database/LinkCommandTest.php create mode 100644 tests/Feature/SSHCommands/Database/UnlinkCommandTest.php create mode 100644 tests/Feature/SSHCommands/Firewall/AddRuleCommandTest.php create mode 100644 tests/Feature/SSHCommands/Firewall/InstallUfwCommandTest.php create mode 100644 tests/Feature/SSHCommands/Firewall/RemoveRuleCommandTest.php create mode 100644 tests/Feature/SSHCommands/Installation/InstallNodejsCommandTest.php create mode 100644 tests/Feature/SSHCommands/Installation/InstallRedisCommandTest.php create mode 100644 tests/Feature/SSHCommands/Installation/InstallRequirementsCommandTest.php create mode 100644 tests/Feature/SSHCommands/Nginx/ChangeNginxPHPVersionCommandTest.php create mode 100644 tests/Feature/SSHCommands/Nginx/CreateNginxVHostCommandTest.php create mode 100644 tests/Feature/SSHCommands/Nginx/DeleteNginxSiteCommandTest.php create mode 100644 tests/Feature/SSHCommands/Nginx/InstallNginxCommandTest.php create mode 100644 tests/Feature/SSHCommands/Nginx/UpdateNginxRedirectsCommandTest.php create mode 100644 tests/Feature/SSHCommands/Nginx/UpdateNginxVHostCommandTest.php create mode 100644 tests/Feature/SSHCommands/PHP/ChangeDefaultPHPCommandTest.php create mode 100644 tests/Feature/SSHCommands/PHP/GetPHPIniCommandTest.php create mode 100644 tests/Feature/SSHCommands/PHP/InstallComposerCommandTest.php create mode 100644 tests/Feature/SSHCommands/PHP/InstallPHPCommandTest.php create mode 100644 tests/Feature/SSHCommands/PHP/InstallPHPExtensionCommandTest.php create mode 100644 tests/Feature/SSHCommands/PHP/UninstallPHPCommandTest.php create mode 100644 tests/Feature/SSHCommands/PHPMyAdmin/CreateNginxPHPMyAdminVHostCommandTest.php create mode 100644 tests/Feature/SSHCommands/PHPMyAdmin/DeleteNginxPHPMyAdminVHostCommandTest.php create mode 100644 tests/Feature/SSHCommands/PHPMyAdmin/DownloadPHPMyAdminCommandTest.php create mode 100644 tests/Feature/SSHCommands/SSL/CreateCustomSSLCommandTest.php create mode 100644 tests/Feature/SSHCommands/SSL/CreateLetsencryptSSLCommandTest.php create mode 100644 tests/Feature/SSHCommands/SSL/InstallCertbotCommandTest.php create mode 100644 tests/Feature/SSHCommands/SSL/RemoveSSLCommandTest.php create mode 100644 tests/Feature/SSHCommands/Service/RestartServiceCommandTest.php create mode 100644 tests/Feature/SSHCommands/Service/ServiceStatusCommandTest.php create mode 100644 tests/Feature/SSHCommands/Service/StartServiceCommandTest.php create mode 100644 tests/Feature/SSHCommands/Service/StopServiceCommandTest.php create mode 100644 tests/Feature/SSHCommands/Storage/DownloadFromDropboxCommandTest.php create mode 100644 tests/Feature/SSHCommands/Storage/UploadToDropboxCommandTest.php create mode 100644 tests/Feature/SSHCommands/Supervisor/CreateWorkerCommandTest.php create mode 100644 tests/Feature/SSHCommands/Supervisor/DeleteWorkerCommandTest.php create mode 100644 tests/Feature/SSHCommands/Supervisor/InstallSupervisorCommandTest.php create mode 100644 tests/Feature/SSHCommands/Supervisor/RestartWorkerCommandTest.php create mode 100644 tests/Feature/SSHCommands/Supervisor/StartWorkerCommandTest.php create mode 100644 tests/Feature/SSHCommands/Supervisor/StopWorkerCommandTest.php create mode 100644 tests/Feature/SSHCommands/System/CreateUserCommandTest.php create mode 100644 tests/Feature/SSHCommands/System/DeleteSshKeyCommandTest.php create mode 100644 tests/Feature/SSHCommands/System/DeploySshKeyCommandTest.php create mode 100644 tests/Feature/SSHCommands/System/EditFileCommandTest.php create mode 100644 tests/Feature/SSHCommands/System/GenerateSshKeyCommandTest.php create mode 100644 tests/Feature/SSHCommands/System/GetPublicKeyCommandTest.php create mode 100644 tests/Feature/SSHCommands/System/ReadFileCommandTest.php create mode 100644 tests/Feature/SSHCommands/System/ReadSshKeyCommandTest.php create mode 100644 tests/Feature/SSHCommands/System/RebootCommandTest.php create mode 100644 tests/Feature/SSHCommands/System/RunScriptCommandTest.php create mode 100644 tests/Feature/SSHCommands/System/UpgradeCommandTest.php create mode 100644 tests/Feature/SSHCommands/Website/CloneRepositoryCommandTest.php create mode 100644 tests/Feature/SSHCommands/Website/ComposerInstallCommandTest.php create mode 100644 tests/Feature/SSHCommands/Website/UpdateBranchCommandTest.php diff --git a/.github/workflows/style-check.yml b/.github/workflows/style-check.yml new file mode 100644 index 0000000..d610553 --- /dev/null +++ b/.github/workflows/style-check.yml @@ -0,0 +1,54 @@ +name: style-check + +on: + push: + pull_request: + +jobs: + tests: + runs-on: ubuntu-20.04 + + services: + mysql: + image: mysql + env: + MYSQL_DATABASE: test_db + MYSQL_USER: user + MYSQL_PASSWORD: password + MYSQL_ROOT_PASSWORD: rootpassword + ports: + - 3306:3306 + options: --health-cmd="mysqladmin ping" --health-interval=10s --health-timeout=5s --health-retries=3 + + strategy: + fail-fast: true + matrix: + php: [ 8.1 ] + + steps: + - uses: actions/checkout@v2 + + - name: Setup PHP + uses: shivammathur/setup-php@v2 + with: + php-version: ${{ matrix.php }} + + - name: Cache Composer packages + id: composer-cache + uses: actions/cache@v2 + with: + path: vendor + key: ${{ runner.os }}-php-${{ hashFiles('**/composer.lock') }} + restore-keys: | + ${{ runner.os }}-php- + - name: Install dependencies + if: steps.composer-cache.outputs.cache-hit != 'true' + run: composer install --prefer-dist --no-progress --no-suggest + + - name: Run test suite + run: php artisan test + env: + DB_HOST: 127.0.0.1 + DB_DATABASE: test_db + DB_USERNAME: user + DB_PASSWORD: password diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index 60d0d6a..50bf1ef 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -3,25 +3,11 @@ name: tests on: push: pull_request: - schedule: - - cron: '0 0 * * *' jobs: tests: runs-on: ubuntu-20.04 - services: - mysql: - image: mysql - env: - MYSQL_DATABASE: test_db - MYSQL_USER: user - MYSQL_PASSWORD: password - MYSQL_ROOT_PASSWORD: rootpassword - ports: - - 3306:3306 - options: --health-cmd="mysqladmin ping" --health-interval=10s --health-timeout=5s --health-retries=3 - strategy: fail-fast: true matrix: @@ -47,10 +33,5 @@ jobs: if: steps.composer-cache.outputs.cache-hit != 'true' run: composer install --prefer-dist --no-progress --no-suggest - - name: Run test suite - run: php artisan test - env: - DB_HOST: 127.0.0.1 - DB_DATABASE: test_db - DB_USERNAME: user - DB_PASSWORD: password + - name: Run pint + run: ./vendor/bin/pint --test diff --git a/app/Actions/Database/CreateBackup.php b/app/Actions/Database/CreateBackup.php index b8d6edc..3acbd01 100644 --- a/app/Actions/Database/CreateBackup.php +++ b/app/Actions/Database/CreateBackup.php @@ -59,7 +59,7 @@ private function validate($type, Server $server, array $input): void '0 0 * * *', '0 0 * * 0', '0 0 1 * *', - 'custom' + 'custom', ]), ], ]; diff --git a/app/Actions/FirewallRule/CreateRule.php b/app/Actions/FirewallRule/CreateRule.php index 26f7691..135f352 100755 --- a/app/Actions/FirewallRule/CreateRule.php +++ b/app/Actions/FirewallRule/CreateRule.php @@ -6,7 +6,6 @@ use App\Models\FirewallRule; use App\Models\Server; use Illuminate\Support\Facades\Validator; -use Illuminate\Validation\Rule; use Illuminate\Validation\ValidationException; class CreateRule diff --git a/app/Actions/SourceControl/ConnectSourceControl.php b/app/Actions/SourceControl/ConnectSourceControl.php index 875ba44..3fe72d7 100644 --- a/app/Actions/SourceControl/ConnectSourceControl.php +++ b/app/Actions/SourceControl/ConnectSourceControl.php @@ -15,7 +15,7 @@ public function connect(array $input): void $sourceControl = new SourceControl([ 'provider' => $input['provider'], 'profile' => $input['name'], - 'access_token' => $input['token'] + 'access_token' => $input['token'], ]); if (! $sourceControl->provider()->connect()) { @@ -24,7 +24,7 @@ public function connect(array $input): void ), ]); } - + $sourceControl->save(); } @@ -36,14 +36,14 @@ private function validate(array $input): void $rules = [ 'provider' => [ 'required', - Rule::in(\App\Enums\SourceControl::getValues()) + Rule::in(\App\Enums\SourceControl::getValues()), ], 'name' => [ 'required', ], 'token' => [ - 'required' - ] + 'required', + ], ]; Validator::make($input, $rules)->validate(); } diff --git a/app/Actions/StorageProvider/CreateStorageProvider.php b/app/Actions/StorageProvider/CreateStorageProvider.php index f70a767..ab3293c 100644 --- a/app/Actions/StorageProvider/CreateStorageProvider.php +++ b/app/Actions/StorageProvider/CreateStorageProvider.php @@ -22,15 +22,15 @@ public function create(User $user, array $input): void 'provider' => $input['provider'], 'profile' => $input['name'], 'credentials' => [ - 'token' => $input['token'] - ] + 'token' => $input['token'], + ], ]); if (! $storageProvider->provider()->connect()) { throw ValidationException::withMessages([ - 'token' => __("Couldn't connect to the provider") + 'token' => __("Couldn't connect to the provider"), ]); } - $storageProvider->save();; + $storageProvider->save(); } private function validate(User $user, array $input): void @@ -45,8 +45,8 @@ private function validate(User $user, array $input): void Rule::unique('storage_providers', 'profile')->where('user_id', $user->id), ], 'token' => [ - 'required' - ] + 'required', + ], ])->validate(); } } diff --git a/app/Console/Commands/CreateUserCommand.php b/app/Console/Commands/CreateUserCommand.php index 0d40fb5..db85401 100644 --- a/app/Console/Commands/CreateUserCommand.php +++ b/app/Console/Commands/CreateUserCommand.php @@ -4,7 +4,6 @@ use App\Models\User; use Illuminate\Console\Command; -use Illuminate\Support\Str; class CreateUserCommand extends Command { @@ -20,6 +19,6 @@ public function handle(): void 'password' => bcrypt($this->argument('password')), ]); - $this->info("User created with password"); + $this->info('User created with password'); } } diff --git a/app/Contracts/StorageProvider.php b/app/Contracts/StorageProvider.php index fef2d84..dea18ef 100644 --- a/app/Contracts/StorageProvider.php +++ b/app/Contracts/StorageProvider.php @@ -3,7 +3,6 @@ namespace App\Contracts; use App\Models\Server; -use Symfony\Component\HttpFoundation\RedirectResponse; interface StorageProvider { diff --git a/app/Enums/ServerType.php b/app/Enums/ServerType.php index 7713941..201bac4 100644 --- a/app/Enums/ServerType.php +++ b/app/Enums/ServerType.php @@ -7,5 +7,6 @@ final class ServerType extends Enum { const REGULAR = 'regular'; + const DATABASE = 'database'; } diff --git a/app/Helpers/SSH.php b/app/Helpers/SSH.php index 7cebb26..bca12ab 100755 --- a/app/Helpers/SSH.php +++ b/app/Helpers/SSH.php @@ -74,11 +74,11 @@ public function connect(bool $sftp = false): void $login = $this->connection->login($this->user, $this->privateKey); if (! $login) { - throw new SSHAuthenticationError("Error authenticating"); + throw new SSHAuthenticationError('Error authenticating'); } } catch (Throwable $e) { - Log::error("Error connecting", [ - "msg" => $e->getMessage() + Log::error('Error connecting', [ + 'msg' => $e->getMessage(), ]); throw $e; } diff --git a/app/Http/Kernel.php b/app/Http/Kernel.php index 52e5ffb..ec01584 100644 --- a/app/Http/Kernel.php +++ b/app/Http/Kernel.php @@ -64,6 +64,6 @@ class Kernel extends HttpKernel 'signed' => \App\Http\Middleware\ValidateSignature::class, 'throttle' => \Illuminate\Routing\Middleware\ThrottleRequests::class, 'verified' => \Illuminate\Auth\Middleware\EnsureEmailIsVerified::class, - 'server-is-ready' => ServerIsReadyMiddleware::class + 'server-is-ready' => ServerIsReadyMiddleware::class, ]; } diff --git a/app/Http/Livewire/Databases/DatabaseBackupFiles.php b/app/Http/Livewire/Databases/DatabaseBackupFiles.php index 1c0660a..9f9857a 100644 --- a/app/Http/Livewire/Databases/DatabaseBackupFiles.php +++ b/app/Http/Livewire/Databases/DatabaseBackupFiles.php @@ -20,9 +20,9 @@ class DatabaseBackupFiles extends Component public Backup $backup; - public string $restoreId = ""; + public string $restoreId = ''; - public string $restoreDatabaseId = ""; + public string $restoreDatabaseId = ''; public int $deleteId; @@ -61,7 +61,7 @@ public function delete(): void public function render(): View { return view('livewire.databases.database-backup-files', [ - 'files' => $this->backup->files()->orderByDesc('id')->simplePaginate(10) + 'files' => $this->backup->files()->orderByDesc('id')->simplePaginate(10), ]); } } diff --git a/app/Http/Livewire/Databases/DatabaseBackups.php b/app/Http/Livewire/Databases/DatabaseBackups.php index d3f85c8..90a37f8 100644 --- a/app/Http/Livewire/Databases/DatabaseBackups.php +++ b/app/Http/Livewire/Databases/DatabaseBackups.php @@ -75,7 +75,7 @@ public function render(): View return view('livewire.databases.database-backups', [ 'backups' => $this->server->backups, 'databases' => $this->server->databases, - 'files' => $this->files + 'files' => $this->files, ]); } } diff --git a/app/Jobs/Installation/ContinueInstallation.php b/app/Jobs/Installation/ContinueInstallation.php index 69d4faa..6cca01b 100644 --- a/app/Jobs/Installation/ContinueInstallation.php +++ b/app/Jobs/Installation/ContinueInstallation.php @@ -21,6 +21,7 @@ public function handle(): void { if ($this->server->provider()->isRunning()) { $this->server->install(); + return; } @@ -33,6 +34,7 @@ public function handle(): void 'server' => $this->server, ]) ); + return; } diff --git a/app/Jobs/Installation/UninstallPHPMyAdmin.php b/app/Jobs/Installation/UninstallPHPMyAdmin.php index 6d38b6e..91d1d98 100644 --- a/app/Jobs/Installation/UninstallPHPMyAdmin.php +++ b/app/Jobs/Installation/UninstallPHPMyAdmin.php @@ -5,7 +5,7 @@ use App\Jobs\Job; use App\Models\FirewallRule; use App\Models\Service; -use App\SSHCommands\PHPMyAdmin\DeleteNginxPHPMyAdminVHost; +use App\SSHCommands\PHPMyAdmin\DeleteNginxPHPMyAdminVHostCommand; use Exception; use Throwable; @@ -48,7 +48,7 @@ private function removeFirewallRule(): void private function deleteVHost(): void { $this->service->server->ssh()->exec( - new DeleteNginxPHPMyAdminVHost('/home/vito/phpmyadmin'), + new DeleteNginxPHPMyAdminVHostCommand('/home/vito/phpmyadmin'), 'delete-phpmyadmin-vhost' ); } diff --git a/app/Jobs/Site/Deploy.php b/app/Jobs/Site/Deploy.php index 7773dd2..f0c4c2b 100644 --- a/app/Jobs/Site/Deploy.php +++ b/app/Jobs/Site/Deploy.php @@ -7,7 +7,7 @@ use App\Helpers\SSH; use App\Jobs\Job; use App\Models\Deployment; -use App\SSHCommands\System\RunScript; +use App\SSHCommands\System\RunScriptCommand; use Throwable; class Deploy extends Job @@ -34,7 +34,7 @@ public function handle(): void { $this->ssh = $this->deployment->site->server->ssh(); $this->ssh->exec( - new RunScript($this->path, $this->script), + new RunScriptCommand($this->path, $this->script), 'deploy', $this->deployment->site_id ); diff --git a/app/Jobs/Site/DeployKey.php b/app/Jobs/Site/DeployKey.php index 9521fd1..d99ac7a 100755 --- a/app/Jobs/Site/DeployKey.php +++ b/app/Jobs/Site/DeployKey.php @@ -34,7 +34,7 @@ public function handle(): void ); $this->site->save(); $this->site->sourceControl()->provider()->deployKey( - $this->site->domain.'-key-' . $this->site->id, + $this->site->domain.'-key-'.$this->site->id, $this->site->repository, $this->site->ssh_key ); diff --git a/app/Listeners/BroadcastListener.php b/app/Listeners/BroadcastListener.php index fa66776..6fa9b16 100644 --- a/app/Listeners/BroadcastListener.php +++ b/app/Listeners/BroadcastListener.php @@ -15,7 +15,7 @@ public function handle(Broadcast $event): void { Cache::set('broadcast', [ 'type' => $event->type, - 'data' => $event->data + 'data' => $event->data, ], now()->addMinutes(5)); } } diff --git a/app/Models/Site.php b/app/Models/Site.php index 2018450..07ceb11 100755 --- a/app/Models/Site.php +++ b/app/Models/Site.php @@ -110,7 +110,7 @@ public static function boot(): void static::created(function (Site $site) { $site->deploymentScript()->create([ 'name' => 'default', - 'content' => '' + 'content' => '', ]); }); } diff --git a/app/Providers/EventServiceProvider.php b/app/Providers/EventServiceProvider.php index 1b03e38..4164c25 100644 --- a/app/Providers/EventServiceProvider.php +++ b/app/Providers/EventServiceProvider.php @@ -7,7 +7,6 @@ use Illuminate\Auth\Events\Registered; use Illuminate\Auth\Listeners\SendEmailVerificationNotification; use Illuminate\Foundation\Support\Providers\EventServiceProvider as ServiceProvider; -use Illuminate\Support\Facades\Event; class EventServiceProvider extends ServiceProvider { diff --git a/app/SSHCommands/Database/BackupDatabaseCommand.php b/app/SSHCommands/Database/BackupDatabaseCommand.php index 3fdf4cf..8164c65 100644 --- a/app/SSHCommands/Database/BackupDatabaseCommand.php +++ b/app/SSHCommands/Database/BackupDatabaseCommand.php @@ -13,7 +13,7 @@ public function __construct(protected string $provider, protected string $databa public function file(): string { - return File::get(resource_path(sprintf("commands/database/%s/backup.sh", $this->provider))); + return File::get(resource_path(sprintf('commands/database/%s/backup.sh', $this->provider))); } public function content(): string diff --git a/app/SSHCommands/Database/CreateCommand.php b/app/SSHCommands/Database/CreateCommand.php index 4ec61e2..054b297 100755 --- a/app/SSHCommands/Database/CreateCommand.php +++ b/app/SSHCommands/Database/CreateCommand.php @@ -13,7 +13,7 @@ public function __construct(protected string $provider, protected string $name) public function file(): string { - return File::get(resource_path(sprintf("commands/database/%s/create.sh", $this->provider))); + return File::get(resource_path(sprintf('commands/database/%s/create.sh', $this->provider))); } public function content(): string diff --git a/app/SSHCommands/Database/CreateUserCommand.php b/app/SSHCommands/Database/CreateUserCommand.php index 584a2f4..f3ff630 100755 --- a/app/SSHCommands/Database/CreateUserCommand.php +++ b/app/SSHCommands/Database/CreateUserCommand.php @@ -17,7 +17,7 @@ public function __construct( public function file(): string { - return File::get(resource_path(sprintf("commands/database/%s/create-user.sh", $this->provider))); + return File::get(resource_path(sprintf('commands/database/%s/create-user.sh', $this->provider))); } public function content(): string diff --git a/app/SSHCommands/Database/DeleteCommand.php b/app/SSHCommands/Database/DeleteCommand.php index fdd998f..91c6bba 100755 --- a/app/SSHCommands/Database/DeleteCommand.php +++ b/app/SSHCommands/Database/DeleteCommand.php @@ -13,7 +13,7 @@ public function __construct(protected string $provider, protected string $name) public function file(): string { - return File::get(resource_path(sprintf("commands/database/%s/delete.sh", $this->provider))); + return File::get(resource_path(sprintf('commands/database/%s/delete.sh', $this->provider))); } public function content(): string diff --git a/app/SSHCommands/Database/DeleteUserCommand.php b/app/SSHCommands/Database/DeleteUserCommand.php index 6947c22..89fd652 100755 --- a/app/SSHCommands/Database/DeleteUserCommand.php +++ b/app/SSHCommands/Database/DeleteUserCommand.php @@ -13,7 +13,7 @@ public function __construct(protected string $provider, protected string $userna public function file(): string { - return File::get(resource_path(sprintf("commands/database/%s/delete-user.sh", $this->provider))); + return File::get(resource_path(sprintf('commands/database/%s/delete-user.sh', $this->provider))); } public function content(): string diff --git a/app/SSHCommands/Database/LinkCommand.php b/app/SSHCommands/Database/LinkCommand.php index 0af52ad..249a828 100755 --- a/app/SSHCommands/Database/LinkCommand.php +++ b/app/SSHCommands/Database/LinkCommand.php @@ -17,7 +17,7 @@ public function __construct( public function file(): string { - return File::get(resource_path(sprintf("commands/database/%s/link.sh", $this->provider))); + return File::get(resource_path(sprintf('commands/database/%s/link.sh', $this->provider))); } public function content(): string diff --git a/app/SSHCommands/Database/RestoreDatabaseCommand.php b/app/SSHCommands/Database/RestoreDatabaseCommand.php index 989ba33..c19ad35 100644 --- a/app/SSHCommands/Database/RestoreDatabaseCommand.php +++ b/app/SSHCommands/Database/RestoreDatabaseCommand.php @@ -13,7 +13,7 @@ public function __construct(protected string $provider, protected string $databa public function file(): string { - return File::get(resource_path(sprintf("commands/database/%s/restore.sh", $this->provider))); + return File::get(resource_path(sprintf('commands/database/%s/restore.sh', $this->provider))); } public function content(): string diff --git a/app/SSHCommands/Database/UnlinkCommand.php b/app/SSHCommands/Database/UnlinkCommand.php index cc3a75d..91b1b8c 100755 --- a/app/SSHCommands/Database/UnlinkCommand.php +++ b/app/SSHCommands/Database/UnlinkCommand.php @@ -16,7 +16,7 @@ public function __construct( public function file(): string { - return File::get(resource_path(sprintf("commands/database/%s/unlink.sh", $this->provider))); + return File::get(resource_path(sprintf('commands/database/%s/unlink.sh', $this->provider))); } public function content(): string diff --git a/app/SSHCommands/Firewall/AddRuleCommand.php b/app/SSHCommands/Firewall/AddRuleCommand.php index 6f37abc..bf5e212 100755 --- a/app/SSHCommands/Firewall/AddRuleCommand.php +++ b/app/SSHCommands/Firewall/AddRuleCommand.php @@ -21,6 +21,6 @@ public function __construct( public function file(): string { - return File::get(resource_path(sprintf("commands/firewall/%s/add-rule.sh", $this->provider))); + return File::get(resource_path(sprintf('commands/firewall/%s/add-rule.sh', $this->provider))); } } diff --git a/app/SSHCommands/Firewall/RemoveRuleCommand.php b/app/SSHCommands/Firewall/RemoveRuleCommand.php index 763a449..2b9a4c5 100755 --- a/app/SSHCommands/Firewall/RemoveRuleCommand.php +++ b/app/SSHCommands/Firewall/RemoveRuleCommand.php @@ -21,6 +21,6 @@ public function __construct( public function file(): string { - return File::get(resource_path(sprintf("commands/firewall/%s/remove-rule.sh", $this->provider))); + return File::get(resource_path(sprintf('commands/firewall/%s/remove-rule.sh', $this->provider))); } } diff --git a/app/SSHCommands/Nginx/InstallNginxCommand.php b/app/SSHCommands/Nginx/InstallNginxCommand.php index c30e00f..331938a 100755 --- a/app/SSHCommands/Nginx/InstallNginxCommand.php +++ b/app/SSHCommands/Nginx/InstallNginxCommand.php @@ -4,7 +4,6 @@ use App\SSHCommands\Command; use Illuminate\Support\Facades\File; -use Illuminate\Support\Str; class InstallNginxCommand extends Command { diff --git a/app/SSHCommands/PHP/InstallPHPCommand.php b/app/SSHCommands/PHP/InstallPHPCommand.php index d0c9e31..d165d3d 100755 --- a/app/SSHCommands/PHP/InstallPHPCommand.php +++ b/app/SSHCommands/PHP/InstallPHPCommand.php @@ -4,7 +4,6 @@ use App\SSHCommands\Command; use Illuminate\Support\Facades\File; -use Illuminate\Support\Str; class InstallPHPCommand extends Command { diff --git a/app/SSHCommands/PHP/UninstallPHPCommand.php b/app/SSHCommands/PHP/UninstallPHPCommand.php index efd4911..1401d1b 100755 --- a/app/SSHCommands/PHP/UninstallPHPCommand.php +++ b/app/SSHCommands/PHP/UninstallPHPCommand.php @@ -4,7 +4,6 @@ use App\SSHCommands\Command; use Illuminate\Support\Facades\File; -use Illuminate\Support\Str; class UninstallPHPCommand extends Command { diff --git a/app/SSHCommands/PHPMyAdmin/DeleteNginxPHPMyAdminVHost.php b/app/SSHCommands/PHPMyAdmin/DeleteNginxPHPMyAdminVHostCommand.php similarity index 89% rename from app/SSHCommands/PHPMyAdmin/DeleteNginxPHPMyAdminVHost.php rename to app/SSHCommands/PHPMyAdmin/DeleteNginxPHPMyAdminVHostCommand.php index 3d6ad71..5a737f5 100755 --- a/app/SSHCommands/PHPMyAdmin/DeleteNginxPHPMyAdminVHost.php +++ b/app/SSHCommands/PHPMyAdmin/DeleteNginxPHPMyAdminVHostCommand.php @@ -5,7 +5,7 @@ use App\SSHCommands\Command; use Illuminate\Support\Facades\File; -class DeleteNginxPHPMyAdminVHost extends Command +class DeleteNginxPHPMyAdminVHostCommand extends Command { public function __construct(protected string $path) { diff --git a/app/SSHCommands/SSL/RemoveSSLCommand.php b/app/SSHCommands/SSL/RemoveSSLCommand.php index b76a307..bf0b382 100755 --- a/app/SSHCommands/SSL/RemoveSSLCommand.php +++ b/app/SSHCommands/SSL/RemoveSSLCommand.php @@ -17,6 +17,6 @@ public function file(): string public function content(): string { - return 'sudo rm -rf '.$this->path.'*'."\n"; + return 'sudo rm -rf '.$this->path.'*'; } } diff --git a/app/SSHCommands/System/RunScript.php b/app/SSHCommands/System/RunScriptCommand.php similarity index 82% rename from app/SSHCommands/System/RunScript.php rename to app/SSHCommands/System/RunScriptCommand.php index 3ec539e..97bc947 100644 --- a/app/SSHCommands/System/RunScript.php +++ b/app/SSHCommands/System/RunScriptCommand.php @@ -5,7 +5,7 @@ use App\SSHCommands\Command; use Illuminate\Support\Facades\File; -class RunScript extends Command +class RunScriptCommand extends Command { public function __construct(protected string $path, protected string $script) { @@ -20,7 +20,7 @@ public function content(): string { return str($this->file()) ->replace('__path__', $this->path) - ->replace('__script__', make_bash_script($this->script)) + ->replace('__script__', $this->script) ->toString(); } } diff --git a/app/ServerProviders/AWS.php b/app/ServerProviders/AWS.php index 05f139a..1206e7c 100755 --- a/app/ServerProviders/AWS.php +++ b/app/ServerProviders/AWS.php @@ -4,7 +4,6 @@ use App\Enums\OperatingSystem; use App\Exceptions\CouldNotConnectToProvider; -use App\Notifications\FailedToDeleteServerFromProvider; use Aws\Ec2\Ec2Client; use Aws\EC2InstanceConnect\EC2InstanceConnectClient; use Exception; diff --git a/app/ServerProviders/DigitalOcean.php b/app/ServerProviders/DigitalOcean.php index 089bf81..8555c37 100644 --- a/app/ServerProviders/DigitalOcean.php +++ b/app/ServerProviders/DigitalOcean.php @@ -4,7 +4,6 @@ use App\Exceptions\CouldNotConnectToProvider; use App\Exceptions\ServerProviderError; -use App\Notifications\FailedToDeleteServerFromProvider; use Exception; use Illuminate\Support\Facades\Http; use Illuminate\Support\Facades\Log; diff --git a/app/ServerProviders/Hetzner.php b/app/ServerProviders/Hetzner.php index 3df9e63..b0edb68 100644 --- a/app/ServerProviders/Hetzner.php +++ b/app/ServerProviders/Hetzner.php @@ -4,7 +4,6 @@ use App\Exceptions\CouldNotConnectToProvider; use App\Exceptions\ServerProviderError; -use App\Notifications\FailedToDeleteServerFromProvider; use Illuminate\Http\Client\Response; use Illuminate\Support\Facades\Http; diff --git a/app/ServerProviders/Linode.php b/app/ServerProviders/Linode.php index b56d450..6d7340c 100644 --- a/app/ServerProviders/Linode.php +++ b/app/ServerProviders/Linode.php @@ -4,7 +4,6 @@ use App\Exceptions\CouldNotConnectToProvider; use App\Exceptions\ServerProviderError; -use App\Notifications\FailedToDeleteServerFromProvider; use Illuminate\Support\Facades\Http; use Illuminate\Support\Facades\Log; @@ -104,7 +103,7 @@ public function create(): void if (count($errors) > 0) { $msg = $errors[0]['reason']; } - Log::error("Linode error", $errors); + Log::error('Linode error', $errors); throw new ServerProviderError($msg); } $this->server->ip = $create->json()['ipv4'][0]; diff --git a/app/ServerProviders/Vultr.php b/app/ServerProviders/Vultr.php index 2e89e1f..07481cc 100644 --- a/app/ServerProviders/Vultr.php +++ b/app/ServerProviders/Vultr.php @@ -4,7 +4,6 @@ use App\Exceptions\CouldNotConnectToProvider; use App\Exceptions\ServerProviderError; -use App\Notifications\FailedToDeleteServerFromProvider; use Exception; use Illuminate\Support\Facades\Http; use Illuminate\Support\Facades\Log; diff --git a/app/ServerTypes/Database.php b/app/ServerTypes/Database.php index 06325ba..86624f8 100755 --- a/app/ServerTypes/Database.php +++ b/app/ServerTypes/Database.php @@ -4,9 +4,6 @@ use App\Events\Broadcast; use App\Jobs\Installation\Initialize; -use App\Jobs\Installation\InstallCertbot; -use App\Jobs\Installation\InstallComposer; -use App\Jobs\Installation\InstallNodejs; use App\Jobs\Installation\InstallRequirements; use App\Jobs\Installation\Upgrade; use Illuminate\Support\Facades\Bus; diff --git a/app/SourceControlProviders/Bitbucket.php b/app/SourceControlProviders/Bitbucket.php index 209fc6d..9ed55ef 100755 --- a/app/SourceControlProviders/Bitbucket.php +++ b/app/SourceControlProviders/Bitbucket.php @@ -5,9 +5,6 @@ use App\Exceptions\FailedToDeployGitHook; use App\Exceptions\FailedToDeployGitKey; use App\Exceptions\FailedToDestroyGitHook; -use App\Exceptions\RepositoryNotFound; -use App\Exceptions\RepositoryPermissionDenied; -use App\Exceptions\SourceControlIsNotConnected; use Exception; use Illuminate\Support\Facades\Http; use Illuminate\Support\Str; @@ -39,7 +36,7 @@ public function getRepo(string $repo = null): mixed public function fullRepoUrl(string $repo, string $key): string { - return sprintf("git@bitbucket.org-%s:%s.git", $key, $repo); + return sprintf('git@bitbucket.org-%s:%s.git', $key, $repo); } /** diff --git a/app/SourceControlProviders/Github.php b/app/SourceControlProviders/Github.php index f4d0f85..466890b 100755 --- a/app/SourceControlProviders/Github.php +++ b/app/SourceControlProviders/Github.php @@ -2,8 +2,8 @@ namespace App\SourceControlProviders; -use App\Exceptions\FailedToDeployGitKey; use App\Exceptions\FailedToDeployGitHook; +use App\Exceptions\FailedToDeployGitKey; use App\Exceptions\FailedToDestroyGitHook; use Exception; use Illuminate\Support\Facades\Http; @@ -44,7 +44,7 @@ public function getRepo(string $repo = null): mixed public function fullRepoUrl(string $repo, string $key): string { - return sprintf("git@github.com-%s:%s.git", $key, $repo); + return sprintf('git@github.com-%s:%s.git', $key, $repo); } /** diff --git a/app/SourceControlProviders/Gitlab.php b/app/SourceControlProviders/Gitlab.php index a6aef52..0933f45 100755 --- a/app/SourceControlProviders/Gitlab.php +++ b/app/SourceControlProviders/Gitlab.php @@ -2,8 +2,8 @@ namespace App\SourceControlProviders; -use App\Exceptions\FailedToDeployGitKey; use App\Exceptions\FailedToDeployGitHook; +use App\Exceptions\FailedToDeployGitKey; use App\Exceptions\FailedToDestroyGitHook; use Exception; use Illuminate\Support\Facades\Http; @@ -36,7 +36,7 @@ public function getRepo(string $repo = null): mixed public function fullRepoUrl(string $repo, string $key): string { - return sprintf("git@gitlab.com-%s:%s.git", $key, $repo); + return sprintf('git@gitlab.com-%s:%s.git', $key, $repo); } /** diff --git a/app/StorageProviders/Dropbox.php b/app/StorageProviders/Dropbox.php index a2687a7..875d360 100644 --- a/app/StorageProviders/Dropbox.php +++ b/app/StorageProviders/Dropbox.php @@ -17,7 +17,7 @@ public function connect(): bool { $res = Http::withToken($this->storageProvider->credentials['token']) ->post($this->apiUrl.'/check/user', [ - 'query' => '' + 'query' => '', ]); return $res->successful(); @@ -40,7 +40,7 @@ public function upload(Server $server, string $src, string $dest): array $data = json_decode($upload, true); if (isset($data['error'])) { - throw new BackupFileException("Failed to upload to Dropbox ".$data['error_summary'] ?? ''); + throw new BackupFileException('Failed to upload to Dropbox '.$data['error_summary'] ?? ''); } return [ diff --git a/config/app.php b/config/app.php index 646ffe5..96311ad 100644 --- a/config/app.php +++ b/config/app.php @@ -193,7 +193,7 @@ App\Providers\AuthServiceProvider::class, App\Providers\BroadcastServiceProvider::class, App\Providers\EventServiceProvider::class, - App\Providers\RouteServiceProvider::class + App\Providers\RouteServiceProvider::class, ], /* diff --git a/config/core.php b/config/core.php index ac53e1c..e954d49 100755 --- a/config/core.php +++ b/config/core.php @@ -25,7 +25,6 @@ use App\ServiceHandlers\Webserver\Nginx; use App\SiteTypes\Laravel; use App\SiteTypes\PHPSite; -use App\SiteTypes\Wordpress; use App\SourceControlProviders\Bitbucket; use App\SourceControlProviders\Custom; use App\SourceControlProviders\Github; @@ -48,7 +47,7 @@ 'operating_systems' => [ // 'ubuntu_18', 'ubuntu_20', - 'ubuntu_22' + 'ubuntu_22', ], 'webservers' => ['none', 'nginx'], 'php_versions' => [ diff --git a/database/factories/BackupFactory.php b/database/factories/BackupFactory.php index d1e678f..e0d7e21 100644 --- a/database/factories/BackupFactory.php +++ b/database/factories/BackupFactory.php @@ -13,7 +13,7 @@ public function definition(): array 'type' => 'database', 'interval' => '0 * * * *', 'keep_backups' => 10, - 'status' => BackupStatus::RUNNING + 'status' => BackupStatus::RUNNING, ]; } } diff --git a/database/factories/ServerLogFactory.php b/database/factories/ServerLogFactory.php index 7ada3d1..ddfc118 100644 --- a/database/factories/ServerLogFactory.php +++ b/database/factories/ServerLogFactory.php @@ -2,7 +2,6 @@ namespace Database\Factories; -use App\Enums\LogType; use App\Models\ServerLog; use Illuminate\Database\Eloquent\Factories\Factory; diff --git a/database/factories/ServiceFactory.php b/database/factories/ServiceFactory.php index b7d41f0..ec2058e 100644 --- a/database/factories/ServiceFactory.php +++ b/database/factories/ServiceFactory.php @@ -2,10 +2,8 @@ namespace Database\Factories; -use App\Models\Server; use App\Models\Service; use Illuminate\Database\Eloquent\Factories\Factory; -use Illuminate\Support\Carbon; class ServiceFactory extends Factory { diff --git a/database/factories/SiteFactory.php b/database/factories/SiteFactory.php index 9cfa87d..d3a79ff 100644 --- a/database/factories/SiteFactory.php +++ b/database/factories/SiteFactory.php @@ -20,7 +20,7 @@ public function definition(): array 'status' => 'ready', 'progress' => '100', 'php_version' => '8.2', - 'branch' => 'main' + 'branch' => 'main', ]; } } diff --git a/database/factories/SshKeyFactory.php b/database/factories/SshKeyFactory.php index 153a22c..ac0770c 100644 --- a/database/factories/SshKeyFactory.php +++ b/database/factories/SshKeyFactory.php @@ -4,7 +4,6 @@ use App\Models\SshKey; use Illuminate\Database\Eloquent\Factories\Factory; -use Illuminate\Support\Carbon; class SshKeyFactory extends Factory { diff --git a/database/migrations/2023_07_21_210213_update_firewall_rules_table.php b/database/migrations/2023_07_21_210213_update_firewall_rules_table.php index c53c51b..5ac104a 100644 --- a/database/migrations/2023_07_21_210213_update_firewall_rules_table.php +++ b/database/migrations/2023_07_21_210213_update_firewall_rules_table.php @@ -3,7 +3,8 @@ use Illuminate\Database\Migrations\Migration; use Illuminate\Support\Facades\DB; -return new class extends Migration { +return new class extends Migration +{ public function up(): void { DB::statement('ALTER TABLE firewall_rules MODIFY mask varchar(10) null'); diff --git a/database/migrations/2023_07_23_143530_add_ssh_key_field_to_sites_table.php b/database/migrations/2023_07_23_143530_add_ssh_key_field_to_sites_table.php index 33e143f..6c0ff2b 100644 --- a/database/migrations/2023_07_23_143530_add_ssh_key_field_to_sites_table.php +++ b/database/migrations/2023_07_23_143530_add_ssh_key_field_to_sites_table.php @@ -4,7 +4,8 @@ use Illuminate\Database\Schema\Blueprint; use Illuminate\Support\Facades\Schema; -return new class extends Migration { +return new class extends Migration +{ public function up(): void { Schema::table('sites', function (Blueprint $table) { diff --git a/database/migrations/2023_07_30_163805_add_url_to_source_controls_table.php b/database/migrations/2023_07_30_163805_add_url_to_source_controls_table.php index 8d98e8b..50e262f 100644 --- a/database/migrations/2023_07_30_163805_add_url_to_source_controls_table.php +++ b/database/migrations/2023_07_30_163805_add_url_to_source_controls_table.php @@ -4,7 +4,8 @@ use Illuminate\Database\Schema\Blueprint; use Illuminate\Support\Facades\Schema; -return new class extends Migration { +return new class extends Migration +{ public function up(): void { Schema::table('source_controls', function (Blueprint $table) { diff --git a/database/migrations/2023_07_30_200348_add_profile_to_source_controls_table.php b/database/migrations/2023_07_30_200348_add_profile_to_source_controls_table.php index 68cf22e..fb7c873 100644 --- a/database/migrations/2023_07_30_200348_add_profile_to_source_controls_table.php +++ b/database/migrations/2023_07_30_200348_add_profile_to_source_controls_table.php @@ -4,7 +4,8 @@ use Illuminate\Database\Schema\Blueprint; use Illuminate\Support\Facades\Schema; -return new class extends Migration { +return new class extends Migration +{ public function up(): void { Schema::table('source_controls', function (Blueprint $table) { diff --git a/database/migrations/2023_07_30_205328_add_source_control_id_to_sites_table.php b/database/migrations/2023_07_30_205328_add_source_control_id_to_sites_table.php index 083abda..cfdcd23 100644 --- a/database/migrations/2023_07_30_205328_add_source_control_id_to_sites_table.php +++ b/database/migrations/2023_07_30_205328_add_source_control_id_to_sites_table.php @@ -4,7 +4,8 @@ use Illuminate\Database\Schema\Blueprint; use Illuminate\Support\Facades\Schema; -return new class extends Migration { +return new class extends Migration +{ public function up(): void { Schema::table('sites', function (Blueprint $table) { diff --git a/database/migrations/2023_08_13_095440_update_storage_providers_table.php b/database/migrations/2023_08_13_095440_update_storage_providers_table.php index be0b2fe..93deebb 100644 --- a/database/migrations/2023_08_13_095440_update_storage_providers_table.php +++ b/database/migrations/2023_08_13_095440_update_storage_providers_table.php @@ -4,7 +4,8 @@ use Illuminate\Database\Schema\Blueprint; use Illuminate\Support\Facades\Schema; -return new class extends Migration { +return new class extends Migration +{ public function up(): void { Schema::table('storage_providers', function (Blueprint $table) { diff --git a/database/migrations/2023_08_17_231824_update_backups_table.php b/database/migrations/2023_08_17_231824_update_backups_table.php index b9bda13..4103c1d 100644 --- a/database/migrations/2023_08_17_231824_update_backups_table.php +++ b/database/migrations/2023_08_17_231824_update_backups_table.php @@ -4,7 +4,8 @@ use Illuminate\Database\Schema\Blueprint; use Illuminate\Support\Facades\Schema; -return new class extends Migration { +return new class extends Migration +{ public function up(): void { Schema::table('backups', function (Blueprint $table) { diff --git a/database/migrations/2023_08_25_183201_update_backup_files_table.php b/database/migrations/2023_08_25_183201_update_backup_files_table.php index 26f9ee6..a3b3a03 100644 --- a/database/migrations/2023_08_25_183201_update_backup_files_table.php +++ b/database/migrations/2023_08_25_183201_update_backup_files_table.php @@ -4,7 +4,8 @@ use Illuminate\Database\Schema\Blueprint; use Illuminate\Support\Facades\Schema; -return new class extends Migration { +return new class extends Migration +{ public function up(): void { Schema::table('backup_files', function (Blueprint $table) { diff --git a/database/seeders/DatabaseSeeder.php b/database/seeders/DatabaseSeeder.php index dcfd6da..09f8d5d 100644 --- a/database/seeders/DatabaseSeeder.php +++ b/database/seeders/DatabaseSeeder.php @@ -21,13 +21,13 @@ public function run(): void 'email' => 'user@example.com', ]); $server = Server::factory()->create([ - 'user_id' => $user->id + 'user_id' => $user->id, ]); $server->services()->create([ 'type' => 'database', 'name' => config('core.databases_name.mysql80'), 'version' => config('core.databases_version.mysql80'), - 'status' => ServiceStatus::READY + 'status' => ServiceStatus::READY, ]); $server->services()->create([ 'type' => 'php', @@ -36,17 +36,17 @@ public function run(): void ], 'name' => 'php', 'version' => '8.1', - 'status' => ServiceStatus::READY + 'status' => ServiceStatus::READY, ]); $server->services()->create([ 'type' => 'webserver', 'name' => 'nginx', 'version' => 'latest', - 'status' => ServiceStatus::READY + 'status' => ServiceStatus::READY, ]); Site::factory()->create([ 'server_id' => $server->id, - 'type' => SiteType::LARAVEL + 'type' => SiteType::LARAVEL, ]); } } diff --git a/resources/commands/php/change-default-php.sh b/resources/commands/php/change-default-php.sh index e769d1f..c3b131f 100755 --- a/resources/commands/php/change-default-php.sh +++ b/resources/commands/php/change-default-php.sh @@ -6,6 +6,6 @@ if ! sudo ln -s /usr/bin/php__version__ /usr/bin/php; then echo 'VITO_SSH_ERROR' && exit 1 fi -echo "Default php is: \n" +echo "Default php is: " php -v diff --git a/resources/commands/system/run-script.sh b/resources/commands/system/run-script.sh index 7ecdab1..837f548 100644 --- a/resources/commands/system/run-script.sh +++ b/resources/commands/system/run-script.sh @@ -2,4 +2,6 @@ if ! cd __path__; then echo 'VITO_SSH_ERROR' && exit 1 fi -__script__ +if ! __script__; then + echo 'VITO_SSH_ERROR' && exit 1 +fi diff --git a/tests/Feature/Http/ApplicationTest.php b/tests/Feature/Http/ApplicationTest.php index 197ac3d..67ff6b1 100644 --- a/tests/Feature/Http/ApplicationTest.php +++ b/tests/Feature/Http/ApplicationTest.php @@ -23,7 +23,7 @@ public function test_visit_application() $this->get( route('servers.sites.show', [ 'server' => $this->server, - 'site' => $this->site + 'site' => $this->site, ]) ) ->assertOk() @@ -44,7 +44,7 @@ public function test_update_deployment_script() $this->assertDatabaseHas('deployment_scripts', [ 'site_id' => $this->site->id, - 'content' => 'some script' + 'content' => 'some script', ]); $this->site->refresh(); diff --git a/tests/Feature/Http/CronjobTest.php b/tests/Feature/Http/CronjobTest.php index 38c5824..302f735 100644 --- a/tests/Feature/Http/CronjobTest.php +++ b/tests/Feature/Http/CronjobTest.php @@ -58,7 +58,7 @@ public function test_create_cronjob() 'command' => 'ls -la', 'user' => 'vito', 'frequency' => '* * * * *', - 'status' => CronjobStatus::CREATING + 'status' => CronjobStatus::CREATING, ]); } } diff --git a/tests/Feature/Http/DatabaseBackupTest.php b/tests/Feature/Http/DatabaseBackupTest.php index fa21475..b0c955a 100644 --- a/tests/Feature/Http/DatabaseBackupTest.php +++ b/tests/Feature/Http/DatabaseBackupTest.php @@ -32,7 +32,7 @@ public function test_create_backup(): void $storage = StorageProvider::factory()->create([ 'user_id' => $this->user->id, - 'provider' => \App\Enums\StorageProvider::DROPBOX + 'provider' => \App\Enums\StorageProvider::DROPBOX, ]); Livewire::test(DatabaseBackups::class, ['server' => $this->server]) @@ -60,7 +60,7 @@ public function test_see_backups_list(): void $storage = StorageProvider::factory()->create([ 'user_id' => $this->user->id, - 'provider' => \App\Enums\StorageProvider::DROPBOX + 'provider' => \App\Enums\StorageProvider::DROPBOX, ]); $backup = Backup::factory()->create([ @@ -85,7 +85,7 @@ public function test_delete_database(): void $storage = StorageProvider::factory()->create([ 'user_id' => $this->user->id, - 'provider' => \App\Enums\StorageProvider::DROPBOX + 'provider' => \App\Enums\StorageProvider::DROPBOX, ]); $backup = Backup::factory()->create([ diff --git a/tests/Feature/Http/FirewallTest.php b/tests/Feature/Http/FirewallTest.php index bd1eb36..576b155 100644 --- a/tests/Feature/Http/FirewallTest.php +++ b/tests/Feature/Http/FirewallTest.php @@ -35,7 +35,7 @@ public function test_create_firewall_rule(): void Bus::assertDispatched(AddToServer::class); $this->assertDatabaseHas('firewall_rules', [ - 'port' => '1234' + 'port' => '1234', ]); } @@ -44,7 +44,7 @@ public function test_see_firewall_rules(): void $this->actingAs($this->user); $rule = FirewallRule::factory()->create([ - 'server_id' => $this->server->id + 'server_id' => $this->server->id, ]); Livewire::test(FirewallRulesList::class, ['server' => $this->server]) @@ -61,7 +61,7 @@ public function test_delete_firewall_rule(): void $this->actingAs($this->user); $rule = FirewallRule::factory()->create([ - 'server_id' => $this->server->id + 'server_id' => $this->server->id, ]); Livewire::test(FirewallRulesList::class, ['server' => $this->server]) @@ -73,7 +73,7 @@ public function test_delete_firewall_rule(): void $this->assertDatabaseHas('firewall_rules', [ 'id' => $rule->id, - 'status' => FirewallRuleStatus::DELETING + 'status' => FirewallRuleStatus::DELETING, ]); } } diff --git a/tests/Feature/Http/PHP.php b/tests/Feature/Http/PHP.php index baa18a6..7a4eb3f 100644 --- a/tests/Feature/Http/PHP.php +++ b/tests/Feature/Http/PHP.php @@ -59,7 +59,7 @@ public function test_change_default_php_cli(): void ], 'name' => 'php', 'version' => '8.1', - 'status' => ServiceStatus::READY + 'status' => ServiceStatus::READY, ]); Livewire::test(DefaultCli::class, ['server' => $this->server]) diff --git a/tests/Feature/Http/QueuesTest.php b/tests/Feature/Http/QueuesTest.php index a2b41d4..4d0c35e 100644 --- a/tests/Feature/Http/QueuesTest.php +++ b/tests/Feature/Http/QueuesTest.php @@ -63,7 +63,7 @@ public function test_create_queue() 'auto_start' => 1, 'auto_restart' => 1, 'numprocs' => 1, - 'status' => QueueStatus::CREATING + 'status' => QueueStatus::CREATING, ]); } } diff --git a/tests/Feature/Http/ServerKeysTest.php b/tests/Feature/Http/ServerKeysTest.php index bdef927..e5a85ea 100644 --- a/tests/Feature/Http/ServerKeysTest.php +++ b/tests/Feature/Http/ServerKeysTest.php @@ -56,7 +56,7 @@ public function test_delete_ssh_key() $this->assertDatabaseHas('server_ssh_keys', [ 'server_id' => $this->server->id, 'ssh_key_id' => $sshKey->id, - 'status' => SshKeyStatus::DELETING + 'status' => SshKeyStatus::DELETING, ]); Bus::assertDispatched(DeleteSshKeyFromServer::class); @@ -77,7 +77,7 @@ public function test_add_new_ssh_key() $this->assertDatabaseHas('server_ssh_keys', [ 'server_id' => $this->server->id, - 'status' => SshKeyStatus::ADDING + 'status' => SshKeyStatus::ADDING, ]); Bus::assertDispatched(DeploySshKeyToServer::class); @@ -103,7 +103,7 @@ public function test_add_existing_key() $this->assertDatabaseHas('server_ssh_keys', [ 'server_id' => $this->server->id, - 'status' => SshKeyStatus::ADDING + 'status' => SshKeyStatus::ADDING, ]); Bus::assertDispatched(DeploySshKeyToServer::class); diff --git a/tests/Feature/Http/ServicesTest.php b/tests/Feature/Http/ServicesTest.php index d1249ae..853e0d4 100644 --- a/tests/Feature/Http/ServicesTest.php +++ b/tests/Feature/Http/ServicesTest.php @@ -25,7 +25,7 @@ public function test_see_services_list(): void 'supervisor', 'redis', 'ufw', - 'php' + 'php', ]); } diff --git a/tests/Feature/Http/SourceControlsTest.php b/tests/Feature/Http/SourceControlsTest.php index 572daab..ba34c12 100644 --- a/tests/Feature/Http/SourceControlsTest.php +++ b/tests/Feature/Http/SourceControlsTest.php @@ -2,10 +2,7 @@ namespace Tests\Feature\Http; -use App\Http\Livewire\SourceControls\Bitbucket; use App\Http\Livewire\SourceControls\Connect; -use App\Http\Livewire\SourceControls\Github; -use App\Http\Livewire\SourceControls\Gitlab; use App\Http\Livewire\SourceControls\SourceControlsList; use App\Models\SourceControl; use Illuminate\Foundation\Testing\RefreshDatabase; @@ -48,7 +45,7 @@ public function test_delete_provider(string $provider): void /** @var SourceControl $sourceControl */ $sourceControl = SourceControl::factory()->create([ 'provider' => $provider, - 'profile' => 'test' + 'profile' => 'test', ]); Livewire::test(SourceControlsList::class) diff --git a/tests/Feature/Http/StorageProvidersTest.php b/tests/Feature/Http/StorageProvidersTest.php index 36399cf..5873c25 100644 --- a/tests/Feature/Http/StorageProvidersTest.php +++ b/tests/Feature/Http/StorageProvidersTest.php @@ -3,8 +3,8 @@ namespace Tests\Feature\Http; use App\Enums\StorageProvider; -use App\Http\Livewire\StorageProviders\ProvidersList; use App\Http\Livewire\StorageProviders\ConnectProvider; +use App\Http\Livewire\StorageProviders\ProvidersList; use Illuminate\Foundation\Testing\RefreshDatabase; use Illuminate\Support\Facades\Http; use Livewire\Livewire; @@ -39,7 +39,7 @@ public function test_see_providers_list(): void $provider = \App\Models\StorageProvider::factory()->create([ 'user_id' => $this->user->id, - 'provider' => StorageProvider::DROPBOX + 'provider' => StorageProvider::DROPBOX, ]); Livewire::test(ProvidersList::class) diff --git a/tests/Feature/SSHCommands/CronJob/UpdateCronJobsCommandTest.php b/tests/Feature/SSHCommands/CronJob/UpdateCronJobsCommandTest.php new file mode 100644 index 0000000..6db0b4b --- /dev/null +++ b/tests/Feature/SSHCommands/CronJob/UpdateCronJobsCommandTest.php @@ -0,0 +1,18 @@ +assertStringContainsString("echo 'ls -la' | sudo -u vito crontab -;", $command->content()); + + $this->assertStringContainsString('sudo -u vito crontab -l;', $command->content()); + } +} diff --git a/tests/Feature/SSHCommands/Database/BackupDatabaseCommandTest.php b/tests/Feature/SSHCommands/Database/BackupDatabaseCommandTest.php new file mode 100644 index 0000000..f5e0d3e --- /dev/null +++ b/tests/Feature/SSHCommands/Database/BackupDatabaseCommandTest.php @@ -0,0 +1,20 @@ +assertStringContainsString('sudo DEBIAN_FRONTEND=noninteractive mysqldump -u root test > test.sql;', $command->content()); + + $this->assertStringContainsString('DEBIAN_FRONTEND=noninteractive zip test.zip test.sql;', $command->content()); + + $this->assertStringContainsString('rm test.sql;', $command->content()); + } +} diff --git a/tests/Feature/SSHCommands/Database/CreateCommandTest.php b/tests/Feature/SSHCommands/Database/CreateCommandTest.php new file mode 100644 index 0000000..fbc4621 --- /dev/null +++ b/tests/Feature/SSHCommands/Database/CreateCommandTest.php @@ -0,0 +1,18 @@ +assertStringContainsString('sudo mysql -e "CREATE DATABASE IF NOT EXISTS test CHARACTER SET utf8 COLLATE utf8_general_ci";', $command->content()); + + $this->assertStringContainsString('echo "Command executed"', $command->content()); + } +} diff --git a/tests/Feature/SSHCommands/Database/CreateUserCommandTest.php b/tests/Feature/SSHCommands/Database/CreateUserCommandTest.php new file mode 100644 index 0000000..ca51665 --- /dev/null +++ b/tests/Feature/SSHCommands/Database/CreateUserCommandTest.php @@ -0,0 +1,18 @@ +assertStringContainsString('sudo mysql -e "CREATE USER IF NOT EXISTS \'user\'@\'%\' IDENTIFIED BY \'password\'";', $command->content()); + + $this->assertStringContainsString('sudo mysql -e "FLUSH PRIVILEGES";', $command->content()); + } +} diff --git a/tests/Feature/SSHCommands/Database/DeleteCommandTest.php b/tests/Feature/SSHCommands/Database/DeleteCommandTest.php new file mode 100644 index 0000000..10bad82 --- /dev/null +++ b/tests/Feature/SSHCommands/Database/DeleteCommandTest.php @@ -0,0 +1,16 @@ +assertStringContainsString('sudo mysql -e "DROP DATABASE IF EXISTS test";', $command->content()); + } +} diff --git a/tests/Feature/SSHCommands/Database/DeleteUserCommandTest.php b/tests/Feature/SSHCommands/Database/DeleteUserCommandTest.php new file mode 100644 index 0000000..f575725 --- /dev/null +++ b/tests/Feature/SSHCommands/Database/DeleteUserCommandTest.php @@ -0,0 +1,18 @@ +assertStringContainsString('sudo mysql -e "DROP USER IF EXISTS \'user\'@\'%\'";', $command->content()); + + $this->assertStringContainsString('sudo mysql -e "FLUSH PRIVILEGES";', $command->content()); + } +} diff --git a/tests/Feature/SSHCommands/Database/InstallMariadbCommandTest.php b/tests/Feature/SSHCommands/Database/InstallMariadbCommandTest.php new file mode 100644 index 0000000..552d5da --- /dev/null +++ b/tests/Feature/SSHCommands/Database/InstallMariadbCommandTest.php @@ -0,0 +1,31 @@ +assertStringContainsString($expected, $command->content()); + } +} diff --git a/tests/Feature/SSHCommands/Database/InstallMysqlCommandTest.php b/tests/Feature/SSHCommands/Database/InstallMysqlCommandTest.php new file mode 100644 index 0000000..2731e85 --- /dev/null +++ b/tests/Feature/SSHCommands/Database/InstallMysqlCommandTest.php @@ -0,0 +1,61 @@ +assertStringContainsString($expected, $command->content()); + } + + public function test_generate_command_mysql5() + { + $command = new InstallMysqlCommand('5.7'); + + $expected = <<<'EOD' + sudo DEBIAN_FRONTEND=noninteractive apt install mysql-server -y + + sudo service mysql enable + + sudo service mysql start + + if ! sudo mysql -e "ALTER USER 'root'@'localhost' IDENTIFIED WITH auth_socket;"; then + echo 'VITO_SSH_ERROR' && exit 1 + fi + + if ! sudo mysql -e "FLUSH PRIVILEGES"; then + echo 'VITO_SSH_ERROR' && exit 1 + fi + EOD; + + $this->assertStringContainsString($expected, $command->content()); + } +} diff --git a/tests/Feature/SSHCommands/Database/LinkCommandTest.php b/tests/Feature/SSHCommands/Database/LinkCommandTest.php new file mode 100644 index 0000000..1c0d015 --- /dev/null +++ b/tests/Feature/SSHCommands/Database/LinkCommandTest.php @@ -0,0 +1,28 @@ +assertStringContainsString($expected, $command->content()); + } +} diff --git a/tests/Feature/SSHCommands/Database/UnlinkCommandTest.php b/tests/Feature/SSHCommands/Database/UnlinkCommandTest.php new file mode 100644 index 0000000..ab5c9ea --- /dev/null +++ b/tests/Feature/SSHCommands/Database/UnlinkCommandTest.php @@ -0,0 +1,24 @@ +assertStringContainsString($expected, $command->content()); + } +} diff --git a/tests/Feature/SSHCommands/Firewall/AddRuleCommandTest.php b/tests/Feature/SSHCommands/Firewall/AddRuleCommandTest.php new file mode 100644 index 0000000..04848e1 --- /dev/null +++ b/tests/Feature/SSHCommands/Firewall/AddRuleCommandTest.php @@ -0,0 +1,30 @@ +assertStringContainsString($expected, $command->content()); + } +} diff --git a/tests/Feature/SSHCommands/Firewall/InstallUfwCommandTest.php b/tests/Feature/SSHCommands/Firewall/InstallUfwCommandTest.php new file mode 100644 index 0000000..b9a513b --- /dev/null +++ b/tests/Feature/SSHCommands/Firewall/InstallUfwCommandTest.php @@ -0,0 +1,46 @@ +assertStringContainsString($expected, $command->content()); + } +} diff --git a/tests/Feature/SSHCommands/Firewall/RemoveRuleCommandTest.php b/tests/Feature/SSHCommands/Firewall/RemoveRuleCommandTest.php new file mode 100644 index 0000000..1e0947b --- /dev/null +++ b/tests/Feature/SSHCommands/Firewall/RemoveRuleCommandTest.php @@ -0,0 +1,31 @@ +assertStringContainsString($expected, $command->content()); + } +} diff --git a/tests/Feature/SSHCommands/Installation/InstallNodejsCommandTest.php b/tests/Feature/SSHCommands/Installation/InstallNodejsCommandTest.php new file mode 100644 index 0000000..a0b466a --- /dev/null +++ b/tests/Feature/SSHCommands/Installation/InstallNodejsCommandTest.php @@ -0,0 +1,24 @@ +assertStringContainsString($expected, $command->content()); + } +} diff --git a/tests/Feature/SSHCommands/Installation/InstallRedisCommandTest.php b/tests/Feature/SSHCommands/Installation/InstallRedisCommandTest.php new file mode 100644 index 0000000..9075c10 --- /dev/null +++ b/tests/Feature/SSHCommands/Installation/InstallRedisCommandTest.php @@ -0,0 +1,26 @@ +assertStringContainsString($expected, $command->content()); + } +} diff --git a/tests/Feature/SSHCommands/Installation/InstallRequirementsCommandTest.php b/tests/Feature/SSHCommands/Installation/InstallRequirementsCommandTest.php new file mode 100644 index 0000000..6511cfe --- /dev/null +++ b/tests/Feature/SSHCommands/Installation/InstallRequirementsCommandTest.php @@ -0,0 +1,22 @@ +assertStringContainsString($expected, $command->content()); + } +} diff --git a/tests/Feature/SSHCommands/Nginx/ChangeNginxPHPVersionCommandTest.php b/tests/Feature/SSHCommands/Nginx/ChangeNginxPHPVersionCommandTest.php new file mode 100644 index 0000000..f852e2f --- /dev/null +++ b/tests/Feature/SSHCommands/Nginx/ChangeNginxPHPVersionCommandTest.php @@ -0,0 +1,28 @@ +assertStringContainsString($expected, $command->content()); + } +} diff --git a/tests/Feature/SSHCommands/Nginx/CreateNginxVHostCommandTest.php b/tests/Feature/SSHCommands/Nginx/CreateNginxVHostCommandTest.php new file mode 100644 index 0000000..4a88197 --- /dev/null +++ b/tests/Feature/SSHCommands/Nginx/CreateNginxVHostCommandTest.php @@ -0,0 +1,46 @@ +assertStringContainsString($expected, $command->content()); + } +} diff --git a/tests/Feature/SSHCommands/Nginx/DeleteNginxSiteCommandTest.php b/tests/Feature/SSHCommands/Nginx/DeleteNginxSiteCommandTest.php new file mode 100644 index 0000000..811e744 --- /dev/null +++ b/tests/Feature/SSHCommands/Nginx/DeleteNginxSiteCommandTest.php @@ -0,0 +1,26 @@ +assertStringContainsString($expected, $command->content()); + } +} diff --git a/tests/Feature/SSHCommands/Nginx/InstallNginxCommandTest.php b/tests/Feature/SSHCommands/Nginx/InstallNginxCommandTest.php new file mode 100644 index 0000000..52365d5 --- /dev/null +++ b/tests/Feature/SSHCommands/Nginx/InstallNginxCommandTest.php @@ -0,0 +1,115 @@ +assertStringContainsString($expected, $command->content()); + } +} diff --git a/tests/Feature/SSHCommands/Nginx/UpdateNginxRedirectsCommandTest.php b/tests/Feature/SSHCommands/Nginx/UpdateNginxRedirectsCommandTest.php new file mode 100644 index 0000000..0a455f7 --- /dev/null +++ b/tests/Feature/SSHCommands/Nginx/UpdateNginxRedirectsCommandTest.php @@ -0,0 +1,26 @@ +assertStringContainsString($expected, $command->content()); + } +} diff --git a/tests/Feature/SSHCommands/Nginx/UpdateNginxVHostCommandTest.php b/tests/Feature/SSHCommands/Nginx/UpdateNginxVHostCommandTest.php new file mode 100644 index 0000000..965d458 --- /dev/null +++ b/tests/Feature/SSHCommands/Nginx/UpdateNginxVHostCommandTest.php @@ -0,0 +1,26 @@ +assertStringContainsString($expected, $command->content()); + } +} diff --git a/tests/Feature/SSHCommands/PHP/ChangeDefaultPHPCommandTest.php b/tests/Feature/SSHCommands/PHP/ChangeDefaultPHPCommandTest.php new file mode 100644 index 0000000..f67c9d9 --- /dev/null +++ b/tests/Feature/SSHCommands/PHP/ChangeDefaultPHPCommandTest.php @@ -0,0 +1,30 @@ +assertStringContainsString($expected, $command->content()); + } +} diff --git a/tests/Feature/SSHCommands/PHP/GetPHPIniCommandTest.php b/tests/Feature/SSHCommands/PHP/GetPHPIniCommandTest.php new file mode 100644 index 0000000..4ccde5a --- /dev/null +++ b/tests/Feature/SSHCommands/PHP/GetPHPIniCommandTest.php @@ -0,0 +1,20 @@ +assertStringContainsString($expected, $command->content()); + } +} diff --git a/tests/Feature/SSHCommands/PHP/InstallComposerCommandTest.php b/tests/Feature/SSHCommands/PHP/InstallComposerCommandTest.php new file mode 100644 index 0000000..e9a1a94 --- /dev/null +++ b/tests/Feature/SSHCommands/PHP/InstallComposerCommandTest.php @@ -0,0 +1,26 @@ +assertStringContainsString($expected, $command->content()); + } +} diff --git a/tests/Feature/SSHCommands/PHP/InstallPHPCommandTest.php b/tests/Feature/SSHCommands/PHP/InstallPHPCommandTest.php new file mode 100644 index 0000000..dda857a --- /dev/null +++ b/tests/Feature/SSHCommands/PHP/InstallPHPCommandTest.php @@ -0,0 +1,32 @@ +assertStringContainsString($expected, $command->content()); + } +} diff --git a/tests/Feature/SSHCommands/PHP/InstallPHPExtensionCommandTest.php b/tests/Feature/SSHCommands/PHP/InstallPHPExtensionCommandTest.php new file mode 100644 index 0000000..c69c805 --- /dev/null +++ b/tests/Feature/SSHCommands/PHP/InstallPHPExtensionCommandTest.php @@ -0,0 +1,24 @@ +assertStringContainsString($expected, $command->content()); + } +} diff --git a/tests/Feature/SSHCommands/PHP/UninstallPHPCommandTest.php b/tests/Feature/SSHCommands/PHP/UninstallPHPCommandTest.php new file mode 100644 index 0000000..d1b8ca6 --- /dev/null +++ b/tests/Feature/SSHCommands/PHP/UninstallPHPCommandTest.php @@ -0,0 +1,24 @@ +assertStringContainsString($expected, $command->content()); + } +} diff --git a/tests/Feature/SSHCommands/PHPMyAdmin/CreateNginxPHPMyAdminVHostCommandTest.php b/tests/Feature/SSHCommands/PHPMyAdmin/CreateNginxPHPMyAdminVHostCommandTest.php new file mode 100644 index 0000000..70c46f0 --- /dev/null +++ b/tests/Feature/SSHCommands/PHPMyAdmin/CreateNginxPHPMyAdminVHostCommandTest.php @@ -0,0 +1,36 @@ +assertStringContainsString($expected, $command->content()); + } +} diff --git a/tests/Feature/SSHCommands/PHPMyAdmin/DeleteNginxPHPMyAdminVHostCommandTest.php b/tests/Feature/SSHCommands/PHPMyAdmin/DeleteNginxPHPMyAdminVHostCommandTest.php new file mode 100644 index 0000000..9d1b533 --- /dev/null +++ b/tests/Feature/SSHCommands/PHPMyAdmin/DeleteNginxPHPMyAdminVHostCommandTest.php @@ -0,0 +1,30 @@ +assertStringContainsString($expected, $command->content()); + } +} diff --git a/tests/Feature/SSHCommands/PHPMyAdmin/DownloadPHPMyAdminCommandTest.php b/tests/Feature/SSHCommands/PHPMyAdmin/DownloadPHPMyAdminCommandTest.php new file mode 100644 index 0000000..4c83134 --- /dev/null +++ b/tests/Feature/SSHCommands/PHPMyAdmin/DownloadPHPMyAdminCommandTest.php @@ -0,0 +1,40 @@ +assertStringContainsString($expected, $command->content()); + } +} diff --git a/tests/Feature/SSHCommands/SSL/CreateCustomSSLCommandTest.php b/tests/Feature/SSHCommands/SSL/CreateCustomSSLCommandTest.php new file mode 100644 index 0000000..a254d2e --- /dev/null +++ b/tests/Feature/SSHCommands/SSL/CreateCustomSSLCommandTest.php @@ -0,0 +1,32 @@ +assertStringContainsString($expected, $command->content()); + } +} diff --git a/tests/Feature/SSHCommands/SSL/CreateLetsencryptSSLCommandTest.php b/tests/Feature/SSHCommands/SSL/CreateLetsencryptSSLCommandTest.php new file mode 100644 index 0000000..99c5d49 --- /dev/null +++ b/tests/Feature/SSHCommands/SSL/CreateLetsencryptSSLCommandTest.php @@ -0,0 +1,22 @@ +assertStringContainsString($expected, $command->content()); + } +} diff --git a/tests/Feature/SSHCommands/SSL/InstallCertbotCommandTest.php b/tests/Feature/SSHCommands/SSL/InstallCertbotCommandTest.php new file mode 100644 index 0000000..d79a189 --- /dev/null +++ b/tests/Feature/SSHCommands/SSL/InstallCertbotCommandTest.php @@ -0,0 +1,20 @@ +assertStringContainsString($expected, $command->content()); + } +} diff --git a/tests/Feature/SSHCommands/SSL/RemoveSSLCommandTest.php b/tests/Feature/SSHCommands/SSL/RemoveSSLCommandTest.php new file mode 100644 index 0000000..a23a84e --- /dev/null +++ b/tests/Feature/SSHCommands/SSL/RemoveSSLCommandTest.php @@ -0,0 +1,20 @@ +assertStringContainsString($expected, $command->content()); + } +} diff --git a/tests/Feature/SSHCommands/Service/RestartServiceCommandTest.php b/tests/Feature/SSHCommands/Service/RestartServiceCommandTest.php new file mode 100644 index 0000000..e9fdc90 --- /dev/null +++ b/tests/Feature/SSHCommands/Service/RestartServiceCommandTest.php @@ -0,0 +1,22 @@ +assertStringContainsString($expected, $command->content()); + } +} diff --git a/tests/Feature/SSHCommands/Service/ServiceStatusCommandTest.php b/tests/Feature/SSHCommands/Service/ServiceStatusCommandTest.php new file mode 100644 index 0000000..878ff0d --- /dev/null +++ b/tests/Feature/SSHCommands/Service/ServiceStatusCommandTest.php @@ -0,0 +1,20 @@ +assertStringContainsString($expected, $command->content()); + } +} diff --git a/tests/Feature/SSHCommands/Service/StartServiceCommandTest.php b/tests/Feature/SSHCommands/Service/StartServiceCommandTest.php new file mode 100644 index 0000000..aa0888c --- /dev/null +++ b/tests/Feature/SSHCommands/Service/StartServiceCommandTest.php @@ -0,0 +1,22 @@ +assertStringContainsString($expected, $command->content()); + } +} diff --git a/tests/Feature/SSHCommands/Service/StopServiceCommandTest.php b/tests/Feature/SSHCommands/Service/StopServiceCommandTest.php new file mode 100644 index 0000000..1e199fd --- /dev/null +++ b/tests/Feature/SSHCommands/Service/StopServiceCommandTest.php @@ -0,0 +1,22 @@ +assertStringContainsString($expected, $command->content()); + } +} diff --git a/tests/Feature/SSHCommands/Storage/DownloadFromDropboxCommandTest.php b/tests/Feature/SSHCommands/Storage/DownloadFromDropboxCommandTest.php new file mode 100644 index 0000000..9c29a8b --- /dev/null +++ b/tests/Feature/SSHCommands/Storage/DownloadFromDropboxCommandTest.php @@ -0,0 +1,23 @@ +assertStringContainsString($expected, $command->content()); + } +} diff --git a/tests/Feature/SSHCommands/Storage/UploadToDropboxCommandTest.php b/tests/Feature/SSHCommands/Storage/UploadToDropboxCommandTest.php new file mode 100644 index 0000000..585f2ee --- /dev/null +++ b/tests/Feature/SSHCommands/Storage/UploadToDropboxCommandTest.php @@ -0,0 +1,25 @@ +assertStringContainsString($expected, $command->content()); + } +} diff --git a/tests/Feature/SSHCommands/Supervisor/CreateWorkerCommandTest.php b/tests/Feature/SSHCommands/Supervisor/CreateWorkerCommandTest.php new file mode 100644 index 0000000..4d42cd9 --- /dev/null +++ b/tests/Feature/SSHCommands/Supervisor/CreateWorkerCommandTest.php @@ -0,0 +1,40 @@ +assertStringContainsString($expected, $command->content()); + } +} diff --git a/tests/Feature/SSHCommands/Supervisor/DeleteWorkerCommandTest.php b/tests/Feature/SSHCommands/Supervisor/DeleteWorkerCommandTest.php new file mode 100644 index 0000000..448c780 --- /dev/null +++ b/tests/Feature/SSHCommands/Supervisor/DeleteWorkerCommandTest.php @@ -0,0 +1,38 @@ +assertStringContainsString($expected, $command->content()); + } +} diff --git a/tests/Feature/SSHCommands/Supervisor/InstallSupervisorCommandTest.php b/tests/Feature/SSHCommands/Supervisor/InstallSupervisorCommandTest.php new file mode 100644 index 0000000..39d347a --- /dev/null +++ b/tests/Feature/SSHCommands/Supervisor/InstallSupervisorCommandTest.php @@ -0,0 +1,24 @@ +assertStringContainsString($expected, $command->content()); + } +} diff --git a/tests/Feature/SSHCommands/Supervisor/RestartWorkerCommandTest.php b/tests/Feature/SSHCommands/Supervisor/RestartWorkerCommandTest.php new file mode 100644 index 0000000..1463471 --- /dev/null +++ b/tests/Feature/SSHCommands/Supervisor/RestartWorkerCommandTest.php @@ -0,0 +1,22 @@ +assertStringContainsString($expected, $command->content()); + } +} diff --git a/tests/Feature/SSHCommands/Supervisor/StartWorkerCommandTest.php b/tests/Feature/SSHCommands/Supervisor/StartWorkerCommandTest.php new file mode 100644 index 0000000..194af8d --- /dev/null +++ b/tests/Feature/SSHCommands/Supervisor/StartWorkerCommandTest.php @@ -0,0 +1,22 @@ +assertStringContainsString($expected, $command->content()); + } +} diff --git a/tests/Feature/SSHCommands/Supervisor/StopWorkerCommandTest.php b/tests/Feature/SSHCommands/Supervisor/StopWorkerCommandTest.php new file mode 100644 index 0000000..93d90d6 --- /dev/null +++ b/tests/Feature/SSHCommands/Supervisor/StopWorkerCommandTest.php @@ -0,0 +1,22 @@ +assertStringContainsString($expected, $command->content()); + } +} diff --git a/tests/Feature/SSHCommands/System/CreateUserCommandTest.php b/tests/Feature/SSHCommands/System/CreateUserCommandTest.php new file mode 100644 index 0000000..b8f2a21 --- /dev/null +++ b/tests/Feature/SSHCommands/System/CreateUserCommandTest.php @@ -0,0 +1,30 @@ +assertStringContainsString($expected, $command->content()); + } +} diff --git a/tests/Feature/SSHCommands/System/DeleteSshKeyCommandTest.php b/tests/Feature/SSHCommands/System/DeleteSshKeyCommandTest.php new file mode 100644 index 0000000..149c7b0 --- /dev/null +++ b/tests/Feature/SSHCommands/System/DeleteSshKeyCommandTest.php @@ -0,0 +1,20 @@ +assertStringContainsString($expected, $command->content()); + } +} diff --git a/tests/Feature/SSHCommands/System/DeploySshKeyCommandTest.php b/tests/Feature/SSHCommands/System/DeploySshKeyCommandTest.php new file mode 100644 index 0000000..65a623f --- /dev/null +++ b/tests/Feature/SSHCommands/System/DeploySshKeyCommandTest.php @@ -0,0 +1,22 @@ +assertStringContainsString($expected, $command->content()); + } +} diff --git a/tests/Feature/SSHCommands/System/EditFileCommandTest.php b/tests/Feature/SSHCommands/System/EditFileCommandTest.php new file mode 100644 index 0000000..93e112b --- /dev/null +++ b/tests/Feature/SSHCommands/System/EditFileCommandTest.php @@ -0,0 +1,22 @@ +assertStringContainsString($expected, $command->content()); + } +} diff --git a/tests/Feature/SSHCommands/System/GenerateSshKeyCommandTest.php b/tests/Feature/SSHCommands/System/GenerateSshKeyCommandTest.php new file mode 100644 index 0000000..78cee4a --- /dev/null +++ b/tests/Feature/SSHCommands/System/GenerateSshKeyCommandTest.php @@ -0,0 +1,20 @@ +assertStringContainsString($expected, $command->content()); + } +} diff --git a/tests/Feature/SSHCommands/System/GetPublicKeyCommandTest.php b/tests/Feature/SSHCommands/System/GetPublicKeyCommandTest.php new file mode 100644 index 0000000..ffc1576 --- /dev/null +++ b/tests/Feature/SSHCommands/System/GetPublicKeyCommandTest.php @@ -0,0 +1,20 @@ +assertStringContainsString($expected, $command->content()); + } +} diff --git a/tests/Feature/SSHCommands/System/ReadFileCommandTest.php b/tests/Feature/SSHCommands/System/ReadFileCommandTest.php new file mode 100644 index 0000000..323edb1 --- /dev/null +++ b/tests/Feature/SSHCommands/System/ReadFileCommandTest.php @@ -0,0 +1,20 @@ +assertStringContainsString($expected, $command->content()); + } +} diff --git a/tests/Feature/SSHCommands/System/ReadSshKeyCommandTest.php b/tests/Feature/SSHCommands/System/ReadSshKeyCommandTest.php new file mode 100644 index 0000000..aea3dd9 --- /dev/null +++ b/tests/Feature/SSHCommands/System/ReadSshKeyCommandTest.php @@ -0,0 +1,20 @@ +assertStringContainsString($expected, $command->content()); + } +} diff --git a/tests/Feature/SSHCommands/System/RebootCommandTest.php b/tests/Feature/SSHCommands/System/RebootCommandTest.php new file mode 100644 index 0000000..182a1c1 --- /dev/null +++ b/tests/Feature/SSHCommands/System/RebootCommandTest.php @@ -0,0 +1,22 @@ +assertStringContainsString($expected, $command->content()); + } +} diff --git a/tests/Feature/SSHCommands/System/RunScriptCommandTest.php b/tests/Feature/SSHCommands/System/RunScriptCommandTest.php new file mode 100644 index 0000000..41c165f --- /dev/null +++ b/tests/Feature/SSHCommands/System/RunScriptCommandTest.php @@ -0,0 +1,26 @@ +assertStringContainsString($expected, $command->content()); + } +} diff --git a/tests/Feature/SSHCommands/System/UpgradeCommandTest.php b/tests/Feature/SSHCommands/System/UpgradeCommandTest.php new file mode 100644 index 0000000..4e00942 --- /dev/null +++ b/tests/Feature/SSHCommands/System/UpgradeCommandTest.php @@ -0,0 +1,26 @@ +assertStringContainsString($expected, $command->content()); + } +} diff --git a/tests/Feature/SSHCommands/Website/CloneRepositoryCommandTest.php b/tests/Feature/SSHCommands/Website/CloneRepositoryCommandTest.php new file mode 100644 index 0000000..0dc33f8 --- /dev/null +++ b/tests/Feature/SSHCommands/Website/CloneRepositoryCommandTest.php @@ -0,0 +1,46 @@ +> ~/.ssh/config + + ssh-keyscan -H github.com >> ~/.ssh/known_hosts + + rm -rf path + + if ! git config --global core.fileMode false; then + echo 'VITO_SSH_ERROR' && exit 1 + fi + + if ! git clone -b main git@github.com-key:vitodeploy/vito.git path; then + echo 'VITO_SSH_ERROR' && exit 1 + fi + + if ! find path -type d -exec chmod 755 {} \;; then + echo 'VITO_SSH_ERROR' && exit 1 + fi + + if ! find path -type f -exec chmod 644 {} \;; then + echo 'VITO_SSH_ERROR' && exit 1 + fi + + if ! cd path && git config core.fileMode false; then + echo 'VITO_SSH_ERROR' && exit 1 + fi + EOD; + + $this->assertStringContainsString($expected, $command->content()); + } +} diff --git a/tests/Feature/SSHCommands/Website/ComposerInstallCommandTest.php b/tests/Feature/SSHCommands/Website/ComposerInstallCommandTest.php new file mode 100644 index 0000000..35d1d2f --- /dev/null +++ b/tests/Feature/SSHCommands/Website/ComposerInstallCommandTest.php @@ -0,0 +1,26 @@ +assertStringContainsString($expected, $command->content()); + } +} diff --git a/tests/Feature/SSHCommands/Website/UpdateBranchCommandTest.php b/tests/Feature/SSHCommands/Website/UpdateBranchCommandTest.php new file mode 100644 index 0000000..5e3af39 --- /dev/null +++ b/tests/Feature/SSHCommands/Website/UpdateBranchCommandTest.php @@ -0,0 +1,26 @@ +assertStringContainsString($expected, $command->content()); + } +} From 88f26ce6a3159fcacd3a8d438dabd5c4643788d9 Mon Sep 17 00:00:00 2001 From: Saeed Vaziry Date: Sat, 2 Sep 2023 17:30:31 +0200 Subject: [PATCH 2/3] update workflows --- .../workflows/{style-check.yml => checks.yml} | 32 +++++++++++++++- .github/workflows/tests.yml | 37 ------------------- 2 files changed, 31 insertions(+), 38 deletions(-) rename .github/workflows/{style-check.yml => checks.yml} (61%) delete mode 100644 .github/workflows/tests.yml diff --git a/.github/workflows/style-check.yml b/.github/workflows/checks.yml similarity index 61% rename from .github/workflows/style-check.yml rename to .github/workflows/checks.yml index d610553..a35d37d 100644 --- a/.github/workflows/style-check.yml +++ b/.github/workflows/checks.yml @@ -1,4 +1,4 @@ -name: style-check +name: checks on: push: @@ -52,3 +52,33 @@ jobs: DB_DATABASE: test_db DB_USERNAME: user DB_PASSWORD: password + code-style: + runs-on: ubuntu-20.04 + + strategy: + fail-fast: true + matrix: + php: [ 8.1 ] + + steps: + - uses: actions/checkout@v2 + + - name: Setup PHP + uses: shivammathur/setup-php@v2 + with: + php-version: ${{ matrix.php }} + + - name: Cache Composer packages + id: composer-cache + uses: actions/cache@v2 + with: + path: vendor + key: ${{ runner.os }}-php-${{ hashFiles('**/composer.lock') }} + restore-keys: | + ${{ runner.os }}-php- + - name: Install dependencies + if: steps.composer-cache.outputs.cache-hit != 'true' + run: composer install --prefer-dist --no-progress --no-suggest + + - name: Run pint + run: ./vendor/bin/pint --test diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml deleted file mode 100644 index 50bf1ef..0000000 --- a/.github/workflows/tests.yml +++ /dev/null @@ -1,37 +0,0 @@ -name: tests - -on: - push: - pull_request: - -jobs: - tests: - runs-on: ubuntu-20.04 - - strategy: - fail-fast: true - matrix: - php: [ 8.1 ] - - steps: - - uses: actions/checkout@v2 - - - name: Setup PHP - uses: shivammathur/setup-php@v2 - with: - php-version: ${{ matrix.php }} - - - name: Cache Composer packages - id: composer-cache - uses: actions/cache@v2 - with: - path: vendor - key: ${{ runner.os }}-php-${{ hashFiles('**/composer.lock') }} - restore-keys: | - ${{ runner.os }}-php- - - name: Install dependencies - if: steps.composer-cache.outputs.cache-hit != 'true' - run: composer install --prefer-dist --no-progress --no-suggest - - - name: Run pint - run: ./vendor/bin/pint --test From 9dcd37bf65fcfb37ecc60cdc6355892ebb89f46b Mon Sep 17 00:00:00 2001 From: Saeed Vaziry Date: Sat, 2 Sep 2023 17:33:59 +0200 Subject: [PATCH 3/3] update checks.yml --- .github/workflows/checks.yml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.github/workflows/checks.yml b/.github/workflows/checks.yml index a35d37d..fe49d3d 100644 --- a/.github/workflows/checks.yml +++ b/.github/workflows/checks.yml @@ -3,6 +3,8 @@ name: checks on: push: pull_request: + schedule: + - cron: '0 0 * * *' jobs: tests: @@ -52,6 +54,7 @@ jobs: DB_DATABASE: test_db DB_USERNAME: user DB_PASSWORD: password + code-style: runs-on: ubuntu-20.04