Parcourir la source

revise tests for Service/Cotisation/*

Olivier Massot il y a 3 ans
Parent
commit
4955b86164

+ 4 - 0
src/Enum/Cotisation/AlertStateEnum.php

@@ -7,6 +7,10 @@ use MyCLabs\Enum\Enum;
 
 /**
  * état des alertes des cotisations disponibles.
+ * @method static AFFILIATION()
+ * @method static INSURANCE()
+ * @method static INVOICE()
+ * @method static ADVERTISINGINSURANCE()
  */
 class AlertStateEnum extends Enum
 {

+ 1 - 3
src/Service/Cotisation/Utils.php

@@ -17,8 +17,6 @@ use App\Service\Network\Utils as NetworkUtils;
  */
 class Utils
 {
-    // TODO: Renommer en CotisationUtils
-
     const MEMBERSHIP_WAITING = 495; // Affiliation in progress
     const MEMBERSHIP_NOPAYMENT = 517; // Waiting paiement
     const SUBMIT_IN_PROGRESS = 540; // Affiliation in progress
@@ -84,7 +82,7 @@ class Utils
      */
     public function isManagerAndNotLastParentAndCMF(Organization $organization): bool
     {
-        return $this->organizationUtils->isManager($organization) && !$this->isLastParentAndCMF($organization);
+        return $this->organizationUtils->isManager($organization) && !$this->networkOrganizationRepository->isLastParent($organization) && $this->networkUtils->isCMF($organization);
     }
 
 

+ 15 - 10
tests/Service/Cotisation/CotisationCreatorTest.php

@@ -6,32 +6,37 @@ use App\Entity\Organization\Organization;
 use App\Repository\Organization\OrganizationRepository;
 use App\Service\Cotisation\CotisationCreator;
 use App\Service\Cotisation\Utils;
+use PHPUnit\Framework\MockObject\MockObject;
 use PHPUnit\Framework\TestCase;
 
 class CotisationCreatorTest extends TestCase
 {
-    private OrganizationRepository $organizationRepository;
-    private Utils $cotisationUtils;
-    private CotisationCreator $cotisationCreator;
+    private MockObject | OrganizationRepository $organizationRepository;
+    private MockObject | Utils $cotisationUtils;
 
     public function setUp():void
     {
         $this->organizationRepository = $this->getMockBuilder(OrganizationRepository::class)->disableOriginalConstructor()->getMock();
         $this->cotisationUtils = $this->getMockBuilder(Utils::class)->disableOriginalConstructor()->getMock();
-
-        $this->cotisationCreator = new CotisationCreator(
-            $this->organizationRepository,
-            $this->cotisationUtils
-        );
     }
 
     public function testGetCotisation() {
+        $cotisationCreator = $this->getMockBuilder(CotisationCreator::class)
+            ->setConstructorArgs([$this->organizationRepository, $this->cotisationUtils])
+            ->setMethodsExcept(['getCotisation'])
+            ->getMock();
+
         $this->cotisationUtils->expects(self::once())->method('getCurrentCotisationYear')->willReturn(2000);
+
         $organization = $this->getMockBuilder(Organization::class)->disableOriginalConstructor()->getMock();
         $this->organizationRepository->expects(self::once())->method('find')->willReturn($organization);
-        $this->cotisationUtils->expects(self::once())->method('getAlertState')->with($organization, 2000);
-        $cotisation = $this->cotisationCreator->getCotisation(1);
+
+        $this->cotisationUtils->expects(self::once())->method('getAlertState')->with($organization, 2000)->willReturn('foo');
+
+        $cotisation = $cotisationCreator->getCotisation(1);
 
         $this->assertEquals(1, $cotisation->getOrganizationId());
+        $this->assertEquals(2000, $cotisation->getCotisationYear());
+        $this->assertEquals('foo', $cotisation->getAlertState());
     }
 }

+ 225 - 233
tests/Service/Cotisation/UtilsTest.php

@@ -6,65 +6,35 @@ 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\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
 {
-    const MEMBERSHIP_WAITING = 495; // Affiliation in progress
-    const MEMBERSHIP_NOPAYMENT = 517; // Waiting paiement
-    const SUBMIT_IN_PROGRESS = 540; // Affiliation in progress
+    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 NetworkOrganizationRepository $networkOrganizationRepositoryMock;
-    private NetworkUtils $networkUtilsMock;
-    private OrganizationUtils $organizationUtilsMock;
-
-    public function getOrganizationMock(): Organization{
-        $organizationMock = $this->getMockBuilder(Organization::class)
-            ->disableOriginalConstructor()
-            ->getMock();
-        $organizationMock
-            ->method('getId')
-            ->willReturn(1);
-        return $organizationMock;
-
-    }
-
-    public function getUtilsInstance(){
-        return new Utils(
-            $this->networkUtilsMock,
-            $this->organizationUtilsMock,
-            $this->networkOrganizationRepositoryMock,
-            $this->cotisationApiResourcesRepositoryMock
-        );
-    }
+    private MockObject | NetworkOrganizationRepository $networkOrganizationRepository;
+    private MockObject | NetworkUtils $networkUtils;
+    private MockObject | OrganizationUtils $organizationUtils;
+    private MockObject | CotisationApiResourcesRepository $cotisationApiResourcesRepository;
 
     public function setUp(): void
     {
-        $this->networkOrganizationRepositoryMock =
-            $this
-                ->getMockBuilder(NetworkOrganizationRepository::class)
+        $this->networkOrganizationRepository = $this->getMockBuilder(NetworkOrganizationRepository::class)
                 ->disableOriginalConstructor()
                 ->getMock();
 
-        $this->networkUtilsMock =
-            $this
-                ->getMockBuilder(NetworkUtils::class)
-                ->disableOriginalConstructor()
-                ->getMock();
-
-        $this->organizationUtilsMock =
-            $this
-                ->getMockBuilder(OrganizationUtils::class)
-                ->getMock();
+        $this->networkUtils = $this->getMockBuilder(NetworkUtils::class)->disableOriginalConstructor()->getMock();
+        $this->organizationUtils = $this->getMockBuilder(OrganizationUtils::class)->getMock();
 
-        $this->cotisationApiResourcesRepositoryMock =
-            $this
-                ->getMockBuilder(CotisationApiResourcesRepository::class)
-                ->disableOriginalConstructor()
-                ->getMock();
+        $this->cotisationApiResourcesRepository = $this->getMockBuilder(CotisationApiResourcesRepository::class)
+            ->disableOriginalConstructor()
+            ->getMock();
     }
 
     /**
@@ -72,43 +42,38 @@ class UtilsTest extends TestCase
      */
     public function testIsLastParentAndCMF(): void
     {
-        $organizationMock = $this->getOrganizationMock();
+        $cotisationUtils = $this->getMockBuilder(CotisationUtils::class)
+            ->setConstructorArgs([$this->networkUtils, $this->organizationUtils, $this->networkOrganizationRepository, $this->cotisationApiResourcesRepository])
+            ->setMethodsExcept(['isLastParentAndCMF'])
+            ->getMock();
 
-        $this->networkOrganizationRepositoryMock
-                ->expects($this->once())
-                ->method('isLastParent')
-                ->with($organizationMock)
-                ->willReturn(true);
+        $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->networkUtilsMock
-                ->expects($this->once())
+        $this->networkOrganizationRepository
+                ->method('isLastParent')
+                ->willReturnMap([
+                    [$organization1, true],
+                    [$organization2, true],
+                    [$organization3, false],
+                    [$organization4, false],
+                ]);
+
+        $this->networkUtils
                 ->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));
+                ->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));
     }
 
     /**
@@ -116,43 +81,39 @@ class UtilsTest extends TestCase
      */
     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);
