45 خطوط
1.3 KiB
PHP
45 خطوط
1.3 KiB
PHP
<?php
|
|
|
|
namespace Tests\Unit\Courses;
|
|
|
|
use App\Modules\Courses\Application\BlockDefinition;
|
|
use LogicException;
|
|
use PHPUnit\Framework\Attributes\Test;
|
|
use Tests\TestCase;
|
|
|
|
final class BlockDefinitionTest extends TestCase
|
|
{
|
|
#[Test]
|
|
public function ordered_schema_migrations_are_explicit_and_non_mutating(): void
|
|
{
|
|
$definition = new BlockDefinition(
|
|
'example',
|
|
'basic',
|
|
'Example',
|
|
'square',
|
|
3,
|
|
['text' => ''],
|
|
['text' => ['required', 'string']],
|
|
migrations: [
|
|
1 => fn (array $data): array => ['text' => $data['title']],
|
|
2 => fn (array $data): array => [...$data, 'format' => 'plain'],
|
|
],
|
|
);
|
|
$persisted = ['title' => 'Original'];
|
|
|
|
$result = $definition->migrate(1, $persisted);
|
|
|
|
$this->assertSame(['version' => 3, 'data' => ['text' => 'Original', 'format' => 'plain']], $result);
|
|
$this->assertSame(['title' => 'Original'], $persisted);
|
|
}
|
|
|
|
#[Test]
|
|
public function missing_schema_migration_fails_loudly(): void
|
|
{
|
|
$definition = new BlockDefinition('example', 'basic', 'Example', 'square', 2, [], []);
|
|
|
|
$this->expectException(LogicException::class);
|
|
$definition->migrate(1, []);
|
|
}
|
|
}
|