Skip to content

Commit

Permalink
[Add] Orchestral Testbench Dusk for real browser based tests,
Browse files Browse the repository at this point in the history
[Change] Refactor FeatureTestCase into seperate Concern to initialize the app environment,
[Add] Browser testsuite using Laravel Dusk throught Orchestral Workbench,
[Add] Basic TestCase super for Browser and Unit tests
  • Loading branch information
bumbummen99 committed Nov 24, 2024
1 parent bcb9f4a commit 812752e
Show file tree
Hide file tree
Showing 9 changed files with 97 additions and 47 deletions.
5 changes: 3 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@
},
"require-dev": {
"orchestra/testbench": "^9.5",
"filament/filament": "^3.2.120"
"filament/filament": "^3.2.120",
"orchestra/testbench-dusk": "^9.8"
},
"extra": {
"laravel": {
Expand Down Expand Up @@ -59,4 +60,4 @@
"@php vendor/bin/phpstan analyse --verbose --ansi"
]
}
}
}
6 changes: 6 additions & 0 deletions phpunit.xml
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,15 @@
<env name="DB_CONNECTION" value="testing"/>
</php>
<testsuites>
<testsuite name="Browser">
<directory suffix="Test.php">./tests/Browser</directory>
</testsuite>
<testsuite name="Feature">
<directory suffix="Test.php">./tests/Feature</directory>
</testsuite>
<testsuite name="Unit">
<directory suffix="Test.php">./tests/Unit</directory>
</testsuite>
</testsuites>

<source restrictNotices="true" restrictWarnings="true">
Expand Down
14 changes: 14 additions & 0 deletions tests/Browser/TestCase.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<?php

namespace Tests\SkyRaptor\FilamentBlocksBuilder\Browser;

use Tests\SkyRaptor\FilamentBlocksBuilder\Concerns\RequiresApplicationEnvironment;

/**
* This class acts as the TestCase super to be extended in
* case a Browser test is implemented.
*/
class TestCase extends \Orchestra\Testbench\Dusk\TestCase
{
use RequiresApplicationEnvironment;
}
47 changes: 47 additions & 0 deletions tests/Concerns/RequiresApplicationEnvironment.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
<?php

namespace Tests\SkyRaptor\FilamentBlocksBuilder\Concerns;

use Illuminate\Foundation\Testing\RefreshDatabase;
use Orchestra\Testbench\Attributes\WithMigration;
use Orchestra\Testbench\Concerns\WithWorkbench;
use PHPUnit\Framework\Attributes\Before;
use Workbench\App\Models\User;

#[WithMigration]
trait RequiresApplicationEnvironment
{
/* Use Orchestral Testbench's Workbench environment */
use WithWorkbench;

/* Ensure the databse is migrated & fresh before each test */
use RefreshDatabase;

/**
* The default testing User
*/
protected User $user;

/**
* This method is responsible for setting up anything
* implemented throught this Trait by using the
* PHPUnit "setUp" annotation.
*
* @setUp
*/
protected function setUpRequiresApplicationEnvironment(): void
{
/* Setup the default testing User */
$this->user = $this->createUser();
$this->actingAs($this->user);
}

/**
* This helper method does create a new
* User using the Model's Factory.
*/
protected function createUser(): User
{
return User::factory()->create();
}
}
3 changes: 1 addition & 2 deletions tests/Feature/BlocksInputTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,9 @@
use Livewire\Livewire;
use SkyRaptor\FilamentBlocksBuilder\Blocks;
use SkyRaptor\FilamentBlocksBuilder\Forms\Components\BlocksInput;
use Tests\SkyRaptor\FilamentBlocksBuilder\FeatureTestCase;
use Workbench\App\Filament\Resources\PageResource\Pages;

class BlocksInputTest extends FeatureTestCase
class BlocksInputTest extends TestCase
{
/**
* This test is intended to ensure that nested BlockBuilder instances
Expand Down
14 changes: 14 additions & 0 deletions tests/Feature/TestCase.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<?php

namespace Tests\SkyRaptor\FilamentBlocksBuilder\Feature;

use Tests\SkyRaptor\FilamentBlocksBuilder\Concerns\RequiresApplicationEnvironment;

/**
* This class acts as the TestCase super to be extended in
* case a Feature test is implemented.
*/
class TestCase extends \Orchestra\Testbench\TestCase
{
use RequiresApplicationEnvironment;
}
35 changes: 0 additions & 35 deletions tests/FeatureTestCase.php

This file was deleted.

8 changes: 0 additions & 8 deletions tests/TestCase.php

This file was deleted.

12 changes: 12 additions & 0 deletions tests/Unit/TestCase.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<?php

namespace Tests\SkyRaptor\FilamentBlocksBuilder\Unit;

/**
* This class acts as the TestCase super to be extended in
* case a Unit test is implemented.
*/
class TestCase extends \Orchestra\Testbench\TestCase
{
//
}

0 comments on commit 812752e

Please sign in to comment.