| 1 |
<?php |
| 2 |
|
| 3 |
namespace Give\Donors\Factories; |
| 4 |
|
| 5 |
use Give\Donors\ValueObjects\DonorAddress; |
| 6 |
use Give\Framework\Models\Factories\ModelFactory; |
| 7 |
use Give\Framework\Support\ValueObjects\Money; |
| 8 |
|
| 9 |
class DonorFactory extends ModelFactory |
| 10 |
{ |
| 11 |
/** |
| 12 |
* @since 4.4.0 Add "company", "avatarId", "additionalEmails", and "addresses" properties |
| 13 |
* @since 3.7.0 Add "phone" property |
| 14 |
* @since 2.19.6 |
| 15 |
*/ |
| 16 |
public function definition(): array |
| 17 |
{ |
| 18 |
$firstName = $this->faker->firstName; |
| 19 |
$lastName = $this->faker->lastName; |
| 20 |
|
| 21 |
// Generate 0-3 additional emails |
| 22 |
$additionalEmails = []; |
| 23 |
$additionalEmailCount = $this->faker->numberBetween(0, 3); |
| 24 |
for ($i = 0; $i < $additionalEmailCount; $i++) { |
| 25 |
$additionalEmails[] = $this->faker->unique()->email; |
| 26 |
} |
| 27 |
|
| 28 |
// Generate 0-3 addresses |
| 29 |
$addresses = []; |
| 30 |
$addressCount = $this->faker->numberBetween(0, 3); |
| 31 |
for ($i = 0; $i < $addressCount; $i++) { |
| 32 |
$addresses[] = DonorAddress::fromArray([ |
| 33 |
'address1' => $this->faker->streetAddress, |
| 34 |
'address2' => $this->faker->optional(0.3)->secondaryAddress, |
| 35 |
'city' => $this->faker->city, |
| 36 |
'state' => $this->faker->stateAbbr, |
| 37 |
'country' => $this->faker->countryCode, |
| 38 |
'zip' => $this->faker->postcode, |
| 39 |
]); |
| 40 |
} |
| 41 |
|
| 42 |
$data = [ |
| 43 |
'firstName' => $firstName, |
| 44 |
'lastName' => $lastName, |
| 45 |
'prefix' => $this->faker->randomElement(give_get_option('title_prefixes', array_values(give_get_default_title_prefixes()))), |
| 46 |
'name' => trim("$firstName $lastName"), |
| 47 |
'email' => $this->faker->email, |
| 48 |
'phone' => $this->faker->phoneNumber, |
| 49 |
'company' => $this->faker->company, |
| 50 |
'avatarId' => $this->faker->optional(0.2)->numberBetween(1, 9999), |
| 51 |
'additionalEmails' => $additionalEmails, |
| 52 |
'addresses' => $addresses, |
| 53 |
'totalAmountDonated' => new Money(0, 'USD'), |
| 54 |
'totalNumberOfDonations' => 0 |
| 55 |
]; |
| 56 |
|
| 57 |
return $data; |
| 58 |
} |
| 59 |
} |
| 60 |
|