You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

40 lines
970 B

2 years ago
2 years ago
2 years ago
  1. <?php
  2. namespace Tests\Base;
  3. use Illuminate\Support\Arr;
  4. trait FactoryMethodsTrait
  5. {
  6. public function make($class, $attrs = [], $smash = null, $withDependency = false): array
  7. {
  8. $factory = $withDependency ? $class::factory()->withDependency() : $class::factory();
  9. $factory = empty($smash) ? $factory : $factory->smash($smash);
  10. $model = $factory->make($attrs)->makeVisible((new $class())->getHidden());
  11. return $model->toArray();
  12. return Arr::except($model->toArray(), $model->getAppends());
  13. }
  14. public function one($class, $attributes = [])
  15. {
  16. return $class::factory()->withDependency()->createQuietly($attributes);
  17. }
  18. public function randomOne($class)
  19. {
  20. return $class::inRandomOrder()->first();
  21. }
  22. public function trashed($class)
  23. {
  24. $model = $this->one($class);
  25. $model->delete();
  26. $this->assertSoftDeleted($model);
  27. return $model;
  28. }
  29. }