Skip to content

Commit e53b065

Browse files
committed
Optimize object fill for AbstractModel case
1 parent 6521aa3 commit e53b065

File tree

2 files changed

+65
-2
lines changed

2 files changed

+65
-2
lines changed

lib/internal/Magento/Framework/Api/DataObjectHelper.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -299,11 +299,11 @@ private function getSetters(object $dataObject): array
299299
',',
300300
strtolower(
301301
// (0) remove all not setter
302-
// (1) add _ before upper letter
302+
// (1) add _ before upper letter or digits
303303
// (2) remove set_ in start of name
304304
// (3) add name without is_ prefix
305305
preg_replace(
306-
['/(^|,)(?!set)[^,]*/S','/(.)([A-Z])/S', '/(^|,)set_/iS', '/(^|,)is_([^,]+)/is'],
306+
['/(^|,)(?!set)[^,]*/S','/(.)([A-Z]|[0-9]+)/S', '/(^|,)set_/iS', '/(^|,)is_([^,]+)/is'],
307307
['', '$1_$2', '$1', '$1$2,is_$2'],
308308
implode(',', $dataObjectMethods)
309309
)

lib/internal/Magento/Framework/Api/Test/Unit/DataObjectHelperTest.php

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@
2424
use Magento\Framework\Reflection\MethodsMap;
2525
use Magento\Framework\Reflection\TypeProcessor;
2626
use Magento\Framework\TestFramework\Unit\Helper\ObjectManager;
27+
use Magento\Sales\Api\Data\OrderPaymentInterface;
28+
use Magento\Sales\Model\Order\Payment;
2729
use PHPUnit\Framework\MockObject\MockObject;
2830
use PHPUnit\Framework\TestCase;
2931

@@ -297,6 +299,67 @@ public function testPopulateWithArrayWithCustomAttributes(): void
297299
);
298300
}
299301

302+
/**
303+
* @return void
304+
*/
305+
public function testPopulateWithArrayWithOrderPaymentAttributes(): void
306+
{
307+
$method = 'companycredit';
308+
$customerPaymentId = null;
309+
$additionalData = null;
310+
$poNumber = 'ReferenceNumber934829dek2';
311+
$cc_type = "Debit";
312+
$cc_number_enc = "393993138";
313+
$cc_last_4 = "3982";
314+
$cc_owner = "John Doe";
315+
$cc_exp_month = "05";
316+
$cc_exp_year = "24";
317+
$cc_number = '1234567890';
318+
$cc_cid = null;
319+
$cc_ss_issue = null;
320+
$cc_ss_start_month = "0";
321+
$cc_ss_start_year = "0";
322+
323+
324+
/** @var OrderPaymentInterface $orderPaymentObject */
325+
$orderPaymentObject = $this->objectManager->getObject(
326+
Payment::class,
327+
['dataObjectHelper' => $this->dataObjectHelper]
328+
);
329+
330+
$data = [
331+
'method' => $method,
332+
'customer_payment_id' => $customerPaymentId,
333+
'additionalData' => $additionalData,
334+
'additionalInformation' => [],
335+
'po_number' => $poNumber,
336+
'cc_type' => $cc_type,
337+
'cc_number_enc' => $cc_number_enc,
338+
'cc_last_4' => $cc_last_4,
339+
'cc_owner' => $cc_owner,
340+
'cc_exp_month' => $cc_exp_month,
341+
'cc_exp_year' => $cc_exp_year,
342+
'cc_number' => $cc_number,
343+
'cc_cid' => $cc_cid,
344+
'cc_ss_issue' => $cc_ss_issue,
345+
'cc_ss_start_month' => $cc_ss_start_month,
346+
'cc_ss_start_year' => $cc_ss_start_year
347+
];
348+
$this->dataObjectHelper->populateWithArray(
349+
$orderPaymentObject,
350+
$data,
351+
OrderPaymentInterface::class
352+
);
353+
$this->assertEquals($method, $orderPaymentObject->getMethod());
354+
$this->assertEquals($cc_exp_month, $orderPaymentObject->getCcExpMonth());
355+
$this->assertEquals($cc_exp_year, $orderPaymentObject->getCcExpYear());
356+
$this->assertEquals($cc_last_4, $orderPaymentObject->getCcLast4());
357+
$this->assertEquals($cc_owner, $orderPaymentObject->getCcOwner());
358+
$this->assertEquals($cc_number_enc,$orderPaymentObject->getCcNumberEnc());
359+
$this->assertEquals($poNumber, $orderPaymentObject->getPoNumber());
360+
$this->assertEquals($cc_type, $orderPaymentObject->getCcType());
361+
}
362+
300363
/**
301364
* @param array $data1
302365
* @param array $data2

0 commit comments

Comments
 (0)