From ef6b2fbf2372deecbdb9cb075b575b8d79053e39 Mon Sep 17 00:00:00 2001 From: Daniil Tkachev Date: Tue, 26 Nov 2024 16:58:49 +0100 Subject: [PATCH] UNZER-523 Unzer order model inheritance chain --- src/Controller/Admin/ModuleConfiguration.php | 23 +---- src/Controller/Admin/OrderMain.php | 4 - src/Controller/DispatcherController.php | 31 ++++++- src/Model/Order.php | 29 ++---- src/Model/TmpOrder.php | 4 +- src/Service/FlexibleSerializer.php | 40 ++++---- src/Service/Payment.php | 32 ++----- tests/PhpStan/phpstan-bootstrap.php | 7 +- tests/PhpStan/phpstan.neon | 6 +- .../Controller/DispatcherControllerTest.php | 91 +++++++++++++++++-- .../Service/FlexibleSerializerOrderTest.php | 49 ++++++++-- tests/Unit/Service/FlexibleSerializerTest.php | 7 +- 12 files changed, 208 insertions(+), 115 deletions(-) diff --git a/src/Controller/Admin/ModuleConfiguration.php b/src/Controller/Admin/ModuleConfiguration.php index 9246fe4b..915c7f11 100644 --- a/src/Controller/Admin/ModuleConfiguration.php +++ b/src/Controller/Admin/ModuleConfiguration.php @@ -27,6 +27,7 @@ /** * @SuppressWarnings(PHPMD.ExcessiveClassComplexity) + * @SuppressWarnings(PHPMD.CouplingBetweenObjects) */ class ModuleConfiguration extends ModuleConfiguration_parent { @@ -193,10 +194,6 @@ public function transferApplePayPaymentProcessingData(): void } } - /** - * @throws \GuzzleHttp\Exception\GuzzleException - * @throws \OxidEsales\EshopCommunity\Core\Exception\FileException - */ public function getApplePayPaymentProcessingKeyExists(): bool { $keyId = $this->moduleSettings->getApplePayPaymentKeyId(); @@ -215,10 +212,6 @@ public function getApplePayPaymentProcessingKeyExists(): bool return false; } - /** - * @throws GuzzleException - * @throws FileException - */ public function getApplePayPaymentProcessingCertExists(): bool { $certId = $this->moduleSettings->getApplePayPaymentCertificateId(); @@ -242,11 +235,10 @@ public function getApplePayPaymentProcessingCertExists(): bool } /** - * @return void - * @throws FileException * @SuppressWarnings(PHPMD.StaticAccess) + * @throws \OxidEsales\EshopCommunity\Core\Exception\FileException */ - public function saveConfVars() + public function saveConfVars(): void { $moduleId = $this->getUnzerStringRequestEscapedParameter('oxid'); if ($moduleId === Module::MODULE_ID) { @@ -269,9 +261,6 @@ public function saveConfVars() parent::saveConfVars(); } - /** - * @throws \OxidEsales\EshopCommunity\Core\Exception\FileException - */ private function saveMerchantKey(string $systemMode): void { $errorIds = [ @@ -318,9 +307,6 @@ private function saveMerchantCert(string $systemMode): void } } - /** - * @throws \OxidEsales\EshopCommunity\Core\Exception\FileException - */ private function savePaymentKey(string $systemMode): void { $errorIds = [ @@ -343,9 +329,6 @@ private function savePaymentKey(string $systemMode): void } } - /** - * @throws \OxidEsales\EshopCommunity\Core\Exception\FileException - */ private function savePaymentCert(string $systemMode): void { $errorIds = [ diff --git a/src/Controller/Admin/OrderMain.php b/src/Controller/Admin/OrderMain.php index 5a95eeb1..90ae78f5 100644 --- a/src/Controller/Admin/OrderMain.php +++ b/src/Controller/Admin/OrderMain.php @@ -44,10 +44,6 @@ protected function onOrderSend() } } - /** - * @param Order $oOrder - * @return void - */ public function sendShipmentNotification(Order $oOrder): void { $paymentService = $this->getServiceFromContainer(PaymentService::class); diff --git a/src/Controller/DispatcherController.php b/src/Controller/DispatcherController.php index e5f1d78a..f1177b8f 100644 --- a/src/Controller/DispatcherController.php +++ b/src/Controller/DispatcherController.php @@ -177,6 +177,9 @@ private function updateOrder(Order $order, Payment $unzerPayment, string $paymen return $this->translator->translate('oscunzer_TRANSACTION_NOTHINGTODO') . $paymentId; } + /** + * @throws \Exception + */ public function finalizeTmpOrder( Payment $unzerPayment, TmpOrder $tmpOrder, @@ -184,15 +187,23 @@ public function finalizeTmpOrder( bool $bError ): string { $return = $this->returnError(); - if ($tmpOrder->load($tmpData['OXID'])) { + if ($tmpOrder->load($tmpData['oxid'])) { $flexibleSerializer = $this->getFlexibleSerializer(); - $oOrder = $flexibleSerializer->safeUnserialize($tmpData['tmporder'], [Order::class]); + + /** @var Order $oOrder */ + $oOrder = $flexibleSerializer->safeUnserialize( + $tmpData['tmporder'], + [ + Order::class + ] + ); if ($oOrder instanceof \stdClass || $oOrder === false) { $oOrder = $flexibleSerializer->restoreOrderFromStrClass($tmpData['tmporder']); } - if ($oOrder instanceof Order) { + if (!is_null($oOrder) && method_exists($oOrder, 'finalizeTmpOrder')) { + /** @var \OxidSolutionCatalysts\Unzer\Model\Order $oOrder */ $oOrder->finalizeTmpOrder($unzerPayment, $bError); $tmpOrder->assign(['status' => 'FINISHED']); $tmpOrder->save(); @@ -229,6 +240,16 @@ protected function getTransactionService(): Transaction return $this->getServiceFromContainer(Transaction::class); } + protected function returnError(): string + { + return $this->translator->translate('oscunzer_ERROR_HANDLE_TMP_ORDER'); + } + + protected function returnSuccess(): string + { + return $this->translator->translate('oscunzer_SUCCESS_HANDLE_TMP_ORDER'); + } + private function handleTmpOrder(Payment $unzerPayment): string { $tmpOrder = oxNew(TmpOrder::class); @@ -236,8 +257,8 @@ private function handleTmpOrder(Payment $unzerPayment): string $tmpData = $tmpOrder->getTmpOrderByUnzerId($orderId); if ( - isset($tmpData['OXID']) && - $tmpOrder->load($tmpData['OXID']) && + isset($tmpData['oxid']) && + $tmpOrder->load($tmpData['oxid']) && $this->hasExceededTimeLimit($tmpOrder) ) { $bError = !( diff --git a/src/Model/Order.php b/src/Model/Order.php index 813e5363..c6ee4dd8 100644 --- a/src/Model/Order.php +++ b/src/Model/Order.php @@ -272,30 +272,26 @@ public function setUnzerTransId(string $sTransId): void } /** - * @param \UnzerSDK\Resources\Payment|null $unzerPayment - * @return bool * @throws UnzerApiException * @throws Exception */ - public function initWriteTransactionToDB($unzerPayment = null): bool + public function initWriteTransactionToDB(\UnzerSDK\Resources\Payment|null $unzerPayment = null): void { /** @var string $oxpaymenttype */ $oxpaymenttype = $this->getFieldData('oxpaymenttype'); - if (strpos($oxpaymenttype, "oscunzer") !== false) { + if ($oxpaymenttype !== null && str_contains($oxpaymenttype, "oscunzer")) { $transactionService = $this->getServiceFromContainer(TransactionService::class); $unzerPayment = $unzerPayment instanceof \UnzerSDK\Resources\Payment ? $unzerPayment : $this->getServiceFromContainer(PaymentService::class)->getSessionUnzerPayment(true); - return $transactionService->writeTransactionToDB( + $transactionService->writeTransactionToDB( $this->getId(), $this->getOrderUser()->getId() ?: '', $unzerPayment ); } - - return false; } /** @@ -304,9 +300,9 @@ public function initWriteTransactionToDB($unzerPayment = null): bool public function getUnzerInvoiceNr() { /** @var int $number */ - $number = $this->getFieldData('OXINVOICENR') !== 0 ? - $this->getFieldData('OXINVOICENR') : - $this->getFieldData('OXORDERNR'); + $number = $this->getFieldData('oxinvoicenr') !== 0 ? + $this->getFieldData('oxinvoicenr') : + $this->getFieldData('oxordernr'); return $number; } @@ -334,22 +330,17 @@ public function delete($sOxId = null) return parent::delete($sOxId); } - /** - * @param string $fieldName - * @param string $value - * @param int $dataType - * @return false|void - */ - public function setFieldData($fieldName, $value, $dataType = Field::T_TEXT) + + public function setFieldData($fieldName, $value, $dataType = Field::T_TEXT): void { - return parent::setFieldData($fieldName, $value, $dataType); + parent::setFieldData($fieldName, $value, $dataType); } private function setTmpOrderStatus(string $unzerOrderId, string $status): void { $tmpOrder = oxNew(TmpOrder::class); $tmpData = $tmpOrder->getTmpOrderByUnzerId($unzerOrderId); - if ($tmpOrder->load($tmpData['OXID'])) { + if ($tmpOrder->load($tmpData['oxid'])) { $tmpOrder->assign(['status' => $status]); $tmpOrder->save(); } diff --git a/src/Model/TmpOrder.php b/src/Model/TmpOrder.php index b7082f70..364ab3bf 100644 --- a/src/Model/TmpOrder.php +++ b/src/Model/TmpOrder.php @@ -139,8 +139,8 @@ public function getTmpOrderByOxOrderId(string $oxSessionOrderId): ?CoreOrderMode $rawRes = $queryBuilder->execute(); $result = $rawRes->fetchAssociative(); - if (is_array($result) && isset($result['TMPORDER']) && is_string($result['TMPORDER'])) { - $tmpOrder = $result['TMPORDER']; + if (is_array($result) && isset($result['tmporder']) && is_string($result['tmporder'])) { + $tmpOrder = $result['tmporder']; $result = unserialize(base64_decode($tmpOrder)); if (is_array($result) && isset($result['order']) && is_object($result['order'])) { /** @var CoreOrderModel $order */ diff --git a/src/Service/FlexibleSerializer.php b/src/Service/FlexibleSerializer.php index ea40d95c..190d639d 100644 --- a/src/Service/FlexibleSerializer.php +++ b/src/Service/FlexibleSerializer.php @@ -7,10 +7,9 @@ namespace OxidSolutionCatalysts\Unzer\Service; -use Exception; use OxidEsales\Eshop\Application\Model\Order; use ReflectionClass; -use ReflectionException; +use ReflectionMethod; use stdClass; class FlexibleSerializer @@ -34,7 +33,7 @@ public function safeSerialize($object): string * @param array $allowedClasses An array of fully qualified class names that are allowed to be unserialized. * @return mixed The unserialized data. */ - public function safeUnserialize($serialized, array $allowedClasses = []) + public function safeUnserialize(string $serialized, array $allowedClasses = []) { $unserializedData = unserialize( $serialized, @@ -54,16 +53,27 @@ public function restoreOrderFromStrClass(string $serialized): ?Order $unserializedData = unserialize( $serialized, [ - 'allowed_classes' => [stdClass::class, Order::class] + 'allowed_classes' => [stdClass::class, Order ::class] ] ); + /** @var \OxidSolutionCatalysts\Unzer\Model\Order $order */ $order = $this->getOrderModel(); + /** + * @var string $value + */ foreach (get_object_vars($unserializedData) as $property => $value) { - if (property_exists($order, $property) || method_exists($order, 'setFieldData')) { + if ( + property_exists($order, $property) + || method_exists($order, 'setFieldData') + ) { + $property = str_replace("\0", '', $property); if (method_exists($order, 'setFieldData')) { - $order->setFieldData($property, $value); + $reflectionMethod = new ReflectionMethod($order, 'setFieldData'); + if ($reflectionMethod->isPublic()) { + $order->setFieldData($property, $value); + } } $order->$property = $value; } @@ -106,11 +116,6 @@ private function makeSerializable($data) } /** - * Restore unserializable data, including objects of allowed classes. - * - * @param mixed $data The data to be restored. - * @param array $allowedClasses An array of fully qualified class names that are allowed to be restored. - * @return mixed The restored data. * @SuppressWarnings(PHPMD.CyclomaticComplexity) * @SuppressWarnings(PHPMD.ElseExpression) */ @@ -125,17 +130,11 @@ private function restoreUnserializable(mixed $data, array $allowedClasses): mixe if (is_object($data) && isset($data->__class)) { $className = $data->__class; if ($this->isAllowedClass($className, $allowedClasses)) { - $reflection = new ReflectionClass($className); - $restored = $reflection->newInstanceWithoutConstructor(); + $restored = new $className(); foreach (get_object_vars($data) as $key => $value) { if ($key !== '__class') { - if ($reflection->hasProperty($key)) { - $property = $reflection->getProperty($key); - $property->setAccessible(true); - $property->setValue($restored, $this->restoreUnserializable($value, $allowedClasses)); - } else { - $restored->$key = $this->restoreUnserializable($value, $allowedClasses); - } + $key = str_replace("\0", '', $key); + $restored->$key = $this->restoreUnserializable($value, $allowedClasses); } } return $restored; @@ -146,6 +145,7 @@ private function restoreUnserializable(mixed $data, array $allowedClasses): mixe $restored = new stdClass(); foreach (get_object_vars($data) as $key => $value) { if ($key !== '__class') { + $key = str_replace("\0", '', $key); $restored->$key = $this->restoreUnserializable($value, $allowedClasses); } } diff --git a/src/Service/Payment.php b/src/Service/Payment.php index 1ca406da..9611f0ad 100644 --- a/src/Service/Payment.php +++ b/src/Service/Payment.php @@ -442,14 +442,11 @@ public function doUnzerCollect( return true; } - /** - * @param UnzerOrderModel|null $oOrder - * @param string $unzerid - * @param float $amount - * @return UnzerApiException|bool - */ - public function doUnzerAuthorizationCancel($oOrder, $unzerid, $amount) - { + public function doUnzerAuthorizationCancel( + UnzerOrderModel|null $oOrder, + string $unzerid, + float $amount + ): UnzerApiException|bool { if (!($oOrder instanceof Order)) { return false; } @@ -475,14 +472,12 @@ public function doUnzerAuthorizationCancel($oOrder, $unzerid, $amount) } /** - * @param UnzerOrderModel|null $oOrder - * @param string $sPaymentId - * @return UnzerApiException|bool - * * @SuppressWarnings(PHPMD.CyclomaticComplexity) */ - public function sendShipmentNotification($oOrder, $sPaymentId = null) - { + public function sendShipmentNotification( + ?Order $oOrder, + string $sPaymentId = null + ): Exception|bool|UnzerApiException { if (!($oOrder instanceof Order)) { return false; } @@ -545,11 +540,7 @@ public function sendShipmentNotification($oOrder, $sPaymentId = null) return $blSuccess; } - /** - * @param \UnzerSDK\Resources\Payment $unzerPayment - * @return BasePaymentType|AbstractUnzerResource The updated PaymentType object. - */ - public function setInstallmentDueDate($unzerPayment) + public function setInstallmentDueDate(UnzerPayment $unzerPayment): BasePaymentType|AbstractUnzerResource { /** @var InstallmentSecured $installment */ $installment = $unzerPayment->getPaymentType(); @@ -573,9 +564,6 @@ public function getTomorrowsTimestamp(): string return date('Y-m-d', strtotime("+1 days")); } - /** - * @return bool - */ public function isPdfSession(): bool { return (bool)Registry::getRequest()->getRequestParameter('pdfConfirm', '0'); diff --git a/tests/PhpStan/phpstan-bootstrap.php b/tests/PhpStan/phpstan-bootstrap.php index dbd89581..344b0f30 100644 --- a/tests/PhpStan/phpstan-bootstrap.php +++ b/tests/PhpStan/phpstan-bootstrap.php @@ -53,12 +53,7 @@ class_alias( class_alias( \OxidEsales\Eshop\Application\Model\Order::class, - \OxidEsales\Eshop\Application\Model\Order_parent::class, -); - -class_alias( - \OxidEsales\Eshop\Application\Model\Order::class, - \OxidEsales\Eshop\Application\Model\Order::class, + \OxidSolutionCatalysts\Unzer\Model\Order_parent::class, ); class_alias( diff --git a/tests/PhpStan/phpstan.neon b/tests/PhpStan/phpstan.neon index 71a2516c..b4d5f5b0 100644 --- a/tests/PhpStan/phpstan.neon +++ b/tests/PhpStan/phpstan.neon @@ -7,4 +7,8 @@ parameters: - ../../vendor/oxid-esales/oxideshop-ce/source/oxfunctions.php - ../../vendor/oxid-esales/oxideshop-ce/source/overridablefunctions.php ignoreErrors: - - identifier: missingType.iterableValue \ No newline at end of file + - identifier: missingType.iterableValue + + - '#Call to an undefined method OxidEsales\\Eshop\\Application\\Model\\Order::markUnzerOrderAsPaid\(\)#' + - '#Call to an undefined method OxidEsales\\Eshop\\Application\\Model\\Order::getUnzerInvoiceNr\(\)#' + - '#Call to an undefined method OxidEsales\\Eshop\\Application\\Model\\Order::setUnzerTransId\(\)#' diff --git a/tests/Unit/Controller/DispatcherControllerTest.php b/tests/Unit/Controller/DispatcherControllerTest.php index 8206b802..98fb958c 100644 --- a/tests/Unit/Controller/DispatcherControllerTest.php +++ b/tests/Unit/Controller/DispatcherControllerTest.php @@ -4,7 +4,8 @@ namespace OxidSolutionCatalysts\Unzer\Tests\Unit\Controller; -use OxidSolutionCatalysts\Unzer\Model\Order; +use OxidEsales\Eshop\Application\Model\Order; +use OxidEsales\Eshop\Application\Model\User; use OxidSolutionCatalysts\Unzer\Service\FlexibleSerializer; use OxidSolutionCatalysts\Unzer\Service\UnzerWebhooks; use PHPUnit\Framework\MockObject\MockObject; @@ -23,22 +24,81 @@ public function testFinalizeTmpOrderExecutesCorrectly() $paymentMock = $this->createMock(UnzerResourcePayment::class); - $order = \oxNew(Order::class); - $orderId = 'testOrderId'; - $order->assign(['OXID' => $orderId]); + $order = oxNew(Order::class); + $testUserId = $this->createTestUser(); + $order->assign( + [ + 'oxid' => 'testOrderId', + 'oxuserid' => $testUserId, + 'oxordernr' => '42', + 'oxpaymenttype' => 'dummy_oscunzer' + ] + ); $tmpData = [ 'oxid' => 'testTmpOrderId', - 'tmporder' => base64_encode(serialize(['order' => $order])) + 'tmporder' => serialize($order) ]; + /** @var DispatcherController $controller */ $controller = $this->getDispatcherControllerPartialMock(); - $result = $controller->finalizeTmpOrder($paymentMock, $tmpOrderMock, $tmpData, false); $this->assertEquals('success', $result); } + public function testFinalizeTmpOrderExecutesAndGetDataInside() + { + // Create a mock for TmpOrder + $tmpOrderMock = $this->createMock(TmpOrder::class); + $tmpOrderMock->method('load')->willReturn(true); + + // Create a mock for UnzerResourcePayment + $paymentMock = $this->createMock(UnzerResourcePayment::class); + + // Create a partial mock for Order, overriding initWriteTransactionToDB + $orderMock = $this->getMockBuilder(Order::class) + ->onlyMethods(['getFieldData']) + ->getMock(); + + $orderMock->method('getFieldData') + ->willReturn('dummy_oscunzer'); + + // Assign necessary fields to the order + $orderMock->assign([ + 'oxid' => 'testOrderId', + 'oxuserid' => 'testUserId', + 'oxordernr' => '42', + 'oxpaymenttype' => 'dummy_oscunzer' + ]); + + // Serialize the order + $tmpData = [ + 'oxid' => 'testTmpOrderId', + 'tmporder' => serialize($orderMock) + ]; + + // Create a partial mock for DispatcherController + $controllerMock = $this->getMockBuilder(DispatcherController::class) + ->onlyMethods(['getFlexibleSerializer', 'returnSuccess', 'returnError']) + ->getMock(); + + $controllerMock->method('getFlexibleSerializer') + ->willReturn(new FlexibleSerializer()); + + $controllerMock->method('returnSuccess') + ->willReturn('success'); + + $controllerMock->method('returnError') + ->willReturn('error'); + + // Execute the method under test + $result = $controllerMock->finalizeTmpOrder($paymentMock, $tmpOrderMock, $tmpData, false); + + // Assert the result + $this->assertEquals('success', $result); + } + public function testFinalizeTmpOrderReturnsErrorOnInvalidData() { $tmpOrderMock = $this->createMock(TmpOrder::class); @@ -48,7 +108,7 @@ public function testFinalizeTmpOrderReturnsErrorOnInvalidData() $tmpData = [ 'oxid' => 'testTmpOrderId', - 'tmporder' => base64_encode(serialize(['invalid_data' => 'value'])) + 'tmporder' => serialize(['invalid_data' => 'value']) ]; $controller = $this->getDispatcherControllerPartialMock(); @@ -84,9 +144,26 @@ private function getDispatcherControllerPartialMock(): MockObject ->willReturn('success'); $flexibleSerializer = new FlexibleSerializer(); + $controller->method('getFlexibleSerializer') ->willReturn($flexibleSerializer); return $controller; } + + private function createTestUser(): string + { + $user = \oxNew(User::class); + $user->assign( + [ + 'oxusername' => 'testUser', + 'oxpassword' => 'testPassword', + 'oxactive' => 1, + 'oxcountryid' => '8f241f11096877ac0.98748826', + ] + ); + $user->save(); + + return $user->getId(); + } } diff --git a/tests/Unit/Service/FlexibleSerializerOrderTest.php b/tests/Unit/Service/FlexibleSerializerOrderTest.php index 61c68281..0044bbaa 100644 --- a/tests/Unit/Service/FlexibleSerializerOrderTest.php +++ b/tests/Unit/Service/FlexibleSerializerOrderTest.php @@ -2,22 +2,23 @@ namespace OxidSolutionCatalysts\Unzer\Tests\Unit\Service; -use OxidSolutionCatalysts\Unzer\Model\Order; +use OxidEsales\Eshop\Application\Model\Order; +use OxidEsales\EshopCommunity\Tests\Integration\IntegrationTestCase; use OxidEsales\Eshop\Core\Field; use OxidSolutionCatalysts\Unzer\Service\FlexibleSerializer; use PHPUnit\Framework\TestCase; use stdClass; -class FlexibleSerializerOrderTest extends TestCase +class FlexibleSerializerOrderTest extends IntegrationTestCase { - private $flexibleSerializer; + private FlexibleSerializer $flexibleSerializer; - protected function setUp(): void + public function setUp(): void { $this->flexibleSerializer = new FlexibleSerializer(); } - private function createSerializedData(array $data): string + private function createSerializedData(mixed $data): string { $testData = new stdClass(); foreach ($data as $key => $value) { @@ -26,7 +27,7 @@ private function createSerializedData(array $data): string return serialize($testData); } - public function testRestoreOrderFromStrClass(): void + public function testRestoreOrderFromStdClass(): void { // Prepare test data $testData = $this->createSerializedData([ @@ -54,6 +55,42 @@ public function testRestoreOrderFromStrClass(): void $this->assertEquals('Doe', $result->getFieldData('oxbilllname')); } + public function testRestoreOrderFromOrderClass(): void + { + $order = oxNew(Order::class); + $order = [ + 'oxid' => 'testOrderId', + 'oxordernr' => '12345', + 'oxtotalordersum' => '99.99', + 'oxorderdate' => '2024-01-01 12:00:00', + 'oxbillfname' => 'John', + 'oxbilllname' => 'Doe' + ]; + + $testData = $this->createSerializedData($order); + + $flexResult = $this->flexibleSerializer->safeSerialize($order); + $flexUnserialized = (array)$this->flexibleSerializer->safeUnserialize($flexResult); + + $this->assertEquals('testOrderId', $flexUnserialized['oxid']); + $this->assertEquals('12345', $flexUnserialized['oxordernr']); + $this->assertEquals('99.99', $flexUnserialized['oxtotalordersum']); + + $result = $this->flexibleSerializer->restoreOrderFromStrClass($testData); + + // Verify result is Order instance with finalizeTmpOrder method + $this->assertInstanceOf(Order::class, $result); + $this->assertTrue(method_exists($result, 'finalizeTmpOrder'), 'Result should have finalizeTmpOrder method'); + + // Verify fields were set correctly using getFieldData + $this->assertEquals('testOrderId', $result->getFieldData('oxid')); + $this->assertEquals('12345', $result->getFieldData('oxordernr')); + $this->assertEquals('99.99', $result->getFieldData('oxtotalordersum')); + $this->assertEquals('2024-01-01 12:00:00', $result->getFieldData('oxorderdate')); + $this->assertEquals('John', $result->getFieldData('oxbillfname')); + $this->assertEquals('Doe', $result->getFieldData('oxbilllname')); + } + public function testRestoreOrderFromStrClassWithEmptyData(): void { $testData = $this->createSerializedData([]); diff --git a/tests/Unit/Service/FlexibleSerializerTest.php b/tests/Unit/Service/FlexibleSerializerTest.php index d7bfe104..8e24c3d5 100644 --- a/tests/Unit/Service/FlexibleSerializerTest.php +++ b/tests/Unit/Service/FlexibleSerializerTest.php @@ -7,15 +7,16 @@ namespace OxidSolutionCatalysts\Unzer\Tests\Unit\Service; +use OxidEsales\EshopCommunity\Tests\Integration\IntegrationTestCase; use OxidSolutionCatalysts\Unzer\Service\FlexibleSerializer; use PHPUnit\Framework\TestCase; use OxidSolutionCatalysts\Unzer\Model\Order; -class FlexibleSerializerTest extends TestCase +class FlexibleSerializerTest extends IntegrationTestCase { private FlexibleSerializer $flexibleSerializer; - protected function setUp(): void + public function setUp(): void { $this->flexibleSerializer = new FlexibleSerializer(); } @@ -50,7 +51,7 @@ public function testSafeSerializeAndUnserializeCustomObject(): void ['OxidEsales\Eshop\Application\Model\Order'] ); - $this->assertInstanceOf('OxidSolutionCatalysts\Unzer\Model\Order', $unserialized); + $this->assertInstanceOf('OxidEsales\Eshop\Application\Model\Order', $unserialized); $this->assertEquals(1, $unserialized->id); $this->assertEquals('John Doe', $unserialized->customerName); $this->assertEquals('Extra Info', $unserialized->extraField);