Skip to content

Commit

Permalink
Create ItemTest.php
Browse files Browse the repository at this point in the history
  • Loading branch information
Mohammad-Alavi committed Feb 1, 2025
1 parent 0f03061 commit 40de582
Showing 1 changed file with 32 additions and 0 deletions.
32 changes: 32 additions & 0 deletions tests/Unit/Http/Resources/ItemTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<?php

use Apiato\Http\Resources\Item;
use Illuminate\Support\Collection as LaravelCollection;
use Workbench\App\Containers\Identity\User\Models\User;

describe(class_basename(Item::class), function (): void {
it('prioritizes the resource key from the resource', function (): void {
$sut = new Item(resourceKey: 'override');

expect($sut->getResourceKey())->toBe('override');
});

it(
'can guess the resource key from the data',
function (User|LaravelCollection|stdClass|array|Iterator|null $data, string $expectation): void {
$sut = new Item($data);

expect($sut->getResourceKey())->toBe($expectation, json_encode($data));
},
)->with([
[[], ''],
fn () => [[User::factory()->makeOne()], ''],
fn () => [User::factory(2)->make(), ''],
fn () => [User::factory(2)->make()->getIterator(), ''],
[[new class {}], ''],
fn () => [collect([new class {}]), ''],
fn () => [collect([new class {}])->getIterator(), ''],
fn () => [User::factory()->makeOne(), 'User'],
fn () => [new stdClass(), ''],
]);
})->covers(Item::class);

0 comments on commit 40de582

Please sign in to comment.