function testRegister() { $app = \Bootstrap::getApp(); $dm = $app['odm.dm']; /* @var DocumentManager $dm */ $post = new Post(); $post->setContent("content of the post"); $post->setTitle("title of the post"); $post->setAuthor("author of the post"); $post->setCreated(new \DateTime()); $dm->persist($post); $dm->flush(); $this->assertNotNull($post->getId()); $count = $dm->getRepository('Entity\\Post')->findAll()->count(); $this->assertEquals(1, $count); $dm->remove($post); $dm->flush(); }
<?php require_once '../before.php'; use Entity\Post; if (isset($_POST['submit'])) { $post = new Post(); $post->setSubject($_POST['subject']); $post->setMessage($_POST['message']); $post->setAuthor($user); $entityManager->persist($post); $entityManager->flush($post); } if (isset($_GET['search'])) { $posts = $entityManager->getRepository('Entity\\Post')->searchSubject($_GET['search']); } else { $posts = $entityManager->getRepository('Entity\\Post')->findBy(array(), array('date' => 'DESC')); } ?> <!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title>Les posts</title> </head> <body> <form method="GET" action="post.php"> <label> Rechercher <input type="text" name="search"/>