cotisationApiResourcesRepository = $this->getMockBuilder(CotisationApiResourcesRepository::class) ->disableOriginalConstructor() ->getMock(); } public function getCotisationUtilsMockFor(string $methodName) { return $this->getMockBuilder(CotisationUtils::class) ->setConstructorArgs([$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()->getValue(), $cotisationUtils->getAlertState($organization, $year) ); $this->assertEquals(AlertStateEnum::AFFILIATION()->getValue(), $cotisationUtils->getAlertState($organization, $year) ); $this->assertEquals(AlertStateEnum::INVOICE()->getValue(), $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()->getValue(), $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()->getValue(), $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() ); } }