UtilsTest.php 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  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. public function setUp(): void
  12. {
  13. }
  14. /**
  15. * @see Utils::isLastParentAndCMF()
  16. */
  17. public function testIsLastParentAndCMF(): void
  18. {
  19. $organizationMock = $this->getMockBuilder(Organization::class)->getMock();
  20. $organizationMock
  21. ->method('getId')
  22. ->willReturn(1);
  23. $organizationRepositoryMock =
  24. $this
  25. ->getMockBuilder(OrganizationRepository::class)
  26. ->disableOriginalConstructor()
  27. ->getMock();
  28. $organizationRepositoryMock
  29. ->expects($this->once())
  30. ->method('isLastParent')
  31. ->with($organizationMock)
  32. ->willReturn(true);
  33. $networkUtilsMock =
  34. $this
  35. ->getMockBuilder(NetworkUtils::class)
  36. ->disableOriginalConstructor()
  37. ->getMock();
  38. $networkUtilsMock
  39. ->expects($this->once())
  40. ->method('isCMF')
  41. ->with($organizationMock)
  42. ->willReturn(true);
  43. $organizationUtilsMock = $this->getMockBuilder(OrganizationUtils::class)->getMock();
  44. $utils = new Utils($networkUtilsMock, $organizationUtilsMock, $organizationRepositoryMock);
  45. $this->assertTrue($utils->isLastParentAndCMF($organizationMock));
  46. }
  47. /**
  48. * @see Utils::isLastParentAndCMF()
  49. */
  50. public function testIsNotLastParentAndCMF(): void
  51. {
  52. $organizationMock = $this->getMockBuilder(Organization::class)->getMock();
  53. $organizationMock
  54. ->method('getId')
  55. ->willReturn(1);
  56. $organizationRepositoryMock =
  57. $this
  58. ->getMockBuilder(OrganizationRepository::class)
  59. ->disableOriginalConstructor()
  60. ->getMock();
  61. $organizationRepositoryMock
  62. ->expects($this->once())
  63. ->method('isLastParent')
  64. ->with($organizationMock)
  65. ->willReturn(false);
  66. $networkUtilsMock =
  67. $this
  68. ->getMockBuilder(NetworkUtils::class)
  69. ->disableOriginalConstructor()
  70. ->getMock();
  71. $networkUtilsMock
  72. ->expects($this->never())
  73. ->method('isCMF')
  74. ->with($organizationMock)
  75. ->willReturn(true);
  76. $organizationUtilsMock = $this->getMockBuilder(OrganizationUtils::class)->getMock();
  77. $utils = new Utils($networkUtilsMock, $organizationUtilsMock, $organizationRepositoryMock);
  78. $this->assertFalse($utils->isLastParentAndCMF($organizationMock));
  79. }
  80. }