Maison > Questions et réponses > le corps du texte
P粉5634465792023-09-06 21:24:29
Merci pour quelques conseils dans les réponses. Pas aussi soigné que je l'espérais, mais au moins cela signifie que tous les appels de test (« description du test ») se trouvent au même endroit au bas du fichier php.
$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); });