소스 검색

fix and complete unit tests

Olivier Massot 1 년 전
부모
커밋
b6aa61d6ea

+ 2 - 2
src/Commands/CronCommand.php

@@ -232,7 +232,7 @@ class CronCommand extends Command
      * @return void
      */
     protected function configureLoggerFormatter(string | null $jobName = null): void {
-        // @phpstan-ignore-next-line
+        /** @noinspection PhpPossiblePolymorphicInvocationInspection @phpstan-ignore-next-line */
         foreach ($this->logger->getHandlers() as $handler) {
             if ($handler instanceof RotatingFileHandler) {
 
@@ -251,6 +251,6 @@ class CronCommand extends Command
      */
     protected function resetLoggerFormatter(): void
     {
-        $this->configureLoggerFormatter(null);
+        $this->configureLoggerFormatter();
     }
 }

+ 2 - 0
tests/Unit/Service/Cron/BaseCronJobTest.php

@@ -11,6 +11,8 @@ use Psr\Log\LoggerInterface;
 class TestableBaseCronJob extends BaseCronJob {
     public function getUI(): CronUIInterface { return $this->ui; }
     public function getLogger(): LoggerInterface { return $this->logger; }
+    public function preview(): void {}
+    public function execute(): void {}
 }
 
 class BaseCronJobTest extends TestCase

+ 46 - 0
tests/Unit/Service/Dolibarr/DolibarrApiServiceTest.php

@@ -40,6 +40,52 @@ class DolibarrApiServiceTest extends TestCase
         $this->assertEquals(['id' => 1], $society);
     }
 
+    /**
+     * @see DolibarrApiService::getSociety()
+     */
+    public function testGetSocietyNotExisting(): void {
+        $dolibarrApiService = $this->getMockBuilder(DolibarrApiService::class)
+            ->setConstructorArgs([$this->client])
+            ->setMethodsExcept(['getSociety'])
+            ->getMock();
+
+        $organizationId = 123;
+
+        $dolibarrApiService
+            ->expects(self::once())
+            ->method('getJsonContent')
+            ->with("thirdparties", [ "limit" => "1", "sqlfilters" => "ref_int=" . $organizationId])
+            ->willThrowException(new HttpException(404));
+
+        $society = $dolibarrApiService->getSociety($organizationId);
+
+        $this->assertEquals(null, $society);
+    }
+
+    /**
+     * @see DolibarrApiService::getSociety()
+     */
+    public function testGetSocietyWithError(): void {
+        $dolibarrApiService = $this->getMockBuilder(DolibarrApiService::class)
+            ->setConstructorArgs([$this->client])
+            ->setMethodsExcept(['getSociety'])
+            ->getMock();
+
+        $organizationId = 123;
+
+        $e = new HttpException(500);
+
+        $dolibarrApiService
+            ->expects(self::once())
+            ->method('getJsonContent')
+            ->with("thirdparties", [ "limit" => "1", "sqlfilters" => "ref_int=" . $organizationId])
+            ->willThrowException($e);
+
+        $this->expectException($e::class);
+
+        $dolibarrApiService->getSociety($organizationId);
+    }
+
     /**
      * @see DolibarrApiService::getActiveContract()
      */

+ 2 - 2
tests/Unit/Service/Dolibarr/DolibarrSyncServiceTest.php

@@ -714,8 +714,8 @@ class DolibarrSyncServiceTest extends TestCase
         $index = $dolibarrSyncService->getActiveMembersIndex();
 
         $this->assertEqualsCanonicalizing([
-            1 => [1 => [FunctionEnum::PRESIDENT], 2 => [FunctionEnum::STUDENT]],
-            2 => [3 => [FunctionEnum::PRESIDENT, FunctionEnum::TEACHER]]
+            1 => [1 => [FunctionEnum::PRESIDENT->value], 2 => [FunctionEnum::STUDENT->value]],
+            2 => [3 => [FunctionEnum::PRESIDENT->value, FunctionEnum::TEACHER->value]]
         ], $index);
     }