add factories necessary for testing customer and customer addresses

This commit is contained in:
David Große 2020-01-10 11:51:03 +01:00
parent 78915686e8
commit f1090efa73
4 changed files with 88 additions and 2 deletions

View File

@ -0,0 +1,28 @@
<?php
/** @var \Illuminate\Database\Eloquent\Factory $factory */
use Faker\Generator as Faker;
use Webkul\Customer\Models\Customer;
use Webkul\Customer\Models\CustomerAddress;
$factory->define(CustomerAddress::class, function (Faker $faker) {
$now = date("Y-m-d H:i:s");
return [
'customer_id' => function() {
return factory(Customer::class)->create()->id;
},
'address1' => $faker->streetAddress,
'country' => $faker->countryCode,
'state' => $faker->state,
'city' => $faker->city,
'postcode' => $faker->postcode,
'phone' => $faker->e164PhoneNumber,
'default_address' => 1,
'created_at' => $now,
'updated_at' => $now,
];
});

View File

@ -0,0 +1,35 @@
<?php
/** @var \Illuminate\Database\Eloquent\Factory $factory */
use Faker\Generator as Faker;
use Illuminate\Support\Facades\Hash;
use Webkul\Customer\Models\Customer;
$factory->define(Customer::class, function (Faker $faker) {
$now = date("Y-m-d H:i:s");
$gender = array_rand(['male', 'female', 'other']);
$password = $faker->password;
return [
'first_name' => $faker->firstName($gender),
'last_name' => $faker->lastName,
'gender' => ucfirst($gender),
'email' => $faker->email,
'status' => 1,
'password' => Hash::make($password),
'customer_group_id' => 2,
'is_verified' => 1,
'created_at' => $now,
'updated_at' => $now,
'notes' => json_encode(array('plain_password' => $password)),
];
});
$factory->state(Customer::class, 'male', [
'gender' => 'Male',
]);
$factory->state(Customer::class, 'female', [
'gender' => 'Female',
]);

View File

@ -5,6 +5,7 @@ namespace Webkul\Customer\Providers;
use Illuminate\Support\ServiceProvider;
use Illuminate\Routing\Router;
use Webkul\Customer\Http\Middleware\RedirectIfNotCustomer;
use Illuminate\Database\Eloquent\Factory as EloquentFactory;
class CustomerServiceProvider extends ServiceProvider
{
@ -15,5 +16,27 @@ class CustomerServiceProvider extends ServiceProvider
$this->loadTranslationsFrom(__DIR__ . '/../Resources/lang', 'customer');
$this->loadMigrationsFrom(__DIR__ . '/../Database/Migrations');
$this->registerEloquentFactoriesFrom(__DIR__ . '/../Database/Factories');
}
/**
* Register services.
*
* @return void
*/
public function register(): void
{
}
/**
* Register factories.
*
* @param string $path
* @return void
*/
protected function registerEloquentFactoriesFrom($path): void
{
$this->app->make(EloquentFactory::class)->load($path);
}
}

View File

@ -80,8 +80,8 @@ class CustomerCest
$I->seeInSource('Address have been successfully added.');
$I->seeRecord(CustomerAddress::class, [
'company_name' => $fields['company'],
'address1' => $fields['address1'],
'company_name' => $fields['company_name'],
'address1' => $fields['address1[]'],
'country' => $fields['country'],
'state' => $fields['state'],
'city' => $fields['city'],