CommentaireTest.php 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738
  1. <?php
  2. namespace App\Tests\Entity;
  3. use App\Entity\Commentaire;
  4. use App\Entity\Film;
  5. use App\Entity\User;
  6. use PHPUnit\Framework\TestCase;
  7. class CommentaireTest extends TestCase
  8. {
  9. public function testDefault(): void
  10. {
  11. $film = new Film();
  12. $film->setTitre("Le bon, la brute et le truand");
  13. $user = new User();
  14. $user->setUsername('sangfroid');
  15. $comment = new Commentaire();
  16. $date = new \DateTime('now');
  17. $comment->setContenu('Un beau commentaire');
  18. $comment->setNote(4);
  19. $this->assertTrue( ($date->modify('-5 minute') < $comment->getDateSubmitted() && $comment->getDateSubmitted() < $date->modify('+5 minute')));
  20. $this->assertNull($comment->getId());
  21. $this->assertSame('Un beau commentaire', $comment->getContenu());
  22. $this->assertEquals(4, $comment->getNote());
  23. $comment->setDateSubmitted($date);
  24. $this->assertSame($date, $comment->getDateSubmitted());
  25. $comment->setFilm($film);
  26. $comment->setUser($user);
  27. $this->assertSame('Le bon, la brute et le truand', $comment->getFilm()->getTitre());
  28. $this->assertSame('sangfroid', $comment->getUser()->getUserIdentifier());
  29. }
  30. }