P粉5634465792023-09-06 21:24:29
Thanks for some tips in the reply. Not as neat as I'd hoped, but at least it means all test ("test description") calls are in one place at the bottom of the php file.
$createSubscription = function () { $this->seed(PlansTestSeeder::class); $this->seed(SubscriptionsTestSeeder::class); $this->assertDatabaseCount('plans', 2); $this->assertDatabaseCount('subscriptions', 0); Subscription::factory()->create([ "plan_id" => Plan::where("slug", "bronze")->first()->id ]); Subscription::factory()->create([ "plan_id" => Plan::where("slug", "silver")->first()->id ]); Subscription::factory()->create([ "plan_id" => Plan::where("slug", "silver")->first()->id, "status" => "expired" ]); Subscription::factory()->trashed()->create(); $this->assertDatabaseCount('subscriptions', 4); }; $createBronzeSubscription = function () { $this->seed(PlansTestSeeder::class); $this->seed(SubscriptionsTestSeeder::class); Subscription::factory()->create([ "plan_id" => Plan::where("slug", "bronze")->first()->id ]); $this->assertDatabaseCount('subscriptions', 1); }; test('can create subscription', function () use ($createSubscription) { return \Closure::bind(\Closure::fromCallable($createSubscription), $this, get_class($this))($this); }); test('can create bronze subscription', function () use ($createBronzeSubscription) { return \Closure::bind(\Closure::fromCallable($createBronzeSubscription), $this, get_class($this))($this); });