|
|
@@ -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);
|
|
|
- }
|
|
|
}
|