*/ final class ResultTest extends TestCase { public function testGettersReturnConstructorValues(): void { $scenario = $this->makeScenario(); $bucketA = $this->makeBucket($scenario, priority: 1, name: 'Bucket A'); $bucketB = $this->makeBucket($scenario, priority: 2, name: 'Bucket B'); $allocations = [ ['bucket' => $bucketA, 'amount' => 30000], ['bucket' => $bucketB, 'amount' => 20000], ]; $result = new Result($allocations, 50000, 0); self::assertSame($allocations, $result->getAllocations()); self::assertSame(50000, $result->getTotalAllocated()); self::assertSame(0, $result->getUnallocated()); } public function testEmptyAllocationsWithZeroTotals(): void { $result = new Result([], 0, 0); self::assertSame([], $result->getAllocations()); self::assertSame(0, $result->getTotalAllocated()); self::assertSame(0, $result->getUnallocated()); } public function testTotalsAreStoredNotComputedFromAllocations(): void { $scenario = $this->makeScenario(); $bucket = $this->makeBucket($scenario, priority: 1, name: 'Bucket A'); // Deliberately inconsistent: the allocation entry says 10000, but the // constructor is told totalAllocated is 99999 and unallocated is 1. // A dumb holder returns exactly what it was given, regardless of // whether it matches the sum of $allocations. $allocations = [ ['bucket' => $bucket, 'amount' => 10000], ]; $result = new Result($allocations, 99999, 1); self::assertSame($allocations, $result->getAllocations()); self::assertSame(99999, $result->getTotalAllocated()); self::assertSame(1, $result->getUnallocated()); } private function makeScenario(): Scenario { return (new Scenario()) ->setName('Household Budget') ->setDistributionMode(DistributionMode::PRIORITY); } private function makeBucket(Scenario $scenario, int $priority, string $name): Bucket { return (new Bucket()) ->setScenario($scenario) ->setType(BucketType::NEED) ->setName($name) ->setPriority($priority) ->setAllocationType(BucketAllocationType::FIXED_LIMIT) ->setAllocationValue(50000) ->setStartingAmount(0) ->setBufferMultiplier('0.00'); } }