33 lines
1009 B
PHP
33 lines
1009 B
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace BattleForge\Tests\Unit\Domain;
|
|
|
|
use BattleForge\Domain\Battlefield;
|
|
use BattleForge\Domain\MatchState;
|
|
use BattleForge\Domain\Position;
|
|
use BattleForge\Domain\UnitState;
|
|
use PHPUnit\Framework\TestCase;
|
|
|
|
final class CombatEngineTest extends TestCase
|
|
{
|
|
public function testMatchAndUnitStateAreImmutable(): void
|
|
{
|
|
$unit = $this->unit('unit-1', 'alpha', new Position(0, 0));
|
|
$match = new MatchState(new Battlefield(8, 8), [$unit], 'alpha');
|
|
|
|
$moved = $unit->moveTo(new Position(1, 0))->spendAction();
|
|
$next = $match->withUnit($moved);
|
|
|
|
self::assertSame('0:0', $match->unit('unit-1')->position->key());
|
|
self::assertSame('1:0', $next->unit('unit-1')->position->key());
|
|
self::assertSame(1, $next->unit('unit-1')->actionsRemaining);
|
|
}
|
|
|
|
private function unit(string $id, string $team, Position $position): UnitState
|
|
{
|
|
return new UnitState($id, $team, $position, 10, 10, 4, 2, 4, 2);
|
|
}
|
|
}
|