Skip to content

Commit 19b0113

Browse files
committed
MC-32697: [2.4] AbstractSimpleObjectBuilder.php throws exception when Interceptor instance comes.
1 parent 70cf0c2 commit 19b0113

File tree

2 files changed

+52
-4
lines changed

2 files changed

+52
-4
lines changed
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
declare(strict_types=1);
7+
8+
namespace Magento\Framework\Api;
9+
10+
use Magento\TestFramework\Helper\Bootstrap;
11+
12+
/**
13+
* Test of building the Data Object
14+
*/
15+
class SortOrderBuilderTest extends \PHPUnit\Framework\TestCase
16+
{
17+
/**
18+
* @var SortOrderBuilder
19+
*/
20+
private $interceptedBuilder;
21+
22+
/**
23+
* @inheritdoc
24+
*/
25+
protected function setUp()
26+
{
27+
parent::setUp();
28+
$this->interceptedBuilder = Bootstrap::getObjectManager()->get(SortOrderBuilder::class . '\Interceptor');
29+
}
30+
31+
/**
32+
* Test Builder successfully creates object when Interceptor instance is provided.
33+
*
34+
* @return void
35+
*/
36+
public function testCreate(): void
37+
{
38+
$this->assertEquals(SortOrder::class, get_class($this->interceptedBuilder->create()));
39+
}
40+
}

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

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
* Copyright © Magento, Inc. All rights reserved.
44
* See COPYING.txt for license details.
55
*/
6+
declare(strict_types=1);
7+
68
namespace Magento\Framework\Api;
79

810
/**
@@ -44,6 +46,8 @@ public function create()
4446
}
4547

4648
/**
49+
* Overwrite data in Object.
50+
*
4751
* @param string $key
4852
* @param mixed $value
4953
*
@@ -60,12 +64,16 @@ protected function _set($key, $value)
6064
*
6165
* @return string
6266
*/
63-
protected function _getDataObjectType()
67+
protected function _getDataObjectType(): string
6468
{
6569
$currentClass = get_class($this);
66-
$builderSuffix = 'Builder';
67-
$dataObjectType = substr($currentClass, 0, -strlen($builderSuffix));
68-
return $dataObjectType;
70+
$suffix = 'Builder';
71+
$interceptorSuffix = '\Interceptor';
72+
if (false !== strpos($currentClass, $interceptorSuffix, -strlen($interceptorSuffix))) {
73+
$suffix .= $interceptorSuffix;
74+
}
75+
76+
return substr($currentClass, 0, -strlen($suffix));
6977
}
7078

7179
/**

0 commit comments

Comments
 (0)