Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add test for readonly class #66

Merged
merged 2 commits into from
Dec 27, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions tests/TestEnvironments/Php82/HydratorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

use PHPUnit\Framework\TestCase;
use Yiisoft\Hydrator\Hydrator;
use Yiisoft\Hydrator\Tests\TestEnvironments\Php82\Support\ReadonlyClass;
use Yiisoft\Hydrator\Tests\TestEnvironments\Php82\Support\TypeObject;

final class HydratorTest extends TestCase
Expand Down Expand Up @@ -44,4 +45,14 @@ public function testTypeCast(array $expectedValues, array $data): void
]
);
}

public function testReadonlyClass(): void
{
$hydrator = new Hydrator();

$object = $hydrator->create(ReadonlyClass::class, ['name' => 'Test', 'age' => 19]);

$this->assertSame('Test', $object->name);
$this->assertSame(19, $object->age);
}
}
14 changes: 14 additions & 0 deletions tests/TestEnvironments/Php82/Support/ReadonlyClass.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<?php

declare(strict_types=1);

namespace Yiisoft\Hydrator\Tests\TestEnvironments\Php82\Support;

final readonly class ReadonlyClass
{
public function __construct(
public string $name,
public int $age,
) {
}
}