Rumah > Soal Jawab > teks badan
P粉5634465792023-09-06 21:24:29
Terima kasih atas beberapa petua dalam balasan. Tidak sekemas yang saya harapkan, tetapi sekurang-kurangnya ini bermakna semua panggilan ujian ("keterangan ujian") berada di satu tempat di bahagian bawah fail 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); });