Supercharge your AI agents with data from the web and beyond. Building the library for superintelligence. 🔥
TypeScript aiai-agentsai-crawlerai-scrapingai-searchcrawlerdata-extractionhtml-to-markdownllmmarkdownscraperscrapingweb-crawlerweb-dataweb-data-extractionweb-scraperweb-scrapingweb-searchwebscraping
fix(php-sdk): add test infrastructure (phpunit.xml.dist, Pest config, unit tests)
Devin AIf5ff58e1af71
diff --git a/apps/php-sdk/phpunit.xml.dist b/apps/php-sdk/phpunit.xml.distnew file mode 100644index 000000000..ef4995bcf--- /dev/null+++ b/apps/php-sdk/phpunit.xml.dist@@ -0,0 +1,21 @@+<?xml version="1.0" encoding="UTF-8"?>+<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"+ xsi:noNamespaceSchemaLocation="vendor/phpunit/phpunit/phpunit.xsd"+ bootstrap="vendor/autoload.php"+ colors="true"+ cacheDirectory=".phpunit.cache"+>+ <testsuites>+ <testsuite name="Unit">+ <directory>tests/Unit</directory>+ </testsuite>+ <testsuite name="E2E">+ <directory>tests/E2E</directory>+ </testsuite>+ </testsuites>+ <source>+ <include>+ <directory>src</directory>+ </include>+ </source>+</phpunit>diff --git a/apps/php-sdk/tests/Pest.php b/apps/php-sdk/tests/Pest.phpnew file mode 100644index 000000000..560eff47e--- /dev/null+++ b/apps/php-sdk/tests/Pest.php@@ -0,0 +1,5 @@+<?php++declare(strict_types=1);++uses()->group('unit')->in('Unit');diff --git a/apps/php-sdk/tests/Unit/ModelsTest.php b/apps/php-sdk/tests/Unit/ModelsTest.phpnew file mode 100644index 000000000..6dc8d7e42--- /dev/null+++ b/apps/php-sdk/tests/Unit/ModelsTest.php@@ -0,0 +1,90 @@+<?php++declare(strict_types=1);++use Firecrawl\Models\CreditUsage;+use Firecrawl\Models\MapData;+use Firecrawl\Models\BatchScrapeJob;+use Firecrawl\Models\CrawlJob;++it('hydrates CreditUsage from nested data key', function (): void {+ $response = [+ 'success' => true,+ 'data' => [+ 'remainingCredits' => 500,+ 'planCredits' => 1000,+ 'billingPeriodStart' => '2025-01-01',+ 'billingPeriodEnd' => '2025-02-01',+ ],+ ];++ $usage = CreditUsage::fromArray($response);++ expect($usage->getRemainingCredits())->toBe(500);+ expect($usage->getPlanCredits())->toBe(1000);+ expect($usage->getBillingPeriodStart())->toBe('2025-01-01');+ expect($usage->getBillingPeriodEnd())->toBe('2025-02-01');+});++it('hydrates CreditUsage from flat data', function (): void {+ $response = [+ 'remainingCredits' => 250,+ 'planCredits' => 500,+ ];++ $usage = CreditUsage::fromArray($response);++ expect($usage->getRemainingCredits())->toBe(250);+ expect($usage->getPlanCredits())->toBe(500);+});++it('guards MapData links against non-array input', function (): void {+ $data = ['links' => 'not-an-array'];++ $map = MapData::fromArray($data);++ expect($map->getLinks())->toBe([]);+});++it('normalizes MapData string links', function (): void {+ $data = [+ 'links' => [+ 'https://example.com',+ ['url' => 'https://example.com/about', 'title' => 'About'],+ ],+ ];++ $map = MapData::fromArray($data);++ expect($map->getLinks())->toHaveCount(2);+ expect($map->getLinks()[0])->toBe(['url' => 'https://example.com']);+ expect($map->getLinks()[1])->toBe(['url' => 'https://example.com/about', 'title' => 'About']);+});++it('casts creditsUsed to int in BatchScrapeJob', function (): void {+ $raw = [+ 'id' => 'batch-123',+ 'status' => 'completed',+ 'completed' => 5,+ 'total' => 5,+ 'creditsUsed' => '42',+ 'data' => [],+ ];++ $job = BatchScrapeJob::fromArray($raw);++ expect($job->getCreditsUsed())->toBe(42);+ expect($job->getCreditsUsed())->toBeInt();+});++it('preserves null creditsUsed in CrawlJob', function (): void {+ $raw = [+ 'id' => 'crawl-123',+ 'status' => 'scraping',+ 'data' => [],+ ];++ $job = CrawlJob::fromArray($raw);++ expect($job->getCreditsUsed())->toBeNull();+});