faker = \Faker\Factory::create(); Model::reguard(); $this->makeTestData(); } public function test_initial_email_sends() { $this->invoice->date = now(); $this->invoice->due_date = now()->addDays(7); $this->invoice->number = $this->getNextInvoiceNumber($this->client); $this->invoice->client_id = $this->client->id; $this->invoice->setRelation('client', $this->client); $this->invoice->save(); $invitations = InvoiceInvitation::whereInvoiceId($this->invoice->id)->get(); $email_builder = (new InvoiceEmail())->build($this->invoice, null, null); $invitations->each(function ($invitation) use ($email_builder) { if ($invitation->contact->send_invoice && $invitation->contact->email) { EmailInvoice::dispatch($email_builder, $invitation); $this->expectsJobs(EmailInvoice::class); } }); } }