1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Database\Factories; |
4
|
|
|
|
5
|
|
|
use Database\Factories\Traits\ModelChanges; |
6
|
|
|
use Illuminate\Database\Eloquent\Factories\Factory; |
7
|
|
|
use Illuminate\Support\Collection; |
8
|
|
|
use Sfneal\Tracking\Utils\ModelAdapter; |
9
|
|
|
|
10
|
|
|
class TrackActionFactory extends Factory |
11
|
|
|
{ |
12
|
|
|
use ModelChanges; |
13
|
|
|
|
14
|
|
|
/** |
15
|
|
|
* TrackActionFactory constructor. |
16
|
|
|
* |
17
|
|
|
* @param null $count |
|
|
|
|
18
|
|
|
* @param Collection|null $states |
19
|
|
|
* @param Collection|null $has |
20
|
|
|
* @param Collection|null $for |
21
|
|
|
* @param Collection|null $afterMaking |
22
|
|
|
* @param Collection|null $afterCreating |
23
|
|
|
* @param null $connection |
|
|
|
|
24
|
|
|
*/ |
25
|
|
|
public function __construct($count = null, |
26
|
|
|
?Collection $states = null, |
27
|
|
|
?Collection $has = null, |
28
|
|
|
?Collection $for = null, |
29
|
|
|
?Collection $afterMaking = null, |
30
|
|
|
?Collection $afterCreating = null, |
31
|
|
|
$connection = null) |
32
|
|
|
{ |
33
|
|
|
$this->model = ModelAdapter::TrackAction(); |
34
|
|
|
parent::__construct($count, $states, $has, $for, $afterMaking, $afterCreating, $connection); |
35
|
|
|
} |
36
|
|
|
|
37
|
|
|
/** |
38
|
|
|
* Define the model's default state. |
39
|
|
|
* |
40
|
|
|
* @return array |
41
|
|
|
*/ |
42
|
|
|
public function definition(): array |
43
|
|
|
{ |
44
|
|
|
return [ |
45
|
|
|
'action' => $this->faker->randomElement($this->randomAction()), |
46
|
|
|
'model_table' => $this->faker->randomElement(['people', 'address']), |
47
|
|
|
'model_key' => $this->faker->randomNumber(3), |
48
|
|
|
'model_changes' => $this->faker->randomElements($this->modelChanges()), |
49
|
|
|
]; |
50
|
|
|
} |
51
|
|
|
|
52
|
|
|
/** |
53
|
|
|
* Retrieve an array of 'actions' to be used as random elements. |
54
|
|
|
* |
55
|
|
|
* @return array |
56
|
|
|
*/ |
57
|
|
|
protected function randomAction(): array |
58
|
|
|
{ |
59
|
|
|
return collect(['created', 'updated', 'deleted'])->each(function (string $action) { |
60
|
|
|
return ucfirst($action).' the model.'; |
61
|
|
|
})->toArray(); |
62
|
|
|
} |
63
|
|
|
} |
64
|
|
|
|