Skip to content

Commit

Permalink
Make Record readonly
Browse files Browse the repository at this point in the history
  • Loading branch information
tangrufus committed Dec 3, 2024
1 parent 4b96af0 commit 026563d
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 16 deletions.
20 changes: 9 additions & 11 deletions src/Record.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,22 +6,20 @@

use DateTimeInterface;

// TODO: Mark as `readonly` when Mockery supports it.
// See: https://github.com/mockery/mockery/issues/1317
class Record
readonly class Record
{
/**
* @param Software[] $software
* @param Copyright[] $copyrights
*/
public function __construct(
public readonly string $id,
public readonly string $title,
public readonly array $software,
public readonly array $references,
public readonly array $copyrights,
public readonly ?string $cve,
public readonly ?Cvss $cvss,
public readonly ?DateTimeInterface $published,
public string $id,
public string $title,
public array $software,
public array $references,
public array $copyrights,
public ?string $cve,
public ?Cvss $cvss,
public ?DateTimeInterface $published,
) {}
}
4 changes: 4 additions & 0 deletions tests/Pest.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
declare(strict_types=1);

use Tests\Feature\TestCase as FeatureTestCase;
use Tests\Unit\TestCase as UnitTestCase;

/*
|--------------------------------------------------------------------------
Expand Down Expand Up @@ -34,6 +35,9 @@
pest()->extend(FeatureTestCase::class)
->in('Feature');

pest()->extend(UnitTestCase::class)
->in('Unit');

/*
|--------------------------------------------------------------------------
| Expectations
Expand Down
9 changes: 4 additions & 5 deletions tests/Unit/ClientTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
use TypistTech\WordfenceApi\Exceptions\HttpException;
use TypistTech\WordfenceApi\Exceptions\InvalidJsonException;
use TypistTech\WordfenceApi\Feed;
use TypistTech\WordfenceApi\Record;
use TypistTech\WordfenceApi\RecordFactory;

covers(Client::class);
Expand Down Expand Up @@ -49,11 +48,11 @@
$expected = array_filter($records);
expect($actualArr)->toEqualCanonicalizing($expected);
})->with([
'single' => [[Mockery::mock(Record::class)]],
'multiple' => [[Mockery::mock(Record::class), Mockery::mock(Record::class)]],
'single' => fn () => [$this->dummyRecord()],
'multiple' => fn () => [$this->dummyRecord(), $this->dummyRecord()],

'mixed single' => [[Mockery::mock(Record::class), null]],
'mixed multiple' => [[Mockery::mock(Record::class), null, null, Mockery::mock(Record::class), null]],
'mixed single' => fn () => [$this->dummyRecord(), null],
'mixed multiple' => fn () => [$this->dummyRecord(), null, null, $this->dummyRecord(), null],

'null single' => [[null]],
'null multiple' => [[null, null]],
Expand Down
25 changes: 25 additions & 0 deletions tests/Unit/TestCase.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<?php

declare(strict_types=1);

namespace Tests\Unit;

use PHPUnit\Framework\TestCase as BaseTestCase;
use TypistTech\WordfenceApi\Record;

abstract class TestCase extends BaseTestCase
{
public function dummyRecord(): Record
{
return new Record(
uniqid('id_', false),
uniqid('title_', false),
[],
[],
[],
null,
null,
null,
);
}
}

0 comments on commit 026563d

Please sign in to comment.