Files
Investidor-V2/tests/Unit/StructuredDataTest.php
T

42 lines
1.3 KiB
PHP

<?php
namespace Tests\Unit;
use App\Support\CheckedPattern;
use App\Support\StructuredData;
use Illuminate\Support\Collection;
use PHPUnit\Framework\TestCase;
use UnexpectedValueException;
class StructuredDataTest extends TestCase
{
public function test_collection_normalisation_preserves_keys_and_object_identity(): void
{
$row = (object) ['id' => 7];
$items = StructuredData::collectionItems(new Collection(['row' => $row]));
self::assertSame(['row' => $row], $items);
self::assertSame($row, $items['row']);
$generator = (static function () use ($row) {
yield 'row' => $row;
})();
self::assertSame(['row' => $row], StructuredData::collectionItems($generator));
}
public function test_invalid_scalar_cannot_be_recovered_as_an_empty_collection(): void
{
$this->expectException(UnexpectedValueException::class);
StructuredData::collectionItems('invalid structured snapshot');
}
public function test_invalid_unicode_fails_without_overwriting_the_source(): void
{
$source = "original\xFF";
try {
CheckedPattern::split('/\s+/u', $source);
self::fail('Malformed text must not be accepted as an empty result.');
} catch (\RuntimeException) {
self::assertSame("original\xFF", $source);
}
}
}