diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml new file mode 100644 index 0000000..60d0d6a --- /dev/null +++ b/.github/workflows/tests.yml @@ -0,0 +1,56 @@ +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: + 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/app/Http/Livewire/SourceControls/Bitbucket.php b/app/Http/Livewire/SourceControls/Bitbucket.php deleted file mode 100644 index c5155b9..0000000 --- a/app/Http/Livewire/SourceControls/Bitbucket.php +++ /dev/null @@ -1,44 +0,0 @@ -url = request()->input('redirect') ?? null; - - $this->token = SourceControl::query() - ->where('provider', \App\Enums\SourceControl::BITBUCKET) - ->first()?->access_token ?? ''; - } - - public function connect(): void - { - app(ConnectSourceControl::class)->connect(\App\Enums\SourceControl::BITBUCKET, $this->all()); - - session()->flash('status', 'bitbucket-updated'); - - if ($this->url) { - $this->redirect($this->url); - } - } - - public function render(): View - { - return view('livewire.source-controls.bitbucket', [ - 'sourceControl' => SourceControl::query() - ->where('provider', \App\Enums\SourceControl::BITBUCKET) - ->first(), - ]); - } -} diff --git a/app/Http/Livewire/SourceControls/Github.php b/app/Http/Livewire/SourceControls/Github.php deleted file mode 100644 index 1e8b0ab..0000000 --- a/app/Http/Livewire/SourceControls/Github.php +++ /dev/null @@ -1,44 +0,0 @@ -url = request()->input('redirect') ?? null; - - $this->token = SourceControl::query() - ->where('provider', \App\Enums\SourceControl::GITHUB) - ->first()?->access_token ?? ''; - } - - public function connect(): void - { - app(ConnectSourceControl::class)->connect(\App\Enums\SourceControl::GITHUB, array_merge($this->all())); - - session()->flash('status', 'github-updated'); - - if ($this->url) { - $this->redirect($this->url); - } - } - - public function render(): View - { - return view('livewire.source-controls.github', [ - 'sourceControl' => SourceControl::query() - ->where('provider', \App\Enums\SourceControl::GITHUB) - ->first(), - ]); - } -} diff --git a/app/Http/Livewire/SourceControls/Gitlab.php b/app/Http/Livewire/SourceControls/Gitlab.php deleted file mode 100644 index da05db7..0000000 --- a/app/Http/Livewire/SourceControls/Gitlab.php +++ /dev/null @@ -1,44 +0,0 @@ -url = request()->input('redirect') ?? null; - - $this->token = SourceControl::query() - ->where('provider', \App\Enums\SourceControl::GITLAB) - ->first()?->access_token ?? ''; - } - - public function connect(): void - { - app(ConnectSourceControl::class)->connect(\App\Enums\SourceControl::GITLAB, $this->all()); - - session()->flash('status', 'gitlab-updated'); - - if ($this->url) { - $this->redirect($this->url); - } - } - - public function render(): View - { - return view('livewire.source-controls.gitlab', [ - 'sourceControl' => SourceControl::query() - ->where('provider', \App\Enums\SourceControl::GITLAB) - ->first(), - ]); - } -} diff --git a/resources/views/livewire/source-controls/bitbucket.blade.php b/resources/views/livewire/source-controls/bitbucket.blade.php deleted file mode 100644 index 375cf01..0000000 --- a/resources/views/livewire/source-controls/bitbucket.blade.php +++ /dev/null @@ -1,48 +0,0 @@ -
- -
- @include('livewire.source-controls.partials.bitbucket-icon') -
-
- {{ __("Bitbucket") }} -
-
-
- @if($sourceControl) - {{ __("Modify") }} - @else - {{ __("Connect") }} - @endif -
-
-
- -
-

- {{ __('Connect to Bitbucket') }} -

- -
- - - @error('token') - - @enderror -
- -
- @if (session('status') === 'bitbucket-updated') -

{{ __('Updated') }}

- @endif - - - {{ __('Cancel') }} - - - - {{ __('Connect') }} - -
-
-
-
diff --git a/resources/views/livewire/source-controls/github.blade.php b/resources/views/livewire/source-controls/github.blade.php deleted file mode 100644 index 7f52ab0..0000000 --- a/resources/views/livewire/source-controls/github.blade.php +++ /dev/null @@ -1,48 +0,0 @@ -
- -
- @include('livewire.source-controls.partials.github-icon') -
-
- {{ __("Github") }} -
-
-
- @if($sourceControl) - {{ __("Modify") }} - @else - {{ __("Connect") }} - @endif -
-
-
- -
-

