12 - Add crawler config and FetchResult value object
This commit is contained in:
parent
abbcedf2e7
commit
a9f2d689ae
2 changed files with 59 additions and 0 deletions
22
app/ValueObjects/FetchResult.php
Normal file
22
app/ValueObjects/FetchResult.php
Normal file
|
|
@ -0,0 +1,22 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\ValueObjects;
|
||||
|
||||
use App\Enums\CrawlOutcomeEnum;
|
||||
use Illuminate\Support\Collection;
|
||||
|
||||
class FetchResult
|
||||
{
|
||||
public function __construct(
|
||||
public CrawlOutcomeEnum $outcome,
|
||||
public int $statusCode,
|
||||
public string $finalUrl,
|
||||
public string $title,
|
||||
public string $extractedText,
|
||||
public Collection $outboundLinks,
|
||||
public int $wordCount,
|
||||
public ?string $errorMessage,
|
||||
) {}
|
||||
}
|
||||
37
tests/Unit/ValueObjects/FetchResultTest.php
Normal file
37
tests/Unit/ValueObjects/FetchResultTest.php
Normal file
|
|
@ -0,0 +1,37 @@
|
|||
<?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,
|
||||
);
|
||||
|
||||
$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);
|
||||
}
|
||||
}
|
||||
Loading…
Reference in a new issue