-
-
Notifications
You must be signed in to change notification settings - Fork 3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We鈥檒l occasionally send you account related emails.
Already on GitHub? Sign in to your account
Purifies model factories #12700
Merged
Merged
Purifies model factories #12700
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
PR Summary
|
This looks fantastic - thank you! |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Description
This PR "purifies" model factories as much as possible to pave the way for their use in test cases easily and with minimal side-effects (mainly avoiding the need to call them in specific and bespoke ways).
Previously, most model factories were dependent on data to be seeded in a specific way and relationships within the factories used hardcoded ids. To use a factory you would need to either seed the necessary data or set the relationship manually in each test even when you didn't particularly care about the related model.
Now, each model factory can be called in isolation using
{Model}::factory()->create()
馃帀In the process of making these changes, seeders have been updated and licenses are checked out to users in the same way that assets are when the seeders are run.
Details
Defining Related Models
Many calls like the following have been replaced:
In some instances, a model or model state requires a specific related model to exist and in those cases closures are used to handle the relationship:
Defining default required fields
Missing required fields and relationships,
qty
inAccessoryFactory
for example, have been added.Seeder Changes
Some seeders still require other data to exist before they can be run. Naive checks at the top of the relevant seeders have been added to account for this:
Tiny Test
A tiny test has been added to ensure the Asset factory can be called as expected (
tests/Feature/Api/Assets/AssetIndexTest.php
).General Clean Ups
create()
instead of setting state have been updated (f.e.Category::factory()->assetLaptopCategory()
)()
s have been added to faker calls since this syntax ($this->faker->sentence
) is depreciated and should be called as$this->faker->sentence()
accessoryKeyboardCategory
state inCategory
's name has been fixed (Keyboardss => Keyboards
)\App\Models\Asset::class => Asset::class
)Before and Afters
SettingsSeeder (16.26ms)
CompanySeeder (26.73ms)
CategorySeeder (34.32ms)
LocationSeeder (21.59ms)
UserSeeder (276.35ms)
DepreciationSeeder (10.66ms)
DepartmentSeeder (10.51ms)
ManufacturerSeeder (44.29ms)
SupplierSeeder (16.63ms)
AssetModelSeeder (40.10ms)
DepreciationSeeder (9.73ms)
StatuslabelSeeder (14.99ms)
AccessorySeeder (21.52ms)
AssetSeeder (19,159.39ms)
LicenseSeeder (70.12ms)
ComponentSeeder (39.39ms)
ConsumableSeeder (13.81ms)
ActionlogSeeder (13,612.08ms)
CustomFieldSeeder (848.16ms)
SettingsSeeder (23.28ms)
CompanySeeder (19.92ms)
CategorySeeder (30.39ms)
LocationSeeder (23.27ms)
DepartmentSeeder (11.47ms)
UserSeeder (174.96ms)
DepreciationSeeder (5.98ms)
ManufacturerSeeder (62.30ms)
SupplierSeeder (20.74ms)
AssetModelSeeder (53.74ms)
DepreciationSeeder (4.12ms)
StatuslabelSeeder (6.69ms)
AccessorySeeder (16.20ms)
AssetSeeder (7,102.35ms)
LicenseSeeder (16.15ms)
ComponentSeeder (10.02ms)
ConsumableSeeder (9.90ms)
ActionlogSeeder (3,538.21ms)
CustomFieldSeeder (1,057.00ms)
Actionlog - 400
Asset - 1373
AssetMaintenance - 0
AssetModel - 18
Category - 15
CheckoutAcceptance - 0
CheckoutRequest - 0
Company - 7
Component - 4
Consumable - 3
ConsumableAssignment - 0
CustomField - 5
CustomFieldset - 2
Department - 6
Depreciation - 3
Group - 0
Import - 0
License - 4
LicenseSeat - 50
Location - 1762
Manufacturer - 11
PredefinedKit - 0
SCIMUser - 58
Setting - 1
Statuslabel - 7
Supplier - 1718
User - 58
Actionlog - 420
Asset - 1373
AssetMaintenance - 0
AssetModel - 18
Category - 15
CheckoutAcceptance - 0
CheckoutRequest - 0
Company - 8
Component - 4
Consumable - 3
ConsumableAssignment - 0
CustomField - 5
CustomFieldset - 2
Department - 6
Depreciation - 3
Group - 0
Import - 0
License - 4
LicenseSeat - 50
Location - 10
Manufacturer - 11
PredefinedKit - 0
SCIMUser - 58
Setting - 1
Statuslabel - 7
Supplier - 5
User - 58