+        $cotisationUtils = $this->getMockBuilder(CotisationUtils::class)
+            ->setConstructorArgs([$this->networkUtils, $this->organizationUtils, $this->networkOrganizationRepository, $this->cotisationApiResourcesRepository])
+            ->setMethodsExcept(['isStructureAndCMF'])
+            ->getMock();
 
-        $utils = $this->getUtilsInstance();
-        $this->assertTrue($utils->isStructureAndCMF($organizationMock));
-    }
+        $organization1 = $this->getMockBuilder(Organization::class)->getMock();
+        $organization2 = $this->getMockBuilder(Organization::class)->getMock();
+        $organization3 = $this->getMockBuilder(Organization::class)->getMock();
+        $organization4 = $this->getMockBuilder(Organization::class)->getMock();
 
-    /**
-     * @see Utils::isStructureAndCMF()
-     */
-    public function testIsNotStructureAndCMF(): void
-    {
-        $organizationMock = $this->getMockBuilder(Organization::class)->getMock();
-
-        $this->organizationUtilsMock
-            ->expects($this->once())
+        $this->organizationUtils
             ->method('isStructure')
-            ->with($organizationMock)
-            ->willReturn(false);
-
-        $this->networkUtilsMock
-            ->expects($this->never())
-            ->method('isCMF');
-
-        $utils = $this->getUtilsInstance();
-        $this->assertFalse($utils->isStructureAndCMF($organizationMock));
+            ->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));
     }
 
     /**
@@ -160,43 +121,77 @@ class UtilsTest extends TestCase
      */
     public function testIsManagerAndCMF(): void
     {
-        $organizationMock = $this->getMockBuilder(Organization::class)->getMock();
+        $cotisationUtils = $this->getMockBuilder(CotisationUtils::class)
+            ->setConstructorArgs([$this->networkUtils, $this->organizationUtils, $this->networkOrganizationRepository, $this->cotisationApiResourcesRepository])
+            ->setMethodsExcept(['isManagerAndCMF'])
+            ->getMock();
 
-        $this->organizationUtilsMock
-            ->expects($this->once())
-            ->method('isManager')
-            ->with($organizationMock)
-            ->willReturn(true);
+        $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->networkUtilsMock
-            ->expects($this->once())
+        $this->organizationUtils
+            ->method('isManager')
+            ->willReturnMap([
+                [$organization1, true],
+                [$organization2, false],
+                [$organization3, true],
+                [$organization4, false],
+            ]);
+
+        $this->networkUtils
             ->method('isCMF')
-            ->with($organizationMock)
-            ->willReturn(true);
-
-        $utils = $this->getUtilsInstance();
-        $this->assertTrue($utils->isManagerAndCMF($organizationMock));
+            ->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::isManagerAndCMF()
+     * @see Utils::isManagerAndNotLastParentAndCMF()
      */
-    public function testIsNotManagerAndCMF(): void
+    public function testIsManagerAndLastParentAndCMF(): void
     {
-        $organizationMock = $this->getMockBuilder(Organization::class)->getMock();
-
-        $this->organizationUtilsMock
-            ->expects($this->once())
-            ->method('isManager')
-            ->with($organizationMock)
-            ->willReturn(false);
+        $cotisationUtils = $this->getMockBuilder(CotisationUtils::class)
+            ->setConstructorArgs([$this->networkUtils, $this->organizationUtils, $this->networkOrganizationRepository, $this->cotisationApiResourcesRepository])
+            ->setMethodsExcept(['isManagerAndLastParentAndCMF'])
+            ->getMock();
 
-        $this->networkUtilsMock
-            ->expects($this->never())
-            ->method('isCMF');
+        $organization1 = $this->getMockBuilder(Organization::class)->getMock();
+        $organization2 = $this->getMockBuilder(Organization::class)->getMock();
+        $organization3 = $this->getMockBuilder(Organization::class)->getMock();
+        $organization4 = $this->getMockBuilder(Organization::class)->getMock();
 
-        $utils = $this->getUtilsInstance();
-        $this->assertFalse($utils->isManagerAndCMF($organizationMock));
+        $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));
     }
 
     /**
@@ -204,100 +199,75 @@ class UtilsTest extends TestCase
      */
     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));
