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

<?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 = [])
{
return $class::factory()->withDependency()->createQuietly($attributes);
}
public function randomOne($class)
{
return $class::inRandomOrder()->first();
}
public function trashed($class)
{
$model = $this->one($class);
$model->delete();
$this->assertSoftDeleted($model);
return $model;
}
}