throw new \InvalidArgumentException("Shift duration cannot be empty", 405); } if (empty($requestObject->shiftDate) === true) { throw new \InvalidArgumentException("Shift date cannot be empty", 405); } if (empty($requestObject->shiftDelete) === true) { $requestObject->shiftDelete = null; } //perform the actual put or post if ($method === "PUT") { $shift = Shift::getShiftByShiftId($pdo, $id); if ($shift === null) { throw new RuntimeException("Shift does not exist", 404); } $shift = new Shift($id, $requestObject->shiftUserId, $requestObject->shiftCrewId, $requestObject->shiftRequestId, $requestObject->shiftStartTime, $requestObject->shiftDuration, $requestObject->shiftDate, $requestObject->shiftDelete); $shift->update($pdo); $reply->message = "Shift updated OK"; } else { if ($method === "POST") { $shift = new Shift(null, $requestObject->shiftUserId, $requestObject->shiftCrewId, $requestObject->shiftRequestId, $requestObject->shiftStartTime, $requestObject->shiftDuration, $requestObject->shiftDate, $requestObject->shiftDelete); $shift->insert($pdo); $reply->message = "Shift created OK"; } } } else { if ($method === "DELETE") { verifyXsrf(); $shift = Shift::getShiftByShiftId($pdo, $id); if ($shift === null) { throw new RuntimeException("Shift does not exist", 404); }
/** *test updating a Shift that already exists * * @expectedException \PDOException **/ public function testUpdateInvalidShift() { //create a Shift with a non null shift id and watch it fail $shift = new Shift(null, $this->requestor->getUserId(), $this->crew->getCrewId(), $this->request->getRequestId(), $this->VALID_SHIFTSTARTTIME, $this->VALID_SHIFTDURATION, $this->VALID_SHIFTDATE, $this->VALID_SHIFTDELETE); $shift->update($this->getPDO()); }