sfneal /
mock-models
| 1 | <?php |
||
| 2 | |||
| 3 | namespace Sfneal\Testing\Utils\Traits; |
||
| 4 | |||
| 5 | use Illuminate\Support\Collection; |
||
| 6 | |||
| 7 | trait ModelProvider |
||
| 8 | { |
||
| 9 | /** |
||
| 10 | * Retrieve an array of models to be used as test params. |
||
| 11 | * |
||
| 12 | * @param string $modelClass |
||
| 13 | * @param int|null $limit |
||
| 14 | * @return array |
||
| 15 | */ |
||
| 16 | protected function modelsProvider(string $modelClass, int $limit = null): array |
||
| 17 | { |
||
| 18 | $this->refreshApplication(); |
||
|
0 ignored issues
–
show
Bug
introduced
by
Loading history...
|
|||
| 19 | |||
| 20 | return $modelClass::query() |
||
| 21 | ->get() |
||
| 22 | ->when(isset($limit), function (Collection $collection) use ($limit) { |
||
| 23 | return $collection->shuffle()->take($limit); |
||
| 24 | }) |
||
| 25 | ->map(function ($model) { |
||
| 26 | return [$model]; |
||
| 27 | }) |
||
| 28 | ->toArray(); |
||
| 29 | } |
||
| 30 | } |
||
| 31 |