networkOrganizationRepositoryMock = $this ->getMockBuilder(NetworkOrganizationRepository::class) ->disableOriginalConstructor() ->getMock(); $this->networkUtilsMock = $this ->getMockBuilder(NetworkUtils::class) ->disableOriginalConstructor() ->getMock(); $this->organizationUtilsMock = $this ->getMockBuilder(OrganizationUtils::class) ->getMock(); $this->cotisationApiResourcesRepositoryMock = $this ->getMockBuilder(CotisationApiResourcesRepository::class) ->getMock(); } /** * @see Utils::isLastParentAndCMF() */ public function testIsLastParentAndCMF(): void { $organizationMock = $this->getMockBuilder(Organization::class)->getMock(); $organizationMock ->method('getId') ->willReturn(1); $this->networkOrganizationRepositoryMock ->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->networkOrganizationRepositoryMock, $this->cotisationApiResourcesRepositoryMock ); $this->assertTrue($utils->isLastParentAndCMF($organizationMock)); } /** * @see Utils::isLastParentAndCMF() */ public function testIsNotLastParentAndCMF(): void { $organizationMock = $this->getMockBuilder(Organization::class)->getMock(); $organizationMock ->method('getId') ->willReturn(1); $this->networkOrganizationRepositoryMock ->expects($this->once()) ->method('isLastParent') ->with($organizationMock) ->willReturn(false); $this->networkUtilsMock ->expects($this->never()) ->method('isCMF'); $utils = new Utils( $this->networkUtilsMock, $this->organizationUtilsMock, $this->networkOrganizationRepositoryMock, $this->cotisationApiResourcesRepositoryMock ); $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->networkOrganizationRepositoryMock, $this->cotisationApiResourcesRepositoryMock ); $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->networkOrganizationRepositoryMock, $this->cotisationApiResourcesRepositoryMock ); $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->networkOrganizationRepositoryMock, $this->cotisationApiResourcesRepositoryMock ); $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->networkOrganizationRepositoryMock, $this->cotisationApiResourcesRepositoryMock ); $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->networkOrganizationRepositoryMock ->expects($this->once()) ->method('isLastParent') ->with($organizationMock) ->willReturn(false); $this->networkUtilsMock ->expects($this->never()) ->method('isCMF'); $utils = new Utils( $this->networkUtilsMock, $this->organizationUtilsMock, $this->networkOrganizationRepositoryMock, $this->cotisationApiResourcesRepositoryMock ); $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->networkOrganizationRepositoryMock ->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->networkOrganizationRepositoryMock, $this->cotisationApiResourcesRepositoryMock ); $this->assertTrue($utils->isManagerAndLastParentAndCMF($organizationMock)); } /** * @see Utils::getAlertState() */ public function testGetAlertStateAffiliation(): void { $year = 2022; $organizationMock = $this->getMockBuilder(Organization::class)->getMock(); $organizationMock ->method('getId') ->willReturn(1); $utils = new Utils( $this->networkUtilsMock, $this->organizationUtilsMock, $this->networkOrganizationRepositoryMock, $this->cotisationApiResourcesRepositoryMock ); $this->cotisationApiResourcesRepositoryMock ->method('getAffiliationState') ->with($organizationMock->getId(), $year) ->willReturn(self::MEMBERSHIP_WAITING); $this->assertEquals(AlertStateEnum::AFFILIATION()->getValue(), $utils->getAlertState($organizationMock, $year) ); $this->cotisationApiResourcesRepositoryMock ->method('getAffiliationState') ->with($organizationMock->getId(), $year) ->willReturn(self::SUBMIT_IN_PROGRESS); $this->assertEquals(AlertStateEnum::AFFILIATION()->getValue(), $utils->getAlertState($organizationMock, $year) ); } /** * @see Utils::getAlertState() */ public function testGetAlertStateInvoice(): void { $year = 2022; $organizationMock = $this->getMockBuilder(Organization::class)->getMock(); $organizationMock ->method('getId') ->willReturn(1); $utils = new Utils( $this->networkUtilsMock, $this->organizationUtilsMock, $this->networkOrganizationRepositoryMock, $this->cotisationApiResourcesRepositoryMock ); $this->cotisationApiResourcesRepositoryMock ->method('getAffiliationState') ->with($organizationMock->getId(), $year) ->willReturn(self::MEMBERSHIP_NOPAYMENT); $this->assertEquals(AlertStateEnum::INVOICE()->getValue(), $utils->getAlertState($organizationMock, $year) ); } /** * @see Utils::getAlertState() */ public function testGetAlertStateInsurance(): void { $year = 2022; $organizationMock = $this->getMockBuilder(Organization::class)->getMock(); $organizationMock ->method('getId') ->willReturn(1); $utils = new Utils( $this->networkUtilsMock, $this->organizationUtilsMock, $this->networkOrganizationRepositoryMock, $this->cotisationApiResourcesRepositoryMock ); $this->cotisationApiResourcesRepositoryMock ->method('isInsuranceNotDone') ->with($organizationMock->getId(), $year) ->willReturn(true); $this->assertEquals(AlertStateEnum::INSURANCE()->getValue(), $utils->getAlertState($organizationMock, $year) ); } /** * @see Utils::getAlertState() */ public function testGetAlertStateAdvertisingInsurance(): void { $year = 2022; $organizationMock = $this->getMockBuilder(Organization::class)->getMock(); $organizationMock ->method('getId') ->willReturn(1); $utils = new Utils( $this->networkUtilsMock, $this->organizationUtilsMock, $this->networkOrganizationRepositoryMock, $this->cotisationApiResourcesRepositoryMock ); $this->cotisationApiResourcesRepositoryMock ->method('isNotDGVCustomer') ->with($organizationMock->getId(), $year) ->willReturn(true); $this->assertEquals(AlertStateEnum::ADVERTISINGINSURANCE()->getValue(), $utils->getAlertState($organizationMock, $year) ); } /** * @see Utils::getCurrentCotisationYear() */ public function testGetCurrentCotisationYear(): void { $utils = new Utils( $this->networkUtilsMock, $this->organizationUtilsMock, $this->networkOrganizationRepositoryMock, $this->cotisationApiResourcesRepositoryMock ); $today = new \DateTime('now'); if($today->format('m') <= 9) $this->assertEquals($today->format('Y'), $utils->getCurrentCotisationYear()); else $this->assertEquals(($today->format('Y') + 1), $utils->getCurrentCotisationYear()); } }