-    }
+        $cotisationUtils = $this->getMockBuilder(CotisationUtils::class)
+            ->setConstructorArgs([$this->networkUtils, $this->organizationUtils, $this->networkOrganizationRepository, $this->cotisationApiResourcesRepository])
+            ->setMethodsExcept(['isManagerAndNotLastParentAndCMF'])
+            ->getMock();
 
-    /**
-     * @see Utils::isManagerAndLastParentAndCMF()
-     */
-    public function testIsManagerAndLastParentAndCMF(): void
-    {
-        $organizationMock = $this->getOrganizationMock();
+        $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->organizationUtilsMock
-            ->expects($this->once())
+        $this->organizationUtils
             ->method('isManager')
-            ->with($organizationMock)
-            ->willReturn(true);
-
-        $this->networkOrganizationRepositoryMock
-            ->expects($this->once())
+            ->willReturnMap([
+                [$organization1, true],
+                [$organization2, false],
+                [$organization3, true],
+                [$organization4, true],
+            ]);
+
+        $this->networkOrganizationRepository
             ->method('isLastParent')
-            ->with($organizationMock)
-            ->willReturn(true);
-
-        $this->networkUtilsMock
-            ->expects($this->once())
+            ->willReturnMap([
+                [$organization1, false],
+                [$organization2, false],
+                [$organization3, true],
+                [$organization4, false],
+            ]);
+
+        $this->networkUtils
             ->method('isCMF')
-            ->willReturn(true);
-
-        $utils = $this->getUtilsInstance();
-        $this->assertTrue($utils->isManagerAndLastParentAndCMF($organizationMock));
+            ->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 testGetAlertStateAffiliation(): void
+    public function testGetAlertState(): 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) );
+        $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);
 
