Bläddra i källkod

remove obsolete put requests result validation

Olivier Massot 1 år sedan
förälder
incheckning
ef1513e024

+ 0 - 39
src/Service/Dolibarr/DolibarrSyncService.php

@@ -462,15 +462,6 @@ class DolibarrSyncService
                     throw new \RuntimeException('Operation has an inconsistent status : '.$operation->getStatus());
                 }
 
-                // If this is an update operation, validate the result
-                if ($operation instanceof UpdateOperation) {
-                    try {
-                        $this->validateResponse($response, $operation);
-                    } catch (\RuntimeException $e) {
-                        $this->logger->warning($e->getMessage());
-                    }
-                }
-
                 ++$done;
             } catch (\RuntimeException $e) {
                 $this->logger->error('Error while executing operation : '.$operation);
@@ -881,34 +872,4 @@ class DolibarrSyncService
 
         return $expectedTags;
     }
-
-    /**
-     * Post-validation of the execution of the operation.
-     * Compare the actual result to the expected one to ensure that the data was correctly updated.
-     *
-     * In the case of a validation error, throw an HttpException
-     *
-     * @throws \RuntimeException
-     */
-    protected function validateResponse(ResponseInterface $response, UpdateOperation|CreateOperation $operation): void
-    {
-        $updated = $operation->getData();
-
-        try {
-            $responseData = $response->toArray();
-        } catch (ClientExceptionInterface|DecodingExceptionInterface|RedirectionExceptionInterface|ServerExceptionInterface|TransportExceptionInterface $e) {
-            throw new \RuntimeException("Couldn't read the content of the response : ".$e);
-        }
-
-        // Sanitize to get rid of the null / empty strings transformations of the API
-        $updated = $this->sanitizeDolibarrData($updated);
-        $responseData = $this->sanitizeDolibarrData($responseData);
-
-        $diffs = $this->arrayUtils->getChanges($responseData, $updated, true);
-
-        if (!empty($diffs)) {
-            /* @noinspection JsonEncodingApiUsageInspection */
-            throw new \RuntimeException('The '.$operation->getMethod()." request had an unexpected result.\n".'Expected content: '.json_encode($updated)."\n".'Actual content  : '.json_encode($responseData));
-        }
-    }
 }

+ 1 - 75
tests/Unit/Service/Dolibarr/DolibarrSyncServiceTest.php

@@ -750,8 +750,6 @@ class DolibarrSyncServiceTest extends TestCase
         $operation1->method('getChangeLog')->willReturn(['foo']);
         $operation1->expects(self::once())->method('execute')->willReturn($response);
 
-        $dolibarrSyncService->method('validateResponse')->with($response, $operation1)->willThrowException(new \RuntimeException());
-
         $operation2 = $this->getMockBuilder(CreateOperation::class)->disableOriginalConstructor()->getMock();
         $operation2->method('getStatus')->willReturn(
             BaseRestOperation::STATUS_READY, BaseRestOperation::STATUS_ERROR, BaseRestOperation::STATUS_ERROR // An error happened
@@ -762,7 +760,7 @@ class DolibarrSyncServiceTest extends TestCase
         $operation3->method('getStatus')->willReturn(BaseRestOperation::STATUS_DONE); // Invalid status, should log a warning and not execute
         $operation3->expects(self::never())->method('execute');
 
-        $this->logger->expects(self::exactly(3))->method('warning'); // 1 warning from validateResponse on the Update Op, and 2 because of the bad status of the Create Op
+        $this->logger->expects(self::exactly(2))->method('warning'); // 2 warnings because of the bad status of the Create Op
         $this->logger->expects(self::exactly(3))->method('error'); // The exception thrown during the execution of the Delete op will log 3 errors
 
         $dolibarrSyncService->execute([$operation1, $operation2, $operation3], $progressionCallback);
@@ -1441,76 +1439,4 @@ class DolibarrSyncServiceTest extends TestCase
             []
         );
     }
-
-    /**
-     * @see DolibarrSyncService::validateResponse()
-     */
-    public function testValidateResponse(): void
-    {
-        $dolibarrSyncService = $this->getMockForMethod('validateResponse');
-
-        $response = $this->getMockBuilder(ResponseInterface::class)->getMock();
-        $response->method('toArray')->willReturn(['a' => 1]);
-
-        $operation = $this->getMockBuilder(CreateOperation::class)->disableOriginalConstructor()->getMock();
-        $operation->method('getData')->willReturn(['a' => 1]);
-
-        $dolibarrSyncService->expects(self::exactly(2))->method('sanitizeDolibarrData')->with(['a' => 1])->willReturn(['a' => 1]);
-
-        $this->arrayUtils->expects(self::once())->method('getChanges')->with(['a' => 1], ['a' => 1], true)->willReturn([]);
-
-        $dolibarrSyncService->validateResponse($response, $operation);
-    }
-
-    /**
-     * @see DolibarrSyncService::validateResponse()
-     */
-    public function testValidateResponseInvalid(): void
-    {
-        $dolibarrSyncService = $this->getMockForMethod('validateResponse');
-
-        $response = $this->getMockBuilder(ResponseInterface::class)->getMock();
-        $response->method('toArray')->willReturn(['a' => 1]);
-
-        $operation = $this->getMockBuilder(CreateOperation::class)->disableOriginalConstructor()->getMock();
-        $operation->method('getData')->willReturn(['a' => 0]);
-
-        $dolibarrSyncService->expects(self::exactly(2))
-            ->method('sanitizeDolibarrData')
-            ->willReturnMap([
-                [['a' => 1], ['a' => 1]],
-                [['a' => 0], ['a' => 0]],
-            ]);
-
-        $this->arrayUtils->expects(self::once())->method('getChanges')->with(['a' => 1], ['a' => 0], true)->willReturn(['a' => 0]);
-
-        $this->expectException(\RuntimeException::class);
-
-        $dolibarrSyncService->validateResponse($response, $operation);
-    }
-
-    /**
-     * @see DolibarrSyncService::validateResponse()
-     */
-    public function testValidateResponseRequestError(): void
-    {
-        $dolibarrSyncService = $this->getMockForMethod('validateResponse');
-
-        $response = $this->getMockBuilder(ResponseInterface::class)->getMock();
-        $response->method('getInfo')->willReturnMap([
-            ['http_code', '200'], ['url', 'http://url.com'], ['response_headers', []],
-        ]);
-        $response->method('getContent')->willReturn('');
-        $response->method('toArray')->willThrowException(new ServerException($response));
-
-        $operation = $this->getMockBuilder(CreateOperation::class)->disableOriginalConstructor()->getMock();
-        $operation->method('getData')->willReturn(['a' => 0]);
-
-        $dolibarrSyncService->expects(self::never())->method('sanitizeDolibarrData');
-        $this->arrayUtils->expects(self::never())->method('getChanges');
-
-        $this->expectException(\RuntimeException::class);
-
-        $dolibarrSyncService->validateResponse($response, $operation);
-    }
 }