Browse Source

@fixed test unitaire

raphael 3 years ago
parent
commit
8fbbf46cb9

+ 28
- 18
tests/Phoenix/Service/Comment/CommentHandlerTest.php View File

@@ -1,4 +1,5 @@
1 1
 <?php
2
+
2 3
 namespace Logipro\Phoenix\tests\Phoenix\Service\Comment;
3 4
 
4 5
 use PHPUnit\Framework\TestCase;
@@ -16,26 +17,28 @@ use Twig\Environment;
16 17
 use Doctrine\ORM\EntityManagerInterface;
17 18
 use Symfony\Component\Security\Core\Security;
18 19
 
20
+use Logipro\Phoenix\Service\Session\SessionHandler;
21
+
19 22
 class CommentHandlerTest extends TestCase
20
-{	
23
+{
21 24
 	private $comment;
22 25
 	private $session;
23 26
 	private $person;
24 27
 
25 28
 
26
-    private $entityManager;
29
+	private $entityManager;
27 30
 
28
-    public function setUp()
29
-    {
31
+	public function setUp()
32
+	{
30 33
 		$this->person = new Person();
31 34
 		$this->person->setGivenName('Laurent');
32 35
 
33
-        $this->session = new SessionOpen();
36
+		$this->session = new SessionOpen();
34 37
 		$this->session->setTitle('Test CommentHandlerTest');
35 38
 
36 39
 		$this->comment = new Comment($this->person);
37 40
 		$this->comment->setContent('Mon commentaire');
38
-		$this->comment->setSession($this->session);	
41
+		$this->comment->setSession($this->session);
39 42
 	}
40 43
 
41 44
 	/**
@@ -54,10 +57,11 @@ class CommentHandlerTest extends TestCase
54 57
 		$translator = $this->createMock(TranslatorInterface::class);
55 58
 		$templing = $this->createMock(Environment::class);
56 59
 		$security = $this->createMock(Security::class);
60
+		$sessionHandler = $this->createMock(SessionHandler::class);
57 61
 
58
-		$commentHandler = new CommentHandler($dispatcher,$entityManager,$translator,$templing,$security);
59
-		$commentHandler->sendNotificationNewComment($this->comment, $this->session, 'session');	
60
-	}		
62
+		$commentHandler = new CommentHandler($dispatcher, $entityManager, $translator, $templing, $security, $sessionHandler);
63
+		$commentHandler->sendNotificationNewComment($this->comment, $this->session, 'session');
64
+	}
61 65
 
62 66
 	/**
63 67
 	 * Test pour verifier que le mail nouveau commentaire ne soit pas envoyé si l'option notifyMailForum est à false
@@ -75,8 +79,10 @@ class CommentHandlerTest extends TestCase
75 79
 		$templing = $this->createMock(Environment::class);
76 80
 		$security = $this->createMock(Security::class);
77 81
 
78
-		$commentHandler = new CommentHandler($dispatcher,$entityManager,$translator,$templing,$security);
79
-		$commentHandler->sendNotificationNewComment($this->comment, $this->session, 'session');	
82
+		$sessionHandler = $this->createMock(SessionHandler::class);
83
+
84
+		$commentHandler = new CommentHandler($dispatcher, $entityManager, $translator, $templing, $security, $sessionHandler);
85
+		$commentHandler->sendNotificationNewComment($this->comment, $this->session, 'session');
80 86
 	}
81 87
 
82 88
 
@@ -96,9 +102,11 @@ class CommentHandlerTest extends TestCase
96 102
 		$templing = $this->createMock(Environment::class);
97 103
 		$security = $this->createMock(Security::class);
98 104
 
99
-		$commentHandler = new CommentHandler($dispatcher,$entityManager,$translator,$templing,$security);
100
-		$commentHandler->sendNotificationNewComment($this->comment, $this->session, 'session');	
101
-	}	
105
+		$sessionHandler = $this->createMock(SessionHandler::class);
106
+
107
+		$commentHandler = new CommentHandler($dispatcher, $entityManager, $translator, $templing, $security, $sessionHandler);
108
+		$commentHandler->sendNotificationNewComment($this->comment, $this->session, 'session');
109
+	}
102 110
 
103 111
 	/**
104 112
 	 * Test pour verifier que le mail nouveau commentaire ne soit pas envoyé si il n'y a pas de responsable pédagogique
@@ -116,7 +124,9 @@ class CommentHandlerTest extends TestCase
116 124
 		$templing = $this->createMock(Environment::class);
117 125
 		$security = $this->createMock(Security::class);
118 126
 
119
-		$commentHandler = new CommentHandler($dispatcher,$entityManager,$translator,$templing,$security);
120
-		$commentHandler->sendNotificationNewComment($this->comment, $this->session, 'session');	
121
-	}	
122
-}
127
+		$sessionHandler = $this->createMock(SessionHandler::class);
128
+
129
+		$commentHandler = new CommentHandler($dispatcher, $entityManager, $translator, $templing, $security, $sessionHandler);
130
+		$commentHandler->sendNotificationNewComment($this->comment, $this->session, 'session');
131
+	}
132
+}

+ 18
- 16
tests/Phoenix/Service/FormHandlerTest.php View File

@@ -1,4 +1,5 @@
1 1
 <?php
2
+
2 3
 namespace Logipro\Phoenix\tests\Phoenix\Service;
3 4
 
4 5
 use Symfony\Component\Form\Test\TypeTestCase;
@@ -12,35 +13,36 @@ use Symfony\Component\Form\FormError;
12 13
 use Logipro\Phoenix\Service\FormHandler;
13 14
 use Symfony\Component\HttpFoundation\RequestStack;
14 15
 use Symfony\Component\HttpFoundation\Request;
16
+use Symfony\Component\Form\FormFactoryInterface;
15 17
 
16 18
 class FormHandlerTest extends TypeTestCase
17 19
 {
18
-	private function generateHandler(bool $isMethod = true) : FormHandler
20
+	private function generateHandler(bool $isMethod = true): FormHandler
19 21
 	{
20 22
 		$requestStackMock = $this->createMock(RequestStack::class);
21
-		
23
+
22 24
 		$request = $this->createMock(Request::class);
23 25
 		$request->method('isMethod')->willReturn($isMethod);
24
-		
26
+
25 27
 		$requestStackMock->method('getCurrentRequest')->willReturn($request);
26
-		
28
+
27 29
 		$trnaslatorMock = $this->createMock(TranslatorInterface::class);
28
-		
29
-		return new FormHandler($requestStackMock,$trnaslatorMock);
30
+		$factoryMock = $this->createMock(FormFactoryInterface::class);
30 31
 
32
+		return new FormHandler($requestStackMock, $trnaslatorMock, $factoryMock);
31 33
 	}
32
-    public function testGetFormFieldError()
33
-    {
34
+	public function testGetFormFieldError()
35
+	{
34 36
 		$handler = $this->generateHandler();
35 37
 
36 38
 		$form = $this->factory->createBuilder(FormType::class)
37 39
 			->add('task', TextType::class)
38 40
 			->getForm();
39 41
 
40
-		$newError = new FormError('','');
42
+		$newError = new FormError('', '');
41 43
 		$taskField = $form->get('task');
42 44
 		// soumettre le formulaire sinon la validation ne se fait pas
43
-		$form->submit(array('task' => 'Fabien'),false);
45
+		$form->submit(array('task' => 'Fabien'), false);
44 46
 		$taskField->addError($newError);
45 47
 
46 48
 		$errors = $handler->getFormFieldError($form);
@@ -57,7 +59,7 @@ class FormHandlerTest extends TypeTestCase
57 59
 			$form
58 60
 		);
59 61
 	}
60
-	
62
+
61 63
 	/**
62 64
 	 * @expectedException \Exception
63 65
 	 *
@@ -68,13 +70,13 @@ class FormHandlerTest extends TypeTestCase
68 70
 		$handler = $this->generateHandler();
69 71
 
70 72
 		$form = $this->factory->createBuilder(FormType::class)
71
-		->add('task', TextType::class)
72
-		->getForm();
73
+			->add('task', TextType::class)
74
+			->getForm();
73 75
 
74
-		$newError = new FormError('','');
76
+		$newError = new FormError('', '');
75 77
 		$taskField = $form->get('task');
76 78
 		// soumettre le formulaire sinon la validation ne se fait pas
77
-		$form->submit(array('task' => 'Fabien'),false);
79
+		$form->submit(array('task' => 'Fabien'), false);
78 80
 		$taskField->addError($newError);
79 81
 
80 82
 		$handler->validForm($form);
@@ -94,4 +96,4 @@ class FormHandlerTest extends TypeTestCase
94 96
 
95 97
 		$handler->validate($form);
96 98
 	}
97
-}
99
+}

Loading…
Cancel
Save