createElectricityData($date->copy()->setHour(0), 15.0), $this->createElectricityData($date->copy()->setHour(1), 16.0), ]); $gasData = collect([ $this->createGasData($date, 5.0), ]); $repository = Mockery::mock(PriceRepository::class); $repository->shouldReceive('retrieveElectricityForDate') ->once() ->with($date) ->andReturn($electricityData); $repository->shouldReceive('retrieveGasForDate') ->once() ->with($date) ->andReturn($gasData); $service = new HistoryService($repository); $result = $service->getHistoryData($date); $this->assertCount(2, $result->electricity); $this->assertCount(1, $result->gas); $this->assertEquals(15.0, $result->electricity->first()->totalPriceTaxIncluded); $this->assertEquals(5.0, $result->gas->first()->totalPriceTaxIncluded); } public function test_get_history_data_with_empty_collections(): void { $date = Carbon::today(); $repository = Mockery::mock(PriceRepository::class); $repository->shouldReceive('retrieveElectricityForDate') ->once() ->andReturn(collect()); $repository->shouldReceive('retrieveGasForDate') ->once() ->andReturn(collect()); $service = new HistoryService($repository); $result = $service->getHistoryData($date); $this->assertCount(0, $result->electricity); $this->assertCount(0, $result->gas); } private function createElectricityData(Carbon $startDate, float $price): ElectricityData { return new ElectricityData( startDate: $startDate, endDate: $startDate->copy()->addHour(), period: 'elec_hour', marketPrice: (int) ($price * 100), totalPriceTaxIncluded: $price, priceInclHandlingVat: (int) ($price * 100), priceTaxWithVat: (int) ($price * 20), pricingProfile: 'dynamic', carbonFootprintInGram: 500, sustainabilityScore: 80, startDateDatetime: $startDate, ); } private function createGasData(Carbon $startDate, float $price): GasData { return new GasData( startDate: $startDate, endDate: $startDate->copy()->addDay(), period: 'gas_day', marketPrice: (int) ($price * 100), totalPriceTaxIncluded: $price, priceInclHandlingVat: (int) ($price * 100), priceTaxWithVat: (int) ($price * 20), startDateDatetime: $startDate, ); } }