public function testRemove()
 {
     $statusDataMapper = new StatusDataMapper($this->con);
     $status = new Status(null, 'Hello World!', 'Julien', new \DateTime());
     $this->assertEquals(true, $statusDataMapper->persist($status));
     $this->assertEquals(true, $statusDataMapper->remove($status));
 }
Beispiel #2
0
    $data = array('status' => $status);
    if ($request->guessBestFormat() === 'json') {
        return new JsonResponse($data);
    }
    return $app->render('status.php', $data);
});
/**
 * Add a status
 */
$app->post('/statuses', function (Request $request) use($app, $statusFinder, $statusDM) {
    $status = new Status(null, $request->getParameter('message'), $request->getParameter('authorName'), new DateTime(), $request->getUserAgent());
    $statusDM->persist($status);
    if ($request->guessBestFormat() === 'json') {
        return new JsonResponse("statuses/" . count($statusFinder->findAll()), 201);
    }
    $app->redirect('/statuses');
});
/**
 * Delete a status
 */
$app->delete('/statuses/(\\d+)', function (Request $request, $id) use($app, $statusFinder, $statusDM) {
    if (is_null($status = $statusFinder->findOneById($id))) {
        throw new HttpException(404, 'Oups! This status cannot be found :(');
    }
    $statusDM->remove($status);
    if ($request->guessBestFormat() === 'json') {
        return new JsonResponse(null, 204);
    }
    $app->redirect('/statuses');
});
return $app;