UtilsTest.php 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240
  1. <?php
  2. namespace App\Tests\Service\Cotisation;
  3. use App\Entity\Organization\Organization;
  4. use App\Repository\Organization\OrganizationRepository;
  5. use App\Service\Cotisation\Utils;
  6. use App\Service\Organization\Utils as OrganizationUtils;
  7. use PHPUnit\Framework\TestCase;
  8. use \App\Service\Network\Utils as NetworkUtils;
  9. class UtilsTest extends TestCase
  10. {
  11. private $organizationMock;
  12. private $organizationRepositoryMock;
  13. private $networkUtilsMock;
  14. private $organizationUtilsMock;
  15. public function setUp(): void
  16. {
  17. $this->organizationRepositoryMock =
  18. $this
  19. ->getMockBuilder(OrganizationRepository::class)
  20. ->disableOriginalConstructor()
  21. ->getMock();
  22. $this->networkUtilsMock =
  23. $this
  24. ->getMockBuilder(NetworkUtils::class)
  25. ->disableOriginalConstructor()
  26. ->getMock();
  27. $this->organizationUtilsMock =
  28. $this
  29. ->getMockBuilder(OrganizationUtils::class)
  30. ->getMock();
  31. }
  32. /**
  33. * @see Utils::isLastParentAndCMF()
  34. */
  35. public function testIsLastParentAndCMF(): void
  36. {
  37. $organizationMock = $this->getMockBuilder(Organization::class)->getMock();
  38. $organizationMock
  39. ->method('getId')
  40. ->willReturn(1);
  41. $this->organizationRepositoryMock
  42. ->expects($this->once())
  43. ->method('isLastParent')
  44. ->with($organizationMock)
  45. ->willReturn(true);
  46. $this->networkUtilsMock
  47. ->expects($this->once())
  48. ->method('isCMF')
  49. ->with($organizationMock)
  50. ->willReturn(true);
  51. $utils = new Utils($this->networkUtilsMock, $this->organizationUtilsMock, $this->organizationRepositoryMock);
  52. $this->assertTrue($utils->isLastParentAndCMF($organizationMock));
  53. }
  54. /**
  55. * @see Utils::isLastParentAndCMF()
  56. */
  57. public function testIsNotLastParentAndCMF(): void
  58. {
  59. $organizationMock = $this->getMockBuilder(Organization::class)->getMock();
  60. $organizationMock
  61. ->method('getId')
  62. ->willReturn(1);
  63. $this->organizationRepositoryMock
  64. ->expects($this->once())
  65. ->method('isLastParent')
  66. ->with($organizationMock)
  67. ->willReturn(false);
  68. $this->networkUtilsMock
  69. ->expects($this->never())
  70. ->method('isCMF');
  71. $utils = new Utils($this->networkUtilsMock, $this->organizationUtilsMock, $this->organizationRepositoryMock);
  72. $this->assertFalse($utils->isLastParentAndCMF($organizationMock));
  73. }
  74. /**
  75. * @see Utils::isStructureAndCMF()
  76. */
  77. public function testIsStructureAndCMF(): void
  78. {
  79. $organizationMock = $this->getMockBuilder(Organization::class)->getMock();
  80. $this->organizationUtilsMock
  81. ->expects($this->once())
  82. ->method('isStructure')
  83. ->with($organizationMock)
  84. ->willReturn(true);
  85. $this->networkUtilsMock
  86. ->expects($this->once())
  87. ->method('isCMF')
  88. ->with($organizationMock)
  89. ->willReturn(true);
  90. $utils = new Utils($this->networkUtilsMock, $this->organizationUtilsMock, $this->organizationRepositoryMock);
  91. $this->assertTrue($utils->isStructureAndCMF($organizationMock));
  92. }
  93. /**
  94. * @see Utils::isStructureAndCMF()
  95. */
  96. public function testIsNotStructureAndCMF(): void
  97. {
  98. $organizationMock = $this->getMockBuilder(Organization::class)->getMock();
  99. $this->organizationUtilsMock
  100. ->expects($this->once())
  101. ->method('isStructure')
  102. ->with($organizationMock)
  103. ->willReturn(false);
  104. $this->networkUtilsMock
  105. ->expects($this->never())
  106. ->method('isCMF');
  107. $utils = new Utils($this->networkUtilsMock, $this->organizationUtilsMock, $this->organizationRepositoryMock);
  108. $this->assertFalse($utils->isStructureAndCMF($organizationMock));
  109. }
  110. /**
  111. * @see Utils::isManagerAndCMF()
  112. */
  113. public function testIsManagerAndCMF(): void
  114. {
  115. $organizationMock = $this->getMockBuilder(Organization::class)->getMock();
  116. $this->organizationUtilsMock
  117. ->expects($this->once())
  118. ->method('isManager')
  119. ->with($organizationMock)
  120. ->willReturn(true);
  121. $this->networkUtilsMock
  122. ->expects($this->once())
  123. ->method('isCMF')
  124. ->with($organizationMock)
  125. ->willReturn(true);
  126. $utils = new Utils($this->networkUtilsMock, $this->organizationUtilsMock, $this->organizationRepositoryMock);
  127. $this->assertTrue($utils->isManagerAndCMF($organizationMock));
  128. }
  129. /**
  130. * @see Utils::isManagerAndCMF()
  131. */
  132. public function testIsNotManagerAndCMF(): void
  133. {
  134. $organizationMock = $this->getMockBuilder(Organization::class)->getMock();
  135. $this->organizationUtilsMock
  136. ->expects($this->once())
  137. ->method('isManager')
  138. ->with($organizationMock)
  139. ->willReturn(false);
  140. $this->networkUtilsMock
  141. ->expects($this->never())
  142. ->method('isCMF');
  143. $utils = new Utils($this->networkUtilsMock, $this->organizationUtilsMock, $this->organizationRepositoryMock);
  144. $this->assertFalse($utils->isManagerAndCMF($organizationMock));
  145. }
  146. /**
  147. * @see Utils::isManagerAndNotLastParentAndCMF()
  148. */
  149. public function testIsManagerAndNotLastParentAndCMF(): void
  150. {
  151. $organizationMock = $this->getMockBuilder(Organization::class)->getMock();
  152. $organizationMock
  153. ->method('getId')
  154. ->willReturn(1);
  155. $this->organizationUtilsMock
  156. ->expects($this->once())
  157. ->method('isManager')
  158. ->with($organizationMock)
  159. ->willReturn(true);
  160. $this->organizationRepositoryMock
  161. ->expects($this->once())
  162. ->method('isLastParent')
  163. ->with($organizationMock)
  164. ->willReturn(false);
  165. $this->networkUtilsMock
  166. ->expects($this->never())
  167. ->method('isCMF');
  168. $utils = new Utils($this->networkUtilsMock, $this->organizationUtilsMock, $this->organizationRepositoryMock);
  169. $this->assertTrue($utils->isManagerAndNotLastParentAndCMF($organizationMock));
  170. }
  171. /**
  172. * @see Utils::isManagerAndLastParentAndCMF()
  173. */
  174. public function testIsManagerAndLastParentAndCMF(): void
  175. {
  176. $organizationMock = $this->getMockBuilder(Organization::class)->getMock();
  177. $organizationMock
  178. ->method('getId')
  179. ->willReturn(1);
  180. $this->organizationUtilsMock
  181. ->expects($this->once())
  182. ->method('isManager')
  183. ->with($organizationMock)
  184. ->willReturn(true);
  185. $this->organizationRepositoryMock
  186. ->expects($this->once())
  187. ->method('isLastParent')
  188. ->with($organizationMock)
  189. ->willReturn(true);
  190. $this->networkUtilsMock
  191. ->expects($this->once())
  192. ->method('isCMF')
  193. ->willReturn(true);
  194. $utils = new Utils($this->networkUtilsMock, $this->organizationUtilsMock, $this->organizationRepositoryMock);
  195. $this->assertTrue($utils->isManagerAndLastParentAndCMF($organizationMock));
  196. }
  197. }