|
| 1 | +<?php |
| 2 | + |
| 3 | +namespace Database\Factories; |
| 4 | + |
| 5 | +use App\Models\Import; |
| 6 | +use Illuminate\Support\Str; |
| 7 | +use Illuminate\Database\Eloquent\Factories\Factory; |
| 8 | +use Tests\Support\Importing; |
| 9 | + |
| 10 | +/** |
| 11 | + * @extends Factory<Import> |
| 12 | + */ |
| 13 | +class ImportFactory extends Factory |
| 14 | +{ |
| 15 | + /** |
| 16 | + * @inheritdoc |
| 17 | + */ |
| 18 | + protected $model = Import::class; |
| 19 | + |
| 20 | + /** |
| 21 | + * @inheritdoc |
| 22 | + */ |
| 23 | + public function definition() |
| 24 | + { |
| 25 | + return [ |
| 26 | + 'name' => $this->faker->company, |
| 27 | + 'file_path' => Str::random().'.csv', |
| 28 | + 'filesize' => $this->faker->randomDigitNotNull(), |
| 29 | + 'field_map' => null, |
| 30 | + ]; |
| 31 | + } |
| 32 | + |
| 33 | + /** |
| 34 | + * Create an accessory import type. |
| 35 | + * |
| 36 | + * @return static |
| 37 | + */ |
| 38 | + public function accessory() |
| 39 | + { |
| 40 | + return $this->state(function (array $attributes) { |
| 41 | + $fileBuilder = Importing\AccessoriesImportFileBuilder::new(); |
| 42 | + |
| 43 | + $attributes['name'] = "{$attributes['name']} Accessories"; |
| 44 | + $attributes['import_type'] = 'accessory'; |
| 45 | + $attributes['header_row'] = $fileBuilder->toCsv()[0]; |
| 46 | + $attributes['first_row'] = $fileBuilder->firstRow(); |
| 47 | + |
| 48 | + return $attributes; |
| 49 | + }); |
| 50 | + } |
| 51 | + |
| 52 | + /** |
| 53 | + * Create an asset import type. |
| 54 | + * |
| 55 | + * @return static |
| 56 | + */ |
| 57 | + public function asset() |
| 58 | + { |
| 59 | + return $this->state(function (array $attributes) { |
| 60 | + $fileBuilder = Importing\AssetsImportFileBuilder::new(); |
| 61 | + |
| 62 | + $attributes['name'] = "{$attributes['name']} Assets"; |
| 63 | + $attributes['import_type'] = 'asset'; |
| 64 | + $attributes['header_row'] = $fileBuilder->toCsv()[0]; |
| 65 | + $attributes['first_row'] = $fileBuilder->firstRow(); |
| 66 | + |
| 67 | + return $attributes; |
| 68 | + }); |
| 69 | + } |
| 70 | + |
| 71 | + /** |
| 72 | + * Create a component import type. |
| 73 | + * |
| 74 | + * @return static |
| 75 | + */ |
| 76 | + public function component() |
| 77 | + { |
| 78 | + return $this->state(function (array $attributes) { |
| 79 | + $fileBuilder = Importing\ComponentsImportFileBuilder::new(); |
| 80 | + |
| 81 | + $attributes['name'] = "{$attributes['name']} Components"; |
| 82 | + $attributes['import_type'] = 'component'; |
| 83 | + $attributes['header_row'] = $fileBuilder->toCsv()[0]; |
| 84 | + $attributes['first_row'] = $fileBuilder->firstRow(); |
| 85 | + |
| 86 | + return $attributes; |
| 87 | + }); |
| 88 | + } |
| 89 | + |
| 90 | + /** |
| 91 | + * Create a consumable import type. |
| 92 | + * |
| 93 | + * @return static |
| 94 | + */ |
| 95 | + public function consumable() |
| 96 | + { |
| 97 | + return $this->state(function (array $attributes) { |
| 98 | + $fileBuilder = Importing\ConsumablesImportFileBuilder::new(); |
| 99 | + |
| 100 | + $attributes['name'] = "{$attributes['name']} Consumables"; |
| 101 | + $attributes['import_type'] = 'consumable'; |
| 102 | + $attributes['header_row'] = $fileBuilder->toCsv()[0]; |
| 103 | + $attributes['first_row'] = $fileBuilder->firstRow(); |
| 104 | + |
| 105 | + return $attributes; |
| 106 | + }); |
| 107 | + } |
| 108 | + |
| 109 | + /** |
| 110 | + * Create a license import type. |
| 111 | + * |
| 112 | + * @return static |
| 113 | + */ |
| 114 | + public function license() |
| 115 | + { |
| 116 | + return $this->state(function (array $attributes) { |
| 117 | + $fileBuilder = Importing\LicensesImportFileBuilder::new(); |
| 118 | + |
| 119 | + $attributes['name'] = "{$attributes['name']} Licenses"; |
| 120 | + $attributes['import_type'] = 'license'; |
| 121 | + $attributes['header_row'] = $fileBuilder->toCsv()[0]; |
| 122 | + $attributes['first_row'] = $fileBuilder->firstRow(); |
| 123 | + |
| 124 | + return $attributes; |
| 125 | + }); |
| 126 | + } |
| 127 | + |
| 128 | + /** |
| 129 | + * Create a users import type. |
| 130 | + * |
| 131 | + * @return static |
| 132 | + */ |
| 133 | + public function users() |
| 134 | + { |
| 135 | + return $this->state(function (array $attributes) { |
| 136 | + $fileBuilder = Importing\UsersImportFileBuilder::new(); |
| 137 | + |
| 138 | + $attributes['name'] = "{$attributes['name']} Employees"; |
| 139 | + $attributes['import_type'] = 'user'; |
| 140 | + $attributes['header_row'] = $fileBuilder->toCsv()[0]; |
| 141 | + $attributes['first_row'] = $fileBuilder->firstRow(); |
| 142 | + |
| 143 | + return $attributes; |
| 144 | + }); |
| 145 | + } |
| 146 | +} |
0 commit comments