2026-10-28 18:17:34 +00:00
< ? php
use App\Game\ConfigLint ;
it ( 'finds no locks in the default config' , function () {
expect ( ConfigLint :: check ( gameConfig ())) -> toBe ([]);
});
it ( 'finds no locks in the dev world' , function () {
expect ( ConfigLint :: check ( gameConfig ([ 'world' => [ 'speed' => 100 ]]))) -> toBe ([]);
});
it ( 'reports a farm whose workers eat more than it makes' , function () {
$config = gameConfig ([ 'buildings' => [ 'farm' => [ 'workers' => [ 'base' => 40 ]]]]);
2026-10-28 21:26:25 +00:00
expect ( ConfigLint :: check ( $config )) -> toContain ( '[farm] level 1 feeds fewer people than it needs as workers.' );
2026-10-28 18:17:34 +00:00
});
2026-11-03 08:38:20 +00:00
it ( 'checks farms in heads, so a fast world does not hide a farm that feeds too few' , function () {
// 2 food/h at speed 1 for 2 workers: 200 food/h at speed 100 hides nothing.
$config = gameConfig ([ 'world' => [ 'speed' => 100 ], 'buildings' => [ 'farm' => [ 'production' => [ 'base' => 2 ]]]]);
expect ( ConfigLint :: check ( $config )) -> toContain ( '[farm] level 1 feeds fewer people than it needs as workers.' );
});
it ( 'reports when one farm at max level cannot staff one of every building at max level' , function () {
// Farm 30 feeds 19387 heads; at a 1% share that is 193 villagers for 343 workers.
$config = gameConfig ([ 'economy' => [ 'villager_share' => 0.01 ]]);
expect ( ConfigLint :: check ( $config ))
-> toContain ( 'One of every building at max level needs 343 workers, more than the 193 villagers one farm at max level feeds.' );
});
2026-10-28 18:17:34 +00:00
it ( 'reports a storage level that its predecessor cannot pay for' , function () {
$config = gameConfig ([ 'buildings' => [ 'storage' => [ 'cost' => [ 'wood' => 2000 ]]]]);
2026-10-28 21:26:25 +00:00
expect ( ConfigLint :: check ( $config )) -> toContain ( '[storage] level 2 costs more than level 1 holds.' );
2026-10-28 18:17:34 +00:00
});
it ( 'reports requirement cycles and unknown requirements' , function () {
$config = gameConfig ([ 'buildings' => [
'wall' => [ 'requires' => [ 'rally_point' => 1 ]],
'rally_point' => [ 'requires' => [ 'wall' => 1 , 'castle' => 1 ]],
]]);
expect ( ConfigLint :: check ( $config ))
-> toContain ( '[rally_point] requires unknown type [castle].' )
-> toContain ( 'Requirement cycle through [wall].' );
});
2026-10-28 18:45:02 +00:00
it ( 'reports start buildings that take more space than a village has' , function () {
$config = gameConfig ([ 'world' => [ 'village' => [ 'space' => 12 ]]]);
2026-10-28 18:17:34 +00:00
2026-10-28 18:45:02 +00:00
expect ( ConfigLint :: check ( $config )) -> toBe ([ 'The start buildings take 17 building space, more than the village\'s 12.' ]);
});
it ( 'reports a type that can never fit next to the start buildings' , function () {
$config = gameConfig ([ 'world' => [ 'village' => [ 'space' => 25 ]]]);
2026-10-28 20:39:48 +00:00
expect ( ConfigLint :: check ( $config )) -> toBe ([
'[headquarters] does not fit next to the start buildings.' ,
'[academy] does not fit next to the start buildings.' ,
]);
2026-10-28 18:17:34 +00:00
});
2026-10-28 20:28:16 +00:00
it ( 'reports a villager share that leaves no food surplus' , function () {
expect ( ConfigLint :: check ( gameConfig ([ 'economy' => [ 'villager_share' => 1.0 ]])))
-> toBe ([ 'economy.villager_share must be between 0 and 1 (is 1), so farms leave a surplus.' ]);
});
2026-10-28 21:03:33 +00:00
it ( 'reports a levy or desertion timer that never runs out' , function () {
$config = gameConfig ([ 'economy' => [ 'levy' => [ 'duration' => 0 ], 'starvation' => [ 'grace' => - 1 ]]]);
expect ( ConfigLint :: check ( $config )) -> toBe ([
'[economy.levy.duration] must be more than 0 seconds.' ,
'[economy.starvation.grace] cannot be negative.' ,
]);
});
2026-10-29 15:02:49 +00:00
2026-10-31 09:57:05 +00:00
it ( 'reports copies that work for nothing, above full, or get cheaper' , function () {
$lint = fn ( array $overrides ) => ConfigLint :: check ( gameConfig ( $overrides ));
expect ( $lint ([ 'economy' => [ 'instance_share' => 0 ]])) -> toBe ([ '[economy.instance_share] must be above 0 and at most 1 (is 0).' ])
-> and ( $lint ([ 'economy' => [ 'instance_share' => 1.5 ]])) -> toBe ([ '[economy.instance_share] must be above 0 and at most 1 (is 1.5).' ])
-> and ( $lint ([ 'economy' => [ 'instance_share' => 1 ]])) -> toBe ([])
-> and ( $lint ([ 'buildings' => [ 'barracks' => [ 'instance_cost_factor' => 0.9 ]]]))
-> toBe ([ '[barracks] instance_cost_factor must be at least 1, or copies get cheaper.' ]);
});
2026-10-29 15:02:49 +00:00
it ( 'reports garrisons that would starve their village or never regroup' , function () {
$config = gameConfig ([ 'world' => [ 'map' => [ 'barbarians' => [ 'garrison' => [
'max_food_share' => 0.9 ,
'regroup' => [ 'every_hours' => 0 ],
'profiles' => [ 'ghosts' => [ 'wraith' => 1.0 ]],
]]]]]);
expect ( ConfigLint :: check ( $config ))
-> toContain ( 'Garrison profile [ghosts] fields [wraith], which is not a unit with a share above 0.' )
-> toContain ( 'Barbarian garrisons must regroup: [regroup.every_hours] and [regroup.share] above 0.' )
-> toContain ( '[garrison.max_food_share] must stay below [economy.villager_share], or a garrison starves its village.' );
});
2026-11-03 08:31:21 +00:00
it ( 'reports barbarian waves that never pause, bring fewer than none or settle on the village' , function () {
$waves = fn ( array $waves ) => ConfigLint :: check ( gameConfig ([ 'world' => [ 'map' => [ 'barbarians' => [ 'waves' => $waves ]]]]));
expect ( $waves ([ 'every_days' => [ 0 , 3 ], 'per_player' => - 1 , 'near' => 0.5 ])) -> toBe ([
'[barbarians.waves.every_days] must be two days above 0, the smaller first, so waves come apart in time.' ,
'[barbarians.waves.per_player] cannot be negative.' ,
'[barbarians.waves.near] must be at least 1 field.' ,
])
-> and ( $waves ([ 'every_days' => [ 9 , 5 ]])) -> toBe ([ '[barbarians.waves.every_days] must be two days above 0, the smaller first, so waves come apart in time.' ])
-> and ( $waves ([ 'enabled' => false , 'every_days' => [ 0 , 0 ]])) -> toBe ([]);
});
2026-10-29 15:07:54 +00:00
it ( 'reports raids that never pause or that a beaten camp still sends' , function () {
2026-10-31 10:05:05 +00:00
$config = gameConfig ([ 'raids' => [ 'every_hours' => [ 0 , 5 ], 'scatter_below' => 0 , 'mode' => 'teleport' , 'dare' => - 1 ]]);
2026-10-29 15:07:54 +00:00
expect ( ConfigLint :: check ( $config ))
-> toContain ( '[raids.every_hours] must be two hours above 0, the smaller first, so a village gets time between raids.' )
2026-10-31 10:05:05 +00:00
-> toContain ( '[raids.dare] cannot be negative.' )
2026-10-29 15:07:54 +00:00
-> toContain ( '[raids.scatter_below] must be above 0 and at most 1, or beating the camp would not stop its raid.' )
-> toContain ( '[raids.mode] is not a travel mode.' );
});
2026-10-31 09:56:05 +00:00
it ( 'reports battle shares out of range' , function () {
2026-10-31 10:01:11 +00:00
$config = gameConfig ([ 'combat' => [ 'loss_threshold' => 1.0 , 'siege' => [ 'ram' => [ 'before_battle' => 1.5 ]]], 'units' => [ 'archer' => [ 'volley' => - 0.1 ]]]);
expect ( ConfigLint :: check ( $config )) -> toBe ([
'[combat.loss_threshold] must be at least 0 and below 1.' ,
'[combat.siege.ram.before_battle] must be between 0 and 1, or rams fire more than they are.' ,
'[units.archer.volley] cannot be negative.' ,
]);
2026-10-31 09:56:05 +00:00
});
2026-10-29 15:20:52 +00:00
it ( 'reports roles that share buildings or can never be reached' , function () {
$config = gameConfig ([ 'world' => [ 'village' => [ 'specialisation' => [
'min_space' => 999 ,
'roles' => [ 'military' => [ 'buildings' => [ 'barracks' , 'timber_camp' , 'castle' ]]],
]]]]);
expect ( ConfigLint :: check ( $config ))
-> toContain ( 'Role [military] counts unknown building [castle].' )
-> toContain ( '[timber_camp] counts for two roles, [resources] and [military].' )
-> toContain ( '[specialisation.min_space] is more than a village has room for.' );
});
2026-10-29 15:31:34 +00:00
it ( 'reports crown forts that would starve or stand on levels that do not exist' , function () {
$config = gameConfig ([ 'world' => [ 'season' => [
'buildings' => [ 'farm' => 2 , 'wall' => 99 ],
'garrison' => [ 'dragon' => 1 ],
]]]);
expect ( ConfigLint :: check ( $config ))
-> toContain ( 'Crown forts have [wall] at level 99, which can\'t stand.' )
-> toContain ( 'Crown forts field unknown unit [dragon].' )
-> toContain ( 'A crown fort\'s garrison eats more than its farms leave over, so it would starve.' );
});