employee_sites = ['PA', 'LY']; $setting->saveOrFail(); $baseTxLevel = DB::transactionLevel(); $arcadiaTxLevel = null; $lySinceTimestamps = []; /** @var ArcadiaEmployeeService&\Mockery\MockInterface $arcadiaService */ $arcadiaService = \Mockery::mock(ArcadiaEmployeeService::class); $arcadiaService->shouldReceive('getEmployeesOfSiteSince') ->once() ->with(\Mockery::on(static fn (ShopperSiteCode $s): bool => $s->value === 'PA'), \Mockery::any()) ->andReturnUsing(static function () use (&$arcadiaTxLevel): array { $arcadiaTxLevel = DB::transactionLevel(); return [ new ArcadiaEmployee( matricule: new Matricule('9123456'), lastname: 'Pa', firstname: 'Alice', startDate: CarbonImmutable::parse('2026-01-01'), endDate: null, etablissement: new ShopperEstablishmentCode('01'), site: new ShopperSiteCode('PA'), service: new ShopperServiceCode('01'), ), ]; }); $arcadiaService->shouldReceive('getEmployeesOfSiteSince') ->twice() ->with(\Mockery::on(static fn (ShopperSiteCode $s): bool => $s->value === 'LY'), \Mockery::any()) ->andReturnUsing(static function (ShopperSiteCode $site, \DateTimeInterface $since) use (&$lySinceTimestamps): false { $lySinceTimestamps[] = $since->getTimestamp(); return false; }); $cache = new CacheRepository(new ArrayStore()); $upsertService = new EmployeeUpsertService( new NullLogger(), new CodeGenerationService(new SerialCasterBuilder(new NativeBaseConverter())), new EloquentEmployeeImportStorageService(), ); $syncService = new EmployeeSyncService( new NullLogger(), $cache, $arcadiaService, $upsertService, new GetSettingsQuery(), ); $action = new SynchronizeEmployeesWithArcadiaApi($syncService); $executor = new ActionExecutorService( new LaravelCacheLock($cache), new NullLogger(), new LaravelDomainEventDispatcher(), ); $arcadiaService->shouldReceive('getEmployeesOfSiteSince') ->once() ->with( \Mockery::on(static fn (ShopperSiteCode $s): bool => $s->value === 'PA'), \Mockery::on(static fn (\DateTimeInterface $since): bool => $since->getTimestamp() > 0), ) ->andReturn([]); // WHEN $executor->execute($action, new ActionInputEmpty()); $executor->execute($action, new ActionInputEmpty()); // THEN expect($arcadiaTxLevel)->toBe($baseTxLevel) ->and(Employee::query()->where('matricule', '9123456')->first()?->last_sync)->not->toBeNull() ->and($lySinceTimestamps)->toBe([0, 0]); }); });