CluPilotCloud/database/factories/CustomerFactory.php

44 lines
1.6 KiB
PHP

<?php
namespace Database\Factories;
use App\Models\Customer;
use Illuminate\Database\Eloquent\Factories\Factory;
/** @extends Factory<Customer> */
class CustomerFactory extends Factory
{
protected $model = Customer::class;
public function definition(): array
{
return [
'name' => $this->faker->company(),
// Large unique space — safeEmail()'s pool can collide late in a full
// suite run (process-wide unique() state), tripping customers.email.
'email' => 'customer-'.$this->faker->unique()->numerify('########').'@example.test',
'locale' => 'de',
'status' => 'active',
// `customer_type` is deliberately absent, so it stays NULL: the
// factory has not asked, and neither has anybody else. A default
// here would be the one thing the column exists to prevent — an
// answer nobody gave — and it would also hide the case that most
// needs testing, since NULL is what every customer created from a
// Stripe event arrives with. Use consumer() or business() when a
// test is about the answer.
];
}
/** Somebody who said they are a private person. Has the withdrawal right. */
public function consumer(): static
{
return $this->state(['customer_type' => Customer::TYPE_CONSUMER]);
}
/** Somebody who said they are a business. Has no withdrawal right. */
public function business(): static
{
return $this->state(['customer_type' => Customer::TYPE_BUSINESS]);
}
}