- {{ __('Connect to Github') }} -

- -
- - - @error('token') - - @enderror -
- -
- @if (session('status') === 'github-updated') -

{{ __('Updated') }}

- @endif - - - {{ __('Cancel') }} - - - - {{ __('Connect') }} - -
-
-
-
diff --git a/resources/views/livewire/source-controls/gitlab.blade.php b/resources/views/livewire/source-controls/gitlab.blade.php deleted file mode 100644 index 63cf4ce..0000000 --- a/resources/views/livewire/source-controls/gitlab.blade.php +++ /dev/null @@ -1,48 +0,0 @@ -
- -
- @include('livewire.source-controls.partials.gitlab-icon') -
-
- {{ __("Gitlab") }} -
-
-
- @if($sourceControl) - {{ __("Modify") }} - @else - {{ __("Connect") }} - @endif -
-
-
- -
-

- {{ __('Connect to Gitlab') }} -

- -
- - - @error('token') - - @enderror -
- -
- @if (session('status') === 'gitlab-updated') -

{{ __('Updated') }}

- @endif - - - {{ __('Cancel') }} - - - - {{ __('Connect') }} - -
-
-
-
diff --git a/tests/Feature/Http/ApplicationTest.php b/tests/Feature/Http/ApplicationTest.php index 7ca36a3..197ac3d 100644 --- a/tests/Feature/Http/ApplicationTest.php +++ b/tests/Feature/Http/ApplicationTest.php @@ -21,7 +21,7 @@ public function test_visit_application() $this->actingAs($this->user); $this->get( - route('servers.sites.application', [ + route('servers.sites.show', [ 'server' => $this->server, 'site' => $this->site ]) diff --git a/tests/Feature/Http/SitesTest.php b/tests/Feature/Http/SitesTest.php index 9a93ab0..aa8d782 100644 --- a/tests/Feature/Http/SitesTest.php +++ b/tests/Feature/Http/SitesTest.php @@ -29,7 +29,8 @@ public function test_create_site(): void $this->actingAs($this->user); - \App\Models\SourceControl::factory()->create([ + /** @var \App\Models\SourceControl $sourceControl */ + $sourceControl = \App\Models\SourceControl::factory()->create([ 'provider' => SourceControl::GITHUB, ]); @@ -39,7 +40,7 @@ public function test_create_site(): void ->set('alias', 'www.example.com') ->set('php_version', '8.2') ->set('web_directory', 'public') - ->set('source_control', SourceControl::GITHUB) + ->set('source_control', $sourceControl->id) ->set('repository', 'test/test') ->set('branch', 'main') ->set('composer', true) diff --git a/tests/Feature/Http/SourceControlsTest.php b/tests/Feature/Http/SourceControlsTest.php index 593056c..572daab 100644 --- a/tests/Feature/Http/SourceControlsTest.php +++ b/tests/Feature/Http/SourceControlsTest.php @@ -3,8 +3,10 @@ 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; use Illuminate\Support\Facades\Http; @@ -18,14 +20,16 @@ class SourceControlsTest extends TestCase /** * @dataProvider data */ - public function test_connect_provider(string $provider, string $component): void + public function test_connect_provider(string $provider): void { $this->actingAs($this->user); Http::fake(); - Livewire::test($component) + Livewire::test(Connect::class) ->set('token', 'token') + ->set('name', 'profile') + ->set('provider', $provider) ->call('connect') ->assertSuccessful(); @@ -37,17 +41,19 @@ public function test_connect_provider(string $provider, string $component): void /** * @dataProvider data */ - public function test_delete_provider(string $provider, string $component): void + public function test_delete_provider(string $provider): void { $this->actingAs($this->user); - SourceControl::factory()->create([ + /** @var SourceControl $sourceControl */ + $sourceControl = SourceControl::factory()->create([ 'provider' => $provider, + 'profile' => 'test' ]); - Livewire::test($component) - ->set('token', '') - ->call('connect') + Livewire::test(SourceControlsList::class) + ->set('deleteId', $sourceControl->id) + ->call('delete') ->assertSuccessful(); $this->assertDatabaseMissing('source_controls', [ @@ -58,9 +64,9 @@ public function test_delete_provider(string $provider, string $component): void public static function data(): array { return [ - ['github', Github::class], - ['gitlab', Gitlab::class], - ['bitbucket', Bitbucket::class], + ['github'], + ['gitlab'], + ['bitbucket'], ]; } }