| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350 |
- <?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;
- use App\Service\Organization\Utils as OrganizationUtils;
- use PHPUnit\Framework\TestCase;
- use \App\Service\Network\Utils as NetworkUtils;
- class UtilsTest extends TestCase
- {
- const MEMBERSHIP_WAITING = 495; // Affiliation in progress
- const MEMBERSHIP_NOPAYMENT = 517; // Waiting paiement
- const SUBMIT_IN_PROGRESS = 540; // Affiliation in progress
- private NetworkOrganizationRepository $networkOrganizationRepositoryMock;
- private NetworkUtils $networkUtilsMock;
- private OrganizationUtils $organizationUtilsMock;
- public function getOrganizationMock(): Organization{
- $organizationMock = $this->getMockBuilder(Organization::class)->getMock();
- return $organizationMock
- ->method('getId')
- ->willReturn(1);
- }
- public function getUtilsInstance(){
- return new Utils(
- $this->networkUtilsMock,
- $this->organizationUtilsMock,
- $this->networkOrganizationRepositoryMock,
- $this->cotisationApiResourcesRepositoryMock
- );
- }
- public function setUp(): void
- {
- $this->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->getOrganizationMock();
- $this->networkOrganizationRepositoryMock
- ->expects($this->once())
- ->method('isLastParent')
- ->with($organizationMock)
- ->willReturn(true);
- $this->networkUtilsMock
- ->expects($this->once())
- ->method('isCMF')
- ->with($organizationMock)
- ->willReturn(true);
- $utils = $this->getUtilsInstance();
- $this->assertTrue($utils->isLastParentAndCMF($organizationMock));
- }
- /**
- * @see Utils::isLastParentAndCMF()
- */
- public function testIsNotLastParentAndCMF(): void
- {
- $organizationMock = $this->getOrganizationMock();
- $this->networkOrganizationRepositoryMock
- ->expects($this->once())
- ->method('isLastParent')
- ->with($organizationMock)
- ->willReturn(false);
- $this->networkUtilsMock
- ->expects($this->never())
- ->method('isCMF');
- $utils = $this->getUtilsInstance();
- $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 = $this->getUtilsInstance();
- $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 = $this->getUtilsInstance();
- $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 = $this->getUtilsInstance();
- $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 = $this->getUtilsInstance();
- $this->assertFalse($utils->isManagerAndCMF($organizationMock));
- }
- /**
- * @see Utils::isManagerAndNotLastParentAndCMF()
- */
- public function testIsManagerAndNotLastParentAndCMF(): void
- {
- $organizationMock = $this->getOrganizationMock();
- $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 = $this->getUtilsInstance();
- $this->assertTrue($utils->isManagerAndNotLastParentAndCMF($organizationMock));
- }
- /**
- * @see Utils::isManagerAndLastParentAndCMF()
- */
- public function testIsManagerAndLastParentAndCMF(): void
- {
- $organizationMock = $this->getOrganizationMock();
- $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 = $this->getUtilsInstance();
- $this->assertTrue($utils->isManagerAndLastParentAndCMF($organizationMock));
- }
- /**
- * @see Utils::getAlertState()
- */
- public function testGetAlertStateAffiliation(): void
- {
- $year = 2022;
- $organizationMock = $this->getOrganizationMock();
- $utils = $this->getUtilsInstance();
- $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->getOrganizationMock();
- $utils = $this->getUtilsInstance();
- $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->getOrganizationMock();
- $utils = $this->getUtilsInstance();
- $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->getOrganizationMock();
- $utils = $this->getUtilsInstance();
- $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 = $this->getUtilsInstance();
- $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());
- }
- }
|