68 lines
2.5 KiB
PHP
68 lines
2.5 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace Tests\Unit\ValueObjects;
|
|
|
|
use App\Enums\CrawlOutcomeEnum;
|
|
use App\ValueObjects\FetchResult;
|
|
use Illuminate\Support\Collection;
|
|
use PHPUnit\Framework\TestCase;
|
|
|
|
class FetchResultTest extends TestCase
|
|
{
|
|
public function test_it_exposes_all_fields(): void
|
|
{
|
|
$result = new FetchResult(
|
|
outcome: CrawlOutcomeEnum::Success,
|
|
statusCode: 200,
|
|
finalUrl: 'https://example.com/article',
|
|
title: 'An Example Article',
|
|
extractedText: 'Lorem ipsum dolor sit amet.',
|
|
outboundLinks: collect(['https://other.com', 'https://another.com']),
|
|
wordCount: 5,
|
|
errorMessage: null,
|
|
language: 'en',
|
|
languageConfidence: 0.95,
|
|
);
|
|
|
|
$this->assertSame(CrawlOutcomeEnum::Success, $result->outcome);
|
|
$this->assertSame(200, $result->statusCode);
|
|
$this->assertSame('https://example.com/article', $result->finalUrl);
|
|
$this->assertSame('An Example Article', $result->title);
|
|
$this->assertSame('Lorem ipsum dolor sit amet.', $result->extractedText);
|
|
$this->assertInstanceOf(Collection::class, $result->outboundLinks);
|
|
$this->assertSame(['https://other.com', 'https://another.com'], $result->outboundLinks->all());
|
|
$this->assertSame(5, $result->wordCount);
|
|
$this->assertNull($result->errorMessage);
|
|
$this->assertSame('en', $result->language);
|
|
$this->assertSame(0.95, $result->languageConfidence);
|
|
}
|
|
|
|
public function test_it_accepts_null_for_failure_outcome_fields(): void
|
|
{
|
|
$result = new FetchResult(
|
|
outcome: CrawlOutcomeEnum::Failed,
|
|
statusCode: null,
|
|
finalUrl: null,
|
|
title: null,
|
|
extractedText: null,
|
|
outboundLinks: collect(),
|
|
wordCount: null,
|
|
errorMessage: 'Could not connect',
|
|
language: null,
|
|
languageConfidence: null,
|
|
);
|
|
|
|
$this->assertSame(CrawlOutcomeEnum::Failed, $result->outcome);
|
|
$this->assertNull($result->statusCode);
|
|
$this->assertNull($result->finalUrl);
|
|
$this->assertNull($result->title);
|
|
$this->assertNull($result->extractedText);
|
|
$this->assertSame([], $result->outboundLinks->all());
|
|
$this->assertNull($result->wordCount);
|
|
$this->assertSame('Could not connect', $result->errorMessage);
|
|
$this->assertNull($result->language);
|
|
$this->assertNull($result->languageConfidence);
|
|
}
|
|
}
|