networkOrganizationRepository = $this->getMockBuilder(NetworkOrganizationRepository::class) ->disableOriginalConstructor() ->getMock(); $this->networkUtils = $this->getMockBuilder(NetworkUtils::class)->disableOriginalConstructor()->getMock(); $this->organizationUtils = $this->getMockBuilder(OrganizationUtils::class)->disableOriginalConstructor()->getMock(); $this->cotisationApiResourcesRepository = $this->getMockBuilder(CotisationApiResourcesRepository::class) ->disableOriginalConstructor() ->getMock(); } public function getCotisationUtilsMockFor(string $methodName): MockObject|CotisationUtils { return $this->getMockBuilder(CotisationUtils::class) ->setConstructorArgs([$this->networkUtils, $this->organizationUtils, $this->networkOrganizationRepository, $this->cotisationApiResourcesRepository]) ->setMethodsExcept([$methodName]) ->getMock(); } /** * @see Utils::getAlertState() */ public function testGetAlertState(): void { $cotisationUtils = $this->getCotisationUtilsMockFor('getAlertState'); $organization = $this->getMockBuilder(Organization::class)->getMock(); $organization->method('getId')->willReturn(1); $year = 2022; $this->cotisationApiResourcesRepository ->method('getAffiliationState') ->with($organization->getId(), $year) ->willReturnOnConsecutiveCalls( self::MEMBERSHIP_WAITING, self::SUBMIT_IN_PROGRESS, self::MEMBERSHIP_NOPAYMENT ); $this->assertEquals(AlertStateEnum::AFFILIATION, $cotisationUtils->getAlertState($organization, $year)); $this->assertEquals(AlertStateEnum::AFFILIATION, $cotisationUtils->getAlertState($organization, $year)); $this->assertEquals(AlertStateEnum::INVOICE, $cotisationUtils->getAlertState($organization, $year)); } /** * @see Utils::getAlertState() */ public function testGetAlertStateInsurance(): void { $cotisationUtils = $this->getCotisationUtilsMockFor('getAlertState'); $year = 2022; $organization = $this->getMockBuilder(Organization::class)->getMock(); $organization->method('getId')->willReturn(1); $this->cotisationApiResourcesRepository ->method('getAffiliationState') ->with($organization->getId(), $year) ->willReturn(null); $this->cotisationApiResourcesRepository ->method('isInsuranceNotDone') ->with($organization->getId(), $year) ->willReturn(true); $this->assertEquals(AlertStateEnum::INSURANCE, $cotisationUtils->getAlertState($organization, $year)); } /** * @see Utils::getAlertState() */ public function testGetAlertStateAdvertisingInsurance(): void { $cotisationUtils = $this->getCotisationUtilsMockFor('getAlertState'); $year = 2022; $organization = $this->getMockBuilder(Organization::class)->getMock(); $organization->method('getId')->willReturn(1); $this->cotisationApiResourcesRepository ->method('getAffiliationState') ->with($organization->getId(), $year) ->willReturn(null); $this->cotisationApiResourcesRepository ->method('isNotDGVCustomer') ->with($organization->getId()) ->willReturn(true); $this->assertEquals(AlertStateEnum::ADVERTISINGINSURANCE, $cotisationUtils->getAlertState($organization, $year)); } /** * @see Utils::getCurrentCotisationYear() */ public function testGetCurrentCotisationYear(): void { $cotisationUtils = $this->getCotisationUtilsMockFor('getCurrentCotisationYear'); DatesUtils::setFakeDatetime('2022-03-01'); $this->assertEquals( 2022, $cotisationUtils->getCurrentCotisationYear() ); DatesUtils::setFakeDatetime('2022-10-01'); $this->assertEquals( 2023, $cotisationUtils->getCurrentCotisationYear() ); } }