Sfoglia il codice sorgente

Ajout de quelques tests unitaires

François Drouhard 2 anni fa
parent
commit
191fee5461

+ 4 - 0
.gitignore

@@ -23,3 +23,7 @@ yarn-error.log
 /phpunit.xml
 .phpunit.result.cache
 ###< phpunit/phpunit ###
+
+###> CodeCoverage ###
+/public/test-coverage/
+###< CodeCoverage ###

+ 0 - 16
config/packages/dev/easy_log_handler.yaml

@@ -1,16 +0,0 @@
-services:
-    EasyCorp\EasyLog\EasyLogHandler:
-        public: false
-        arguments: ['%kernel.logs_dir%/%kernel.environment%.log']
-
-#// FIXME: How to add this configuration automatically without messing up with the monolog configuration?
-#monolog:
-#    handlers:
-#        buffered:
-#            type:     buffer
-#            handler:  easylog
-#            channels: ['!event']
-#            level:    debug
-#        easylog:
-#            type: service
-#            id:   EasyCorp\EasyLog\EasyLogHandler

+ 17 - 0
config/packages/easy_log_handler.yaml

@@ -0,0 +1,17 @@
+when@dev:
+    services:
+        EasyCorp\EasyLog\EasyLogHandler:
+            public: false
+            arguments: ['%kernel.logs_dir%/%kernel.environment%.log']
+
+    #// FIXME: How to add this configuration automatically without messing up with the monolog configuration?
+    #monolog:
+    #    handlers:
+    #        buffered:
+    #            type:     buffer
+    #            handler:  easylog
+    #            channels: ['!event']
+    #            level:    debug
+    #        easylog:
+    #            type: service
+    #            id:   EasyCorp\EasyLog\EasyLogHandler

+ 38 - 0
tests/Entity/CommentaireTest.php

@@ -0,0 +1,38 @@
+<?php
+
+namespace App\Tests\Entity;
+
+use App\Entity\Commentaire;
+use App\Entity\Film;
+use App\Entity\User;
+use PHPUnit\Framework\TestCase;
+
+class CommentaireTest extends TestCase
+{
+    public function testDefault(): void
+    {
+        $film = new Film();
+        $film->setTitre("Le bon, la brute et le truand");
+        $user = new User();
+        $user->setUsername('sangfroid');
+
+        $comment = new Commentaire();
+        $date = new \DateTime('now');
+        
+        $comment->setContenu('Un beau commentaire');
+        $comment->setNote(4);
+        $this->assertTrue( ($date->modify('-5 minute') < $comment->getDateSubmitted() && $comment->getDateSubmitted() < $date->modify('+5 minute')));
+        $this->assertNull($comment->getId());
+        $this->assertSame('Un beau commentaire', $comment->getContenu());
+        $this->assertEquals(4, $comment->getNote());
+
+        $comment->setDateSubmitted($date);
+        $this->assertSame($date, $comment->getDateSubmitted());
+
+        $comment->setFilm($film);
+        $comment->setUser($user);
+
+        $this->assertSame('Le bon, la brute et le truand', $comment->getFilm()->getTitre());
+        $this->assertSame('sangfroid', $comment->getUser()->getUserIdentifier());
+    }
+}

+ 17 - 0
tests/Entity/GenreTest.php

@@ -0,0 +1,17 @@
+<?php
+
+namespace App\Tests\Entity;
+
+use App\Entity\Genre;
+use PHPUnit\Framework\TestCase;
+
+class GenreTest extends TestCase
+{
+    public function testDefault(): void
+    {
+        $genre = new Genre();
+        $genre->setName('Horreur');
+        $this->assertSame('Horreur', $genre->getName());
+        $this->assertNull($genre->getId());
+    }
+}