-    /**
-     * @see Utils::getAlertState()
-     */
-    public function testGetAlertStateInvoice(): void
-    {
         $year = 2022;
 
-        $organizationMock = $this->getOrganizationMock();
-
-        $utils = $this->getUtilsInstance();
-
-        $this->cotisationApiResourcesRepositoryMock
+        $this->cotisationApiResourcesRepository
             ->method('getAffiliationState')
-            ->with($organizationMock->getId(), $year)
-            ->willReturn(self::MEMBERSHIP_NOPAYMENT);
+            ->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) );
 
-        $this->assertEquals(AlertStateEnum::INVOICE()->getValue(), $utils->getAlertState($organizationMock, $year) );
     }
 
     /**
@@ -305,18 +275,27 @@ class UtilsTest extends TestCase
      */
     public function testGetAlertStateInsurance(): void
     {
+        $cotisationUtils = $this->getMockBuilder(CotisationUtils::class)
+            ->setConstructorArgs([$this->networkUtils, $this->organizationUtils, $this->networkOrganizationRepository, $this->cotisationApiResourcesRepository])
+            ->setMethodsExcept(['getAlertState'])
+            ->getMock();
+
         $year = 2022;
 
-        $organizationMock = $this->getOrganizationMock();
+        $organization = $this->getMockBuilder(Organization::class)->getMock();
+        $organization->method('getId')->willReturn(1);
 
-        $utils = $this->getUtilsInstance();
+        $this->cotisationApiResourcesRepository
+            ->method('getAffiliationState')
+            ->with($organization->getId(), $year)
+            ->willReturn(null);
 
-        $this->cotisationApiResourcesRepositoryMock
+        $this->cotisationApiResourcesRepository
             ->method('isInsuranceNotDone')
-            ->with($organizationMock->getId(), $year)
+            ->with($organization->getId(), $year)
             ->willReturn(true);
 
-        $this->assertEquals(AlertStateEnum::INSURANCE()->getValue(), $utils->getAlertState($organizationMock, $year) );
+        $this->assertEquals(AlertStateEnum::INSURANCE()->getValue(), $cotisationUtils->getAlertState($organization, $year) );
     }
 
     /**
@@ -324,18 +303,27 @@ class UtilsTest extends TestCase
      */
     public function testGetAlertStateAdvertisingInsurance(): void
     {
+        $cotisationUtils = $this->getMockBuilder(CotisationUtils::class)
+            ->setConstructorArgs([$this->networkUtils, $this->organizationUtils, $this->networkOrganizationRepository, $this->cotisationApiResourcesRepository])
+            ->setMethodsExcept(['getAlertState'])
+            ->getMock();
+
         $year = 2022;
 
-        $organizationMock = $this->getOrganizationMock();
+        $organization = $this->getMockBuilder(Organization::class)->getMock();
+        $organization->method('getId')->willReturn(1);
 
-        $utils = $this->getUtilsInstance();
+        $this->cotisationApiResourcesRepository
+            ->method('getAffiliationState')
+            ->with($organization->getId(), $year)
+            ->willReturn(null);
 
-        $this->cotisationApiResourcesRepositoryMock
+        $this->cotisationApiResourcesRepository
             ->method('isNotDGVCustomer')
-            ->with($organizationMock->getId())
+            ->with($organization->getId())
             ->willReturn(true);
 
-        $this->assertEquals(AlertStateEnum::ADVERTISINGINSURANCE()->getValue(), $utils->getAlertState($organizationMock, $year) );
+        $this->assertEquals(AlertStateEnum::ADVERTISINGINSURANCE()->getValue(), $cotisationUtils->getAlertState($organization, $year) );
     }
 
     /**
@@ -343,13 +331,17 @@ class UtilsTest extends TestCase
      */
     public function testGetCurrentCotisationYear(): void
     {
-        $utils = $this->getUtilsInstance();
+        $cotisationUtils = $this->getMockBuilder(CotisationUtils::class)
+            ->setConstructorArgs([$this->networkUtils, $this->organizationUtils, $this->networkOrganizationRepository, $this->cotisationApiResourcesRepository])
+            ->setMethodsExcept(['getCurrentCotisationYear'])
+            ->getMock();
 
         $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());
+        $expectedYear = (int)$today->format('Y');
+        if($today->format('m') > 9) {
+            $expectedYear++;
+        }
 
+        $this->assertEquals($expectedYear, $cotisationUtils->getCurrentCotisationYear());
     }
-}
+}