File size: 1,649 Bytes
097eaf0
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
<?php

declare(strict_types=1);

use Firecrawl\Exceptions\FirecrawlException;
use Firecrawl\Models\JsonFormat;
use Firecrawl\Models\ParseFile;
use Firecrawl\Models\ParseOptions;

it('builds a ParseFile from bytes', function (): void {
    $file = ParseFile::fromBytes('doc.pdf', 'hello');

    expect($file->getFilename())->toBe('doc.pdf');
    expect($file->getContent())->toBe('hello');
});

it('rejects empty filename', function (): void {
    ParseFile::fromBytes('  ', 'hello');
})->throws(FirecrawlException::class);

it('rejects empty content', function (): void {
    ParseFile::fromBytes('doc.pdf', '');
})->throws(FirecrawlException::class);

it('serializes ParseOptions with JSON format', function (): void {
    $options = ParseOptions::with(
        formats: ['markdown', JsonFormat::with(prompt: 'Extract')],
        onlyMainContent: true,
    );

    $array = $options->toArray();

    expect($array['formats'][0])->toBe('markdown');
    expect($array['formats'][1])->toMatchArray(['type' => 'json', 'prompt' => 'Extract']);
    expect($array['onlyMainContent'])->toBeTrue();
});

it('rejects unsupported parse formats', function (): void {
    ParseOptions::with(formats: ['screenshot']);
})->throws(FirecrawlException::class);

it('rejects video parse format', function (): void {
    ParseOptions::with(formats: ['video']);
})->throws(FirecrawlException::class);

it('rejects invalid proxy values', function (): void {
    ParseOptions::with(proxy: 'stealth');
})->throws(FirecrawlException::class);

it('rejects non-positive timeout', function (): void {
    ParseOptions::with(timeout: 0);
})->throws(FirecrawlException::class);