public function testDelete() { $messageMapper = new MessageMapper(); $messageMapper->setId(1); $messageMapper->deleteMessage(); $this->assertEquals(new Message(), $messageMapper->selectMessage()); }
<?php $http = Rest::initProcess(); switch ($http->getMethod()) { case 'get': $messageMapper = new MessageMapper(); $messagesObject = $messageMapper->selectMessage(true); $result = true; if (is_array($messagesObject) && !is_null($messagesObject)) { foreach ($messagesObject as $messageObject) { $result = emptyObject($messageObject); } } if (!$result) { foreach ($messagesObject as $messageObject) { $messagesArray[] = extractData($messageObject); } if ($http->getHttpAccept() == 'json') { Rest::sendResponse(200, json_encode($messagesArray), 'application/json'); } else { if ($http->getHttpAccept() == 'xml') { $options = array('indent' => ' ', 'addDecl' => false, XML_SERIALIZER_OPTION_RETURN_RESULT => true, "defaultTagName" => "message"); $serializer = new XML_Serializer($options); Rest::sendResponse(200, $serializer->serialize($messagesArray), 'application/xml'); } } } else { Rest::sendResponse(204); } break; case 'post':
<?php /** * Get the HTTP method and differents data. */ $http = Rest::initProcess(); switch ($http->getMethod()) { case 'get': $message_ = new Message(); $messageMapper = new \MessageMapper(); $messageObject = $messageMapper->selectMessage(); $messageArray = extractData($messageObject); if (!empty($messageArray)) { if ($http->getHttpAccept() == 'json') { Rest::sendResponse(200, json_encode($messageArray), 'application/json'); } else { if ($http->getHttpAccept() == 'xml') { $options = array('indent' => ' ', 'addDecl' => false, "defaultTagName" => "message", XML_SERIALIZER_OPTION_RETURN_RESULT => true); $serializer = new XML_Serializer($options); Rest::sendResponse(200, $serializer->serialize($messageArray), 'application/xml'); } } } else { Rest::sendResponse(204); } break; case 'delete': $messageMapper = new \MessageMapper(); if ($messageMapper->deleteMessage()) { Rest::sendResponse(200); }