| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240 |
- <?php
- namespace App\Tests\Service\Cotisation;
- use App\Entity\Organization\Organization;
- use App\Repository\Organization\OrganizationRepository;
- use App\Service\Cotisation\Utils;
- use App\Service\Organization\Utils as OrganizationUtils;
- use PHPUnit\Framework\TestCase;
- use \App\Service\Network\Utils as NetworkUtils;
- class UtilsTest extends TestCase
- {
- private $organizationMock;
- private $organizationRepositoryMock;
- private $networkUtilsMock;
- private $organizationUtilsMock;
- public function setUp(): void
- {
- $this->organizationRepositoryMock =
- $this
- ->getMockBuilder(OrganizationRepository::class)
- ->disableOriginalConstructor()
- ->getMock();
- $this->networkUtilsMock =
- $this
- ->getMockBuilder(NetworkUtils::class)
- ->disableOriginalConstructor()
- ->getMock();
- $this->organizationUtilsMock =
- $this
- ->getMockBuilder(OrganizationUtils::class)
- ->getMock();
- }
- /**
- * @see Utils::isLastParentAndCMF()
- */
- public function testIsLastParentAndCMF(): void
- {
- $organizationMock = $this->getMockBuilder(Organization::class)->getMock();
- $organizationMock
- ->method('getId')
- ->willReturn(1);
- $this->organizationRepositoryMock
- ->expects($this->once())
- ->method('isLastParent')
- ->with($organizationMock)
- ->willReturn(true);
- $this->networkUtilsMock
- ->expects($this->once())
- ->method('isCMF')
- ->with($organizationMock)
- ->willReturn(true);
- $utils = new Utils($this->networkUtilsMock, $this->organizationUtilsMock, $this->organizationRepositoryMock);
- $this->assertTrue($utils->isLastParentAndCMF($organizationMock));
- }
- /**
- * @see Utils::isLastParentAndCMF()
- */
- public function testIsNotLastParentAndCMF(): void
- {
- $organizationMock = $this->getMockBuilder(Organization::class)->getMock();
- $organizationMock
- ->method('getId')
- ->willReturn(1);
- $this->organizationRepositoryMock
- ->expects($this->once())
- ->method('isLastParent')
- ->with($organizationMock)
- ->willReturn(false);
- $this->networkUtilsMock
- ->expects($this->never())
- ->method('isCMF');
- $utils = new Utils($this->networkUtilsMock, $this->organizationUtilsMock, $this->organizationRepositoryMock);
- $this->assertFalse($utils->isLastParentAndCMF($organizationMock));
- }
- /**
- * @see Utils::isStructureAndCMF()
- */
- public function testIsStructureAndCMF(): void
- {
- $organizationMock = $this->getMockBuilder(Organization::class)->getMock();
- $this->organizationUtilsMock
- ->expects($this->once())
- ->method('isStructure')
- ->with($organizationMock)
- ->willReturn(true);
- $this->networkUtilsMock
- ->expects($this->once())
- ->method('isCMF')
- ->with($organizationMock)
- ->willReturn(true);
- $utils = new Utils($this->networkUtilsMock, $this->organizationUtilsMock, $this->organizationRepositoryMock);
- $this->assertTrue($utils->isStructureAndCMF($organizationMock));
- }
- /**
- * @see Utils::isStructureAndCMF()
- */
- public function testIsNotStructureAndCMF(): void
- {
- $organizationMock = $this->getMockBuilder(Organization::class)->getMock();
- $this->organizationUtilsMock
- ->expects($this->once())
- ->method('isStructure')
- ->with($organizationMock)
- ->willReturn(false);
- $this->networkUtilsMock
- ->expects($this->never())
- ->method('isCMF');
- $utils = new Utils($this->networkUtilsMock, $this->organizationUtilsMock, $this->organizationRepositoryMock);
- $this->assertFalse($utils->isStructureAndCMF($organizationMock));
- }
- /**
- * @see Utils::isManagerAndCMF()
- */
- public function testIsManagerAndCMF(): void
- {
- $organizationMock = $this->getMockBuilder(Organization::class)->getMock();
- $this->organizationUtilsMock
- ->expects($this->once())
- ->method('isManager')
- ->with($organizationMock)
- ->willReturn(true);
- $this->networkUtilsMock
- ->expects($this->once())
- ->method('isCMF')
- ->with($organizationMock)
- ->willReturn(true);
- $utils = new Utils($this->networkUtilsMock, $this->organizationUtilsMock, $this->organizationRepositoryMock);
- $this->assertTrue($utils->isManagerAndCMF($organizationMock));
- }
- /**
- * @see Utils::isManagerAndCMF()
- */
- public function testIsNotManagerAndCMF(): void
- {
- $organizationMock = $this->getMockBuilder(Organization::class)->getMock();
- $this->organizationUtilsMock
- ->expects($this->once())
- ->method('isManager')
- ->with($organizationMock)
- ->willReturn(false);
- $this->networkUtilsMock
- ->expects($this->never())
- ->method('isCMF');
- $utils = new Utils($this->networkUtilsMock, $this->organizationUtilsMock, $this->organizationRepositoryMock);
- $this->assertFalse($utils->isManagerAndCMF($organizationMock));
- }
- /**
- * @see Utils::isManagerAndNotLastParentAndCMF()
- */
- public function testIsManagerAndNotLastParentAndCMF(): void
- {
- $organizationMock = $this->getMockBuilder(Organization::class)->getMock();
- $organizationMock
- ->method('getId')
- ->willReturn(1);
- $this->organizationUtilsMock
- ->expects($this->once())
- ->method('isManager')
- ->with($organizationMock)
- ->willReturn(true);
- $this->organizationRepositoryMock
- ->expects($this->once())
- ->method('isLastParent')
- ->with($organizationMock)
- ->willReturn(false);
- $this->networkUtilsMock
- ->expects($this->never())
- ->method('isCMF');
- $utils = new Utils($this->networkUtilsMock, $this->organizationUtilsMock, $this->organizationRepositoryMock);
- $this->assertTrue($utils->isManagerAndNotLastParentAndCMF($organizationMock));
- }
- /**
- * @see Utils::isManagerAndLastParentAndCMF()
- */
- public function testIsManagerAndLastParentAndCMF(): void
- {
- $organizationMock = $this->getMockBuilder(Organization::class)->getMock();
- $organizationMock
- ->method('getId')
- ->willReturn(1);
- $this->organizationUtilsMock
- ->expects($this->once())
- ->method('isManager')
- ->with($organizationMock)
- ->willReturn(true);
- $this->organizationRepositoryMock
- ->expects($this->once())
- ->method('isLastParent')
- ->with($organizationMock)
- ->willReturn(true);
- $this->networkUtilsMock
- ->expects($this->once())
- ->method('isCMF')
- ->willReturn(true);
- $utils = new Utils($this->networkUtilsMock, $this->organizationUtilsMock, $this->organizationRepositoryMock);
- $this->assertTrue($utils->isManagerAndLastParentAndCMF($organizationMock));
- }
- }
|