diff --git a/composer.json b/composer.json index cfee185..4b74455 100644 --- a/composer.json +++ b/composer.json @@ -40,7 +40,9 @@ }, "autoload-dev": { "psr-4": { - "Tests\\": "tests/" + "Tests\\": "tests/", + "Workbench\\App\\": "workbench/app/", + "Workbench\\Database\\Factories\\": "workbench/database/factories/" } }, "extra": { @@ -59,6 +61,10 @@ "config": { "sort-packages": true }, + "scripts": { + "post-autoload-dump": "@prepare", + "prepare": "@php vendor/bin/testbench package:discover --ansi" + }, "minimum-stability": "dev", "prefer-stable": true } diff --git a/testbench.yaml b/testbench.yaml new file mode 100644 index 0000000..705c076 --- /dev/null +++ b/testbench.yaml @@ -0,0 +1,8 @@ +providers: + - Laravel\Pennant\PennantServiceProvider + +migrations: + - database/migrations + +workbench: + install: true diff --git a/tests/Feature/ArrayDriverTest.php b/tests/Feature/ArrayDriverTest.php index 03f8024..7a09333 100644 --- a/tests/Feature/ArrayDriverTest.php +++ b/tests/Feature/ArrayDriverTest.php @@ -19,6 +19,9 @@ use Laravel\Pennant\Feature; use RuntimeException; use Tests\TestCase; +use Workbench\App\Models\User; + +use function Orchestra\Testbench\workbench_path; class ArrayDriverTest extends TestCase { @@ -857,13 +860,13 @@ public function test_it_can_set_for_all() public function test_it_can_auto_register_feature_classes() { Feature::define('marketing-design', 'marketing-design-value'); - Feature::discover('Tests\\FeatureClasses', __DIR__.'/../FeatureClasses'); + Feature::discover('Workbench\\App\\Features', workbench_path('app/Features')); $all = Feature::all(); $this->assertSame([ 'marketing-design' => 'marketing-design-value', - 'Tests\\FeatureClasses\\NewApi' => 'new-api-value', + 'Workbench\\App\\Features\\NewApi' => 'new-api-value', ], $all); } diff --git a/tests/Feature/DatabaseDriverTest.php b/tests/Feature/DatabaseDriverTest.php index 227de97..1e2adb1 100644 --- a/tests/Feature/DatabaseDriverTest.php +++ b/tests/Feature/DatabaseDriverTest.php @@ -8,7 +8,6 @@ use Illuminate\Support\Facades\Config; use Illuminate\Support\Facades\DB; use Illuminate\Support\Facades\Event; -use Illuminate\Support\Facades\Schema; use Laravel\Pennant\Contracts\FeatureScopeable; use Laravel\Pennant\Events\AllFeaturesPurged; use Laravel\Pennant\Events\DynamicallyRegisteringFeatureClass; @@ -20,6 +19,10 @@ use Laravel\Pennant\Events\UnknownFeatureResolved; use Laravel\Pennant\Feature; use Tests\TestCase; +use Workbench\App\Models\User; +use Workbench\Database\Factories\UserFactory; + +use function Orchestra\Testbench\workbench_path; class DatabaseDriverTest extends TestCase { @@ -365,15 +368,11 @@ public function toFeatureIdentifier($driver): mixed public function test_it_serializes_eloquent_models() { - Schema::create('users', function ($table) { - $table->id(); - $table->timestamps(); - }); - Feature::for(User::create())->activate('foo'); + Feature::for(UserFactory::new()->create())->activate('foo'); $scope = DB::table('features')->value('scope'); - $this->assertStringContainsString('Tests\Feature\User|1', $scope); + $this->assertStringContainsString('Workbench\App\Models\User|1', $scope); } public function test_it_can_load_feature_state_into_memory() @@ -1047,13 +1046,13 @@ public function test_it_can_set_for_all() public function test_it_can_auto_register_feature_classes() { Feature::define('marketing-design', 'marketing-design-value'); - Feature::discover('Tests\\FeatureClasses', __DIR__.'/../FeatureClasses'); + Feature::discover('Workbench\\App\\Features', workbench_path('app/Features')); $all = Feature::all(); $this->assertSame([ 'marketing-design' => 'marketing-design-value', - 'Tests\\FeatureClasses\\NewApi' => 'new-api-value', + 'Workbench\\App\\Features\\NewApi' => 'new-api-value', ], $all); } diff --git a/tests/Feature/FeatureDirectiveTest.php b/tests/Feature/FeatureDirectiveTest.php index e7af0b4..4511951 100644 --- a/tests/Feature/FeatureDirectiveTest.php +++ b/tests/Feature/FeatureDirectiveTest.php @@ -2,7 +2,7 @@ namespace Tests\Feature; -use Illuminate\Foundation\Testing\RefreshDatabase; +use Illuminate\Foundation\Testing\LazilyRefreshDatabase; use Illuminate\Support\Facades\Blade; use Illuminate\Support\Facades\Config; use Laravel\Pennant\Feature; @@ -10,7 +10,7 @@ class FeatureDirectiveTest extends TestCase { - use RefreshDatabase; + use LazilyRefreshDatabase; protected function setUp(): void { diff --git a/tests/Feature/FeatureManagerTest.php b/tests/Feature/FeatureManagerTest.php index 4903eae..0b48f70 100644 --- a/tests/Feature/FeatureManagerTest.php +++ b/tests/Feature/FeatureManagerTest.php @@ -2,15 +2,16 @@ namespace Tests\Feature; -use Illuminate\Foundation\Testing\RefreshDatabase; +use Illuminate\Foundation\Testing\LazilyRefreshDatabase; use Illuminate\Support\Facades\Auth; use Illuminate\Support\Lottery; use Laravel\Pennant\Feature; use Tests\TestCase; +use Workbench\App\Models\User; class FeatureManagerTest extends TestCase { - use RefreshDatabase; + use LazilyRefreshDatabase; public function test_it_can_chain_scope_additions() { diff --git a/tests/Feature/FeatureMiddlewareTest.php b/tests/Feature/FeatureMiddlewareTest.php index 29dbb7c..3f89176 100644 --- a/tests/Feature/FeatureMiddlewareTest.php +++ b/tests/Feature/FeatureMiddlewareTest.php @@ -2,7 +2,7 @@ namespace Tests\Feature; -use Illuminate\Foundation\Testing\RefreshDatabase; +use Illuminate\Foundation\Testing\LazilyRefreshDatabase; use Illuminate\Http\Request; use Laravel\Pennant\Feature; use Laravel\Pennant\Middleware\EnsureFeaturesAreActive; @@ -13,7 +13,7 @@ class FeatureMiddlewareTest extends TestCase { - use RefreshDatabase; + use LazilyRefreshDatabase; private EnsureFeaturesAreActive $middleware; diff --git a/tests/Feature/PurgeCommandTest.php b/tests/Feature/PurgeCommandTest.php index c1362a1..46d11c1 100644 --- a/tests/Feature/PurgeCommandTest.php +++ b/tests/Feature/PurgeCommandTest.php @@ -2,7 +2,7 @@ namespace Tests\Feature; -use Illuminate\Foundation\Testing\RefreshDatabase; +use Illuminate\Foundation\Testing\LazilyRefreshDatabase; use Illuminate\Support\Facades\DB; use InvalidArgumentException; use Laravel\Pennant\Feature; @@ -10,7 +10,7 @@ class PurgeCommandTest extends TestCase { - use RefreshDatabase; + use LazilyRefreshDatabase; public function test_it_can_purge_flags() { diff --git a/tests/Feature/User.php b/tests/Feature/User.php deleted file mode 100644 index 305b8e8..0000000 --- a/tests/Feature/User.php +++ /dev/null @@ -1,10 +0,0 @@ -loadMigrationsFrom(__DIR__.'/../database/migrations'); - } - - /** - * Get package providers. - * - * @param \Illuminate\Foundation\Application $app - * @return array> - */ - protected function getPackageProviders($app) - { - return [ - PennantServiceProvider::class, - ]; - } + use WithWorkbench; /** * Create an instance of the manager. diff --git a/tests/FeatureClasses/NewApi.php b/workbench/app/Features/NewApi.php similarity index 76% rename from tests/FeatureClasses/NewApi.php rename to workbench/app/Features/NewApi.php index a2b03fa..713077a 100644 --- a/tests/FeatureClasses/NewApi.php +++ b/workbench/app/Features/NewApi.php @@ -1,6 +1,6 @@ + */ +class UserFactory extends \Orchestra\Testbench\Factories\UserFactory +{ + /** + * The name of the factory's corresponding model. + * + * @var class-string + */ + protected $model = User::class; +}