Пример #1
0
                 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);
             }
             $schedule->delete($pdo);
             $deletedObject = new stdClass();
             $deletedObject->scheduleId = $id;
             $reply->message = "Schedule deleted OK";
         }
     }
 } else {
     //if not an admin, and attempting a method other than get, throw an exception
     if (empty($method) === false && $method !== "GET") {
         throw new RuntimeException("Only administrators are allowed to modify entries", 401);
     }
 }
 /**
  * test grabbing all Schedules
  **/
 public function testGetAllValidSchedules()
 {
     // count the number of rows and save it for later
     $numRows = $this->getConnection()->getRowCount("schedule");
     // create a new Schedule and insert to into mySQL
     $schedule = new Schedule(null, $this->crew->getCrewId(), $this->VALID_SCHEDULESTARTDATE);
     $schedule->insert($this->getPDO());
     // grab the data from mySQL and enforce the fields match our expectations
     $results = Schedule::getAllSchedules($this->getPDO());
     $this->assertEquals($numRows + 1, $this->getConnection()->getRowCount("schedule"));
     $this->assertCount(1, $results);
     $this->assertContainsOnlyInstancesOf("Edu\\Cnm\\Timecrunchers\\Schedule", $results);
     // grab the result from the array and validate it
     $pdoSchedule = $results[0];
     $this->assertEquals($pdoSchedule->getScheduleCrewId(), $this->crew->getCrewId());
     $this->assertSame($pdoSchedule->getScheduleStartDate()->format("Y:m:d"), $schedule->getScheduleStartDate()->format("Y:m:d"));
 }