| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347 |
- <?php
- namespace App\Tests\Service\Cotisation;
- use App\Entity\Organization\Organization;
- use App\Enum\Cotisation\AlertStateEnum;
- use App\Repository\Cotisation\CotisationApiResourcesRepository;
- use App\Repository\Network\NetworkOrganizationRepository;
- use App\Service\Cotisation\Utils as CotisationUtils;
- use App\Service\Organization\Utils as OrganizationUtils;
- use PHPUnit\Framework\MockObject\MockObject;
- use PHPUnit\Framework\TestCase;
- use \App\Service\Network\Utils as NetworkUtils;
- class UtilsTest extends TestCase
- {
- private const MEMBERSHIP_WAITING = 495; // Affiliation in progress
- private const MEMBERSHIP_NOPAYMENT = 517; // Waiting paiement
- private const SUBMIT_IN_PROGRESS = 540; // Affiliation in progress
- private MockObject | NetworkOrganizationRepository $networkOrganizationRepository;
- private MockObject | NetworkUtils $networkUtils;
- private MockObject | OrganizationUtils $organizationUtils;
- private MockObject | CotisationApiResourcesRepository $cotisationApiResourcesRepository;
- public function setUp(): void
- {
- $this->networkOrganizationRepository = $this->getMockBuilder(NetworkOrganizationRepository::class)
- ->disableOriginalConstructor()
- ->getMock();
- $this->networkUtils = $this->getMockBuilder(NetworkUtils::class)->disableOriginalConstructor()->getMock();
- $this->organizationUtils = $this->getMockBuilder(OrganizationUtils::class)->getMock();
- $this->cotisationApiResourcesRepository = $this->getMockBuilder(CotisationApiResourcesRepository::class)
- ->disableOriginalConstructor()
- ->getMock();
- }
- /**
- * @see Utils::isLastParentAndCMF()
- */
- public function testIsLastParentAndCMF(): void
- {
- $cotisationUtils = $this->getMockBuilder(CotisationUtils::class)
- ->setConstructorArgs([$this->networkUtils, $this->organizationUtils, $this->networkOrganizationRepository, $this->cotisationApiResourcesRepository])
- ->setMethodsExcept(['isLastParentAndCMF'])
- ->getMock();
- $organization1 = $this->getMockBuilder(Organization::class)->getMock();
- $organization2 = $this->getMockBuilder(Organization::class)->getMock();
- $organization3 = $this->getMockBuilder(Organization::class)->getMock();
- $organization4 = $this->getMockBuilder(Organization::class)->getMock();
- $this->networkOrganizationRepository
- ->method('isLastParent')
- ->willReturnMap([
- [$organization1, true],
- [$organization2, true],
- [$organization3, false],
- [$organization4, false],
- ]);
- $this->networkUtils
- ->method('isCMF')
- ->willReturnMap([
- [$organization1, true],
- [$organization2, false],
- [$organization3, true],
- [$organization4, false],
- ]);
- $this->assertTrue($cotisationUtils->isLastParentAndCMF($organization1));
- $this->assertFalse($cotisationUtils->isLastParentAndCMF($organization2));
- $this->assertFalse($cotisationUtils->isLastParentAndCMF($organization3));
- $this->assertFalse($cotisationUtils->isLastParentAndCMF($organization4));
- }
- /**
- * @see Utils::isStructureAndCMF()
- */
- public function testIsStructureAndCMF(): void
- {
- $cotisationUtils = $this->getMockBuilder(CotisationUtils::class)
- ->setConstructorArgs([$this->networkUtils, $this->organizationUtils, $this->networkOrganizationRepository, $this->cotisationApiResourcesRepository])
- ->setMethodsExcept(['isStructureAndCMF'])
- ->getMock();
- $organization1 = $this->getMockBuilder(Organization::class)->getMock();
- $organization2 = $this->getMockBuilder(Organization::class)->getMock();
- $organization3 = $this->getMockBuilder(Organization::class)->getMock();
- $organization4 = $this->getMockBuilder(Organization::class)->getMock();
- $this->organizationUtils
- ->method('isStructure')
- ->willReturnMap([
- [$organization1, true],
- [$organization2, false],
- [$organization3, true],
- [$organization4, false],
- ]);
- $this->networkUtils
- ->method('isCMF')
- ->with($organization1)
- ->willReturnMap([
- [$organization1, true],
- [$organization2, false],
- [$organization3, false],
- [$organization4, true],
- ]);
- $this->assertTrue($cotisationUtils->isStructureAndCMF($organization1));
- $this->assertFalse($cotisationUtils->isStructureAndCMF($organization2));
- $this->assertFalse($cotisationUtils->isStructureAndCMF($organization3));
- $this->assertFalse($cotisationUtils->isStructureAndCMF($organization4));
- }
- /**
- * @see Utils::isManagerAndCMF()
- */
- public function testIsManagerAndCMF(): void
- {
- $cotisationUtils = $this->getMockBuilder(CotisationUtils::class)
- ->setConstructorArgs([$this->networkUtils, $this->organizationUtils, $this->networkOrganizationRepository, $this->cotisationApiResourcesRepository])
- ->setMethodsExcept(['isManagerAndCMF'])
- ->getMock();
- $organization1 = $this->getMockBuilder(Organization::class)->getMock();
- $organization2 = $this->getMockBuilder(Organization::class)->getMock();
- $organization3 = $this->getMockBuilder(Organization::class)->getMock();
- $organization4 = $this->getMockBuilder(Organization::class)->getMock();
- $this->organizationUtils
- ->method('isManager')
- ->willReturnMap([
- [$organization1, true],
- [$organization2, false],
- [$organization3, true],
- [$organization4, false],
- ]);
- $this->networkUtils
- ->method('isCMF')
- ->willReturnMap([
- [$organization1, true],
- [$organization2, false],
- [$organization3, false],
- [$organization4, true],
- ]);
- $this->assertTrue($cotisationUtils->isManagerAndCMF($organization1));
- $this->assertFalse($cotisationUtils->isManagerAndCMF($organization2));
- $this->assertFalse($cotisationUtils->isManagerAndCMF($organization3));
- $this->assertFalse($cotisationUtils->isManagerAndCMF($organization4));
- }
- /**
- * @see Utils::isManagerAndNotLastParentAndCMF()
- */
- public function testIsManagerAndLastParentAndCMF(): void
- {
- $cotisationUtils = $this->getMockBuilder(CotisationUtils::class)
- ->setConstructorArgs([$this->networkUtils, $this->organizationUtils, $this->networkOrganizationRepository, $this->cotisationApiResourcesRepository])
- ->setMethodsExcept(['isManagerAndLastParentAndCMF'])
- ->getMock();
- $organization1 = $this->getMockBuilder(Organization::class)->getMock();
- $organization2 = $this->getMockBuilder(Organization::class)->getMock();
- $organization3 = $this->getMockBuilder(Organization::class)->getMock();
- $organization4 = $this->getMockBuilder(Organization::class)->getMock();
- $this->organizationUtils
- ->method('isManager')
- ->willReturnMap([
- [$organization1, true],
- [$organization2, false],
- [$organization3, true],
- [$organization4, false],
- ]);
- $cotisationUtils
- ->method('isLastParentAndCMF')
- ->willReturnMap([
- [$organization1, true],
- [$organization2, false],
- [$organization3, false],
- [$organization4, true],
- ]);
- $this->assertTrue($cotisationUtils->isManagerAndLastParentAndCMF($organization1));
- $this->assertFalse($cotisationUtils->isManagerAndLastParentAndCMF($organization2));
- $this->assertFalse($cotisationUtils->isManagerAndLastParentAndCMF($organization3));
- $this->assertFalse($cotisationUtils->isManagerAndLastParentAndCMF($organization4));
- }
- /**
- * @see Utils::isManagerAndNotLastParentAndCMF()
- */
- public function testIsManagerAndNotLastParentAndCMF(): void
- {
- $cotisationUtils = $this->getMockBuilder(CotisationUtils::class)
- ->setConstructorArgs([$this->networkUtils, $this->organizationUtils, $this->networkOrganizationRepository, $this->cotisationApiResourcesRepository])
- ->setMethodsExcept(['isManagerAndNotLastParentAndCMF'])
- ->getMock();
- $organization1 = $this->getMockBuilder(Organization::class)->getMock();
- $organization2 = $this->getMockBuilder(Organization::class)->getMock();
- $organization3 = $this->getMockBuilder(Organization::class)->getMock();
- $organization4 = $this->getMockBuilder(Organization::class)->getMock();
- $this->organizationUtils
- ->method('isManager')
- ->willReturnMap([
- [$organization1, true],
- [$organization2, false],
- [$organization3, true],
- [$organization4, true],
- ]);
- $this->networkOrganizationRepository
- ->method('isLastParent')
- ->willReturnMap([
- [$organization1, false],
- [$organization2, false],
- [$organization3, true],
- [$organization4, false],
- ]);
- $this->networkUtils
- ->method('isCMF')
- ->willReturnMap([
- [$organization1, true],
- [$organization2, true],
- [$organization3, true],
- [$organization4, false],
- ]);
- $this->assertTrue($cotisationUtils->isManagerAndNotLastParentAndCMF($organization1));
- $this->assertFalse($cotisationUtils->isManagerAndNotLastParentAndCMF($organization2));
- $this->assertFalse($cotisationUtils->isManagerAndNotLastParentAndCMF($organization3));
- $this->assertFalse($cotisationUtils->isManagerAndNotLastParentAndCMF($organization4));
- }
- /**
- * @see Utils::getAlertState()
- */
- public function testGetAlertState(): void
- {
- $cotisationUtils = $this->getMockBuilder(CotisationUtils::class)
- ->setConstructorArgs([$this->networkUtils, $this->organizationUtils, $this->networkOrganizationRepository, $this->cotisationApiResourcesRepository])
- ->setMethodsExcept(['getAlertState'])
- ->getMock();
- $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->getMockBuilder(CotisationUtils::class)
- ->setConstructorArgs([$this->networkUtils, $this->organizationUtils, $this->networkOrganizationRepository, $this->cotisationApiResourcesRepository])
- ->setMethodsExcept(['getAlertState'])
- ->getMock();
- $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->getMockBuilder(CotisationUtils::class)
- ->setConstructorArgs([$this->networkUtils, $this->organizationUtils, $this->networkOrganizationRepository, $this->cotisationApiResourcesRepository])
- ->setMethodsExcept(['getAlertState'])
- ->getMock();
- $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->getMockBuilder(CotisationUtils::class)
- ->setConstructorArgs([$this->networkUtils, $this->organizationUtils, $this->networkOrganizationRepository, $this->cotisationApiResourcesRepository])
- ->setMethodsExcept(['getCurrentCotisationYear'])
- ->getMock();
- $today = new \DateTime('now');
- $expectedYear = (int)$today->format('Y');
- if($today->format('m') > 9) {
- $expectedYear++;
- }
- $this->assertEquals($expectedYear, $cotisationUtils->getCurrentCotisationYear());
- }
- }
|