public function buy(\AirplaneModel $airplaneModel, \Airline $airline, array $input) { $airplaneValidator = AirplaneValidator::make()->addContext('buy_airplane')->bindReplacement('seats_economy', ['seats_capacity' => $airplaneModel->seats_capacity]); $airlineValidator = AirlineValidator::make(array('funds' => intval($airline->funds - $airplaneModel->price)))->addContext('buy_airplane'); //Grupujemy dwa walidatory: $groupedValidator = GroupedValidator::make()->addValidator($airplaneValidator)->addValidator($airlineValidator); if ($groupedValidator->passes()) { // yay, successful validation //$billingService = new BillingService($this->airplineRepository); $billingService = App::make('Game\\Services\\BillingService'); $billingService->update($airline->id, 'airplane_purchase', $airplaneModel->price * -1); $input['last_maintenance_service'] = date('Y-m-d H:i:s'); $this->airplaneRepository->create($input); return true; } // nay, get the errors $this->errors = $groupedValidator->errors(); return false; }
public function testEnoughSeatsCapacity() { Input::replace($input = ['seats_firstclass' => 4, 'seats_business' => 10, 'seats_economy' => 120]); $airplaneValidator = AirplaneValidator::make()->addContext('buy_airplane')->bindReplacement('seats_economy', ['seats_capacity' => 180]); $this->assertArrayNotHasKey('seats_economy', $airplaneValidator->errors()->toArray()); }