Overview
Unleash Commerce Core ships with factories for all models, making it easy to write tests for your custom implementations and extensions.Model Factories
All core models include Laravel factories that you can use in your tests. Create test data quickly:Using Factories with Relationships
Use thefor method to associate models:
Attaching Customers to Users
The User factory includes ahasCustomer method to easily attach customers with proper pivot attributes.
By default,
hasCustomer marks the customer as active (is_active = true, invitation_accepted_at = now).
The active customer is used throughout the application for authorization and scoping data in B2B contexts.Assigning Roles to Users
The User factory includes arole method to assign roles to users in the context of their active customer.
Roles in Unleash Commerce are scoped to customers (B2B multi-tenancy). The
role method automatically
uses the user’s active customer as the authorization context. If no customer is explicitly provided,
the role is assigned using $user->activeCustomer.