Код: Выделить всё
class WorkSiteFactory extends Factory
{
// ... Other factory stuff....
/**
* Indicate that the Permit status is fully approved.
*/
public function withApprovedPermit(): self
{
return $this->state([
'permit_paid_at' => $this->faker->dateTimeBetween('-12 days', '-8 days'),
'permit_approved_at' => $this->faker->dateTimeBetween('-12 days', '-8 days')
]);
}
}
Код: Выделить всё
use App\Models\WorkSite;
use Illuminate\Support\Carbon;
use Tests\TestCase;
class SchedulerControllerTest extends TestCase
{
/** @test */
public function index_returns_correct_number_of_work_sites(): void
{
// Set the mocked "now" time
$mockNow = Carbon::parse('2024-10-01');
Carbon::setTestNow($mockNow);
// Incomplete WorkSites won't show up as available
WorkSite::factory()
->count(2)
->incomplete()
->create();
// 4 WorkSites Ready to Work
$workSites = WorkSite::factory()
->count(4)
->readyToWork()
->withApprovedPermit() // ❌
Подробнее здесь: [url]https://stackoverflow.com/questions/79135705/how-can-i-use-carbonsettestnow-to-influence-the-results-of-the-fakerphp-date[/url]
Мобильная версия