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
1.1 KiB

<?php
namespace Tests\Base;
use Illuminate\Support\Arr;
trait FactoryMethodsTrait
{
public function make($class, $attrs = [], $smash = null, $withDependency = false): array
{
$factory = $withDependency ? $class::factory()->withDependency() : $class::factory();
$factory = empty($smash) ? $factory : $factory->smash($smash);
$model = $factory->make($attrs)->makeVisible((new $class())->getHidden());
return $model->toArray();
return Arr::except($model->toArray(), $model->getAppends());
}
public function one($class, $attributes = [], $dependencyAttributes = [])
{
return $class::factory()->withDependency($dependencyAttributes)->createQuietly($attributes);
}
public function randomOne($class)
{
return $class::inRandomOrder()->first();
}
public function trashed($class, $dependencyAttributes = [])
{
$model = $this->one($class,dependencyAttributes:$dependencyAttributes);
$model->delete();
$this->assertSoftDeleted($model);
return $model;
}
}