loader = new TravelLoader( $this->createStub(HotelLoader::class), $this->createStub(TravelParser::class), 'https://example.test', $this->createStub(CacheInterface::class), $this->createStub(FilesystemOperator::class), ); } public function testPatchesStatusAlongsideAvailability(): void { $service = $this->createService(60, Constants::STATUS_AVAILABLE, 10); $travel = $this->createTravel([$service]); $this->loader->patchAvailabilities( $travel, $this->createResponse([$this->createAvailability(60, Constants::STATUS_ON_REQUEST, 3)]) ); $this->assertSame(Constants::STATUS_ON_REQUEST, $service->status); $this->assertSame(3, $service->available); } public function testKeepsExportStatusWhenTheResponseOmitsIt(): void { $service = $this->createService(60, Constants::STATUS_AVAILABLE, 10); $travel = $this->createTravel([$service]); $this->loader->patchAvailabilities( $travel, $this->createResponse([$this->createAvailability(60, null, 3)]) ); $this->assertSame(Constants::STATUS_AVAILABLE, $service->status); $this->assertSame(3, $service->available); } public function testKeepsExportStatusWhenTheResponseCarriesABlankOne(): void { $service = $this->createService(60, Constants::STATUS_AVAILABLE, 10); $travel = $this->createTravel([$service]); $this->loader->patchAvailabilities( $travel, $this->createResponse([$this->createAvailability(60, ' ', 3)]) ); $this->assertSame(Constants::STATUS_AVAILABLE, $service->status); } public function testPatchesTransportationServicesToo(): void { $service = $this->createService(80, Constants::STATUS_AVAILABLE, 10); $travel = new Travel(); $travel->transportationServices = [80 => $service]; $this->loader->patchAvailabilities( $travel, $this->createResponse([$this->createAvailability(80, Constants::STATUS_BLOCKED, 0)]) ); $this->assertSame(Constants::STATUS_BLOCKED, $service->status); $this->assertSame(0, $service->available); } /** @param array $services */ private function createTravel(array $services): Travel { $travel = new Travel(); $indexed = []; foreach ($services as $service) { $indexed[$service->id] = $service; } $travel->additionalServices = $indexed; return $travel; } private function createService(int $id, string $status, ?int $available): Service { $service = new Service(); $service->id = $id; $service->status = $status; $service->available = $available; return $service; } private function createAvailability(int $serviceId, ?string $status, ?int $available): Availability { $availability = new Availability(); $availability->serviceId = $serviceId; $availability->status = $status; $availability->available = $available; return $availability; } /** @param array $availabilities */ private function createResponse(array $availabilities): ServiceAvailabilityResponse { $indexed = []; foreach ($availabilities as $availability) { $indexed[$availability->serviceId] = $availability; } return new ServiceAvailabilityResponse($indexed); } }