Heim > Fragen und Antworten > Hauptteil
P粉5634465792023-09-06 21:24:29
感谢回复中的一些提示。不像我希望的那样整洁,但至少这意味着所有测试(“测试描述”)调用都位于 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); });