$requestObject = json_decode($requestContent); //make sure all fields are present, in order to prevent database issues if (empty($requestObject->scheduleCrewId) === true) { throw new InvalidArgumentException("crew ID for this schedule cannot be empty", 405); } if (empty($requestObject->scheduleStartDate) === true) { throw new InvalidArgumentException("please input schedule start date", 405); } //perform the actual put or post if ($method === "PUT") { $schedule = Schedule::getScheduleByScheduleId($pdo, $id); if ($schedule === null) { throw new RuntimeException("Schedule does not exist", 404); } $schedule = new Schedule($id, $requestObject->scheduleCrewId, $requestObject->scheduleStartDate); $schedule->update($pdo); $reply->message = "Schedule updated OK"; } else { if ($method === "POST") { $schedule = new Schedule(null, $requestObject->scheduleCrewId, $requestObject->scheduleStartDate); $schedule->insert($pdo); $reply->message = "Schedule created OK"; } } } else { if ($method === "DELETE") { verifyXsrf(); $schedule = Schedule::getScheduleByScheduleId($pdo, $id); if ($schedule === null) { throw new RuntimeException("Schedule does not exist", 404); }
/** * test updating a Schedule that already exists * * @expectedException \PDOException **/ public function testUpdateInvalidSchedule() { // create a Schedule with a non null schedule id and watch it fail $schedule = new Schedule(null, $this->crew->getCrewId(), $this->VALID_SCHEDULESTARTDATE); $schedule->update($this->getPDO()); }