matricule = new Matricule('1234567'); $employee->nom = 'Doe'; $employee->prenom = 'John'; $employee->site = 'Paris'; $employee->code = new Code('ABCDEFGH'); Excel::shouldReceive('store') ->once() ->with(\Mockery::on(function ($exportClass) use ($employee) { expect($exportClass->headings())->toBe(['Matricule', 'Nom', 'Prenom', 'Site', 'Code']); $mapped = $exportClass->map($employee); expect($mapped)->toBe(['1234567', 'Doe', 'John', 'Paris', $employee->code]); expect($exportClass->getCsvSettings())->toBe([ 'delimiter' => ';', 'output_encoding' => 'UTF-8', ]); expect($exportClass->collection()->first())->toBe($employee); return true; }), 'export.csv', 'local') ->andReturn(true); // WHEN $result = $service->export('local', 'export.csv', [$employee]); // THEN expect($result)->toBeTrue(); }); it('throws exception if not an employee', function () { // GIVEN $service = new EmployeeExportService(); // WHEN & THEN expect(fn () => $service->export('local', 'export.csv', [new \stdClass()])) ->toThrow(\InvalidArgumentException::class, 'employeeToExport as to be an array of ' . Employee::class); }); });