Skip to content

Commit 3d2d072

Browse files
authored
Merge pull request #2592 from magento-architects/MAGETWO-90358-Extension-Attributes
[architects] MAGETWO-90358: Auto-generate ExtensionAttributes object
2 parents 3df6681 + f9903be commit 3d2d072

36 files changed

+312
-133
lines changed

app/code/Magento/Braintree/Test/Unit/Gateway/Response/PayPal/VaultDetailsHandlerTest.php

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ protected function setUp()
8888

8989
$this->paymentInfoMock = $this->getMockBuilder(Payment::class)
9090
->disableOriginalConstructor()
91-
->setMethods(['__wakeup'])
91+
->setMethods(['__wakeup', 'getExtensionAttributes'])
9292
->getMock();
9393

9494
$this->paymentTokenMock = $objectManager->getObject(PaymentToken::class);
@@ -107,6 +107,10 @@ protected function setUp()
107107
->setMethods(['create'])
108108
->getMock();
109109

110+
$this->paymentInfoMock->expects(self::any())
111+
->method('getExtensionAttributes')
112+
->willReturn($this->paymentExtensionMock);
113+
110114
$this->subject = [
111115
'payment' => $this->paymentDataObjectMock,
112116
];
@@ -184,7 +188,7 @@ public function testHandleWithoutToken()
184188
->method('create');
185189

186190
$this->handler->handle($this->subject, $response);
187-
self::assertNull($this->paymentInfoMock->getExtensionAttributes());
191+
self::assertNotNull($this->paymentInfoMock->getExtensionAttributes());
188192
}
189193

190194
/**

app/code/Magento/Braintree/Test/Unit/Gateway/Response/VaultDetailsHandlerTest.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,9 +80,11 @@ protected function setUp()
8080

8181
$this->payment = $this->getMockBuilder(Payment::class)
8282
->disableOriginalConstructor()
83-
->setMethods(['__wakeup'])
83+
->setMethods(['__wakeup', 'getExtensionAttributes'])
8484
->getMock();
8585

86+
$this->payment->expects(self::any())->method('getExtensionAttributes')->willReturn($this->paymentExtension);
87+
8688
$config = $this->getConfigMock();
8789

8890
$this->paymentHandler = new VaultDetailsHandler(

app/code/Magento/Braintree/Test/Unit/Model/Paypal/Helper/QuoteUpdaterTest.php

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
use Magento\Braintree\Observer\DataAssignObserver;
1414
use Magento\Braintree\Gateway\Config\PayPal\Config;
1515
use Magento\Braintree\Model\Paypal\Helper\QuoteUpdater;
16+
use Magento\Quote\Api\Data\CartExtensionInterface;
1617

1718
/**
1819
* Class QuoteUpdaterTest
@@ -281,7 +282,7 @@ private function updateQuoteStep(\PHPUnit_Framework_MockObject_MockObject $quote
281282
*/
282283
private function getQuoteMock()
283284
{
284-
return $this->getMockBuilder(Quote::class)
285+
$quoteMock = $this->getMockBuilder(Quote::class)
285286
->setMethods(
286287
[
287288
'getIsVirtual',
@@ -291,9 +292,21 @@ private function getQuoteMock()
291292
'collectTotals',
292293
'getShippingAddress',
293294
'getBillingAddress',
295+
'getExtensionAttributes'
294296
]
295297
)->disableOriginalConstructor()
296298
->getMock();
299+
300+
$cartExtensionMock = $this->getMockBuilder(CartExtensionInterface::class)
301+
->setMethods(['setShippingAssignments'])
302+
->disableOriginalConstructor()
303+
->getMock();
304+
305+
$quoteMock->expects(self::any())
306+
->method('getExtensionAttributes')
307+
->willReturn($cartExtensionMock);
308+
309+
return $quoteMock;
297310
}
298311

299312
/**

app/code/Magento/Catalog/Model/Product.php

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2535,13 +2535,7 @@ public function setTypeId($typeId)
25352535
*/
25362536
public function getExtensionAttributes()
25372537
{
2538-
$extensionAttributes = $this->_getExtensionAttributes();
2539-
if (null === $extensionAttributes) {
2540-
/** @var \Magento\Catalog\Api\Data\ProductExtensionInterface $extensionAttributes */
2541-
$extensionAttributes = $this->extensionAttributesFactory->create(ProductInterface::class);
2542-
$this->setExtensionAttributes($extensionAttributes);
2543-
}
2544-
return $extensionAttributes;
2538+
return $this->_getExtensionAttributes();
25452539
}
25462540

25472541
/**

app/code/Magento/Catalog/Test/Unit/Model/CustomOptions/CustomOptionTest.php

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77

88
use Magento\Catalog\Model\CustomOptions\CustomOption;
99
use Magento\Catalog\Model\Webapi\Product\Option\Type\File\Processor as FileProcessor;
10+
use Magento\Framework\Api\ExtensionAttributesFactory;
11+
use Magento\Catalog\Api\Data\CustomOptionExtensionInterface;
1012

1113
class CustomOptionTest extends \PHPUnit\Framework\TestCase
1214
{
@@ -15,6 +17,12 @@ class CustomOptionTest extends \PHPUnit\Framework\TestCase
1517
*/
1618
protected $model;
1719

20+
/** @var \Magento\Framework\Api\ExtensionAttributesFactory | \PHPUnit_Framework_MockObject_MockObject */
21+
private $extensionAttributesFactoryMock;
22+
23+
/** @var \Magento\Catalog\Api\Data\CustomOptionExtensionInterface | \PHPUnit_Framework_MockObject_MockObject */
24+
private $extensionMock;
25+
1826
/**
1927
* @var FileProcessor | \PHPUnit_Framework_MockObject_MockObject
2028
*/
@@ -30,7 +38,7 @@ protected function setUp()
3038
->disableOriginalConstructor()
3139
->getMock();
3240

33-
$extensionAttributesFactory = $this->getMockBuilder(\Magento\Framework\Api\ExtensionAttributesFactory::class)
41+
$this->extensionAttributesFactoryMock = $this->getMockBuilder(ExtensionAttributesFactory::class)
3442
->disableOriginalConstructor()
3543
->getMock();
3644

@@ -52,10 +60,17 @@ protected function setUp()
5260
->disableOriginalConstructor()
5361
->getMock();
5462

63+
$this->extensionMock = $this->getMockBuilder(\Magento\Catalog\Api\Data\CustomOptionExtensionInterface::class)
64+
->setMethods(['getFileInfo'])
65+
->getMockForAbstractClass();
66+
67+
$this->extensionAttributesFactoryMock->expects(self::any())
68+
->method('create')->willReturn($this->extensionMock);
69+
5570
$this->model = new CustomOption(
5671
$context,
5772
$registry,
58-
$extensionAttributesFactory,
73+
$this->extensionAttributesFactoryMock,
5974
$attributeValueFactory,
6075
$this->fileProcessor,
6176
$resource,
@@ -84,14 +99,10 @@ public function testGetOptionValue()
8499

85100
public function testGetOptionValueWithFileInfo()
86101
{
87-
$customOption = $this->getMockBuilder(\Magento\Catalog\Api\Data\CustomOptionExtensionInterface::class)
88-
->setMethods(['getFileInfo'])
89-
->getMockForAbstractClass();
90-
91102
$imageContent = $this->getMockBuilder(\Magento\Framework\Api\Data\ImageContentInterface::class)
92103
->getMockForAbstractClass();
93104

94-
$customOption->expects($this->once())
105+
$this->extensionMock->expects($this->once())
95106
->method('getFileInfo')
96107
->willReturn($imageContent);
97108

@@ -112,7 +123,6 @@ public function testGetOptionValueWithFileInfo()
112123
->with($imageContent)
113124
->willReturn($imageResult);
114125

115-
$this->model->setExtensionAttributes($customOption);
116126
$this->model->setData(\Magento\Catalog\Api\Data\CustomOptionInterface::OPTION_VALUE, 'file');
117127
$this->assertEquals($imageResult, $this->model->getOptionValue());
118128
}

app/code/Magento/Checkout/Api/Data/PaymentDetailsInterface.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
* Interface PaymentDetailsInterface
1010
* @api
1111
*/
12-
interface PaymentDetailsInterface
12+
interface PaymentDetailsInterface extends \Magento\Framework\Api\ExtensibleDataInterface
1313
{
1414
/**#@+
1515
* Constants defined for keys of array, makes typos less likely
Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,9 @@
44
* Copyright © Magento, Inc. All rights reserved.
55
* See COPYING.txt for license details.
66
*/
7+
declare(strict_types=1);
78

8-
namespace Magento\Wonderland\Api\Data;
9+
namespace Magento\TestModuleExtensionAttributes\Api\Data;
910

1011
use Magento\Framework\Api\ExtensibleDataInterface;
1112

@@ -55,14 +56,14 @@ public function getCustomerId();
5556
/**
5657
* Get region
5758
*
58-
* @return \Magento\Wonderland\Api\Data\FakeRegionInterface|null
59+
* @return \Magento\TestModuleExtensionAttributes\Api\Data\FakeRegionInterface|null
5960
*/
6061
public function getRegion();
6162

6263
/**
6364
* Get region
6465
*
65-
* @return \Magento\Wonderland\Api\Data\FakeRegionInterface[]|null
66+
* @return \Magento\TestModuleExtensionAttributes\Api\Data\FakeRegionInterface[]|null
6667
*/
6768
public function getRegions();
6869

@@ -174,17 +175,17 @@ public function isDefaultBilling();
174175
/**
175176
* Retrieve existing extension attributes object or create a new one.
176177
*
177-
* @return \Magento\Wonderland\Api\Data\FakeAddressExtensionInterface|null
178+
* @return \Magento\TestModuleExtensionAttributes\Api\Data\FakeAddressExtensionInterface|null
178179
*/
179180
public function getExtensionAttributes();
180181

181182
/**
182183
* Set an extension attributes object.
183184
*
184-
* @param \Magento\Wonderland\Api\Data\FakeAddressExtensionInterface $extensionAttributes
185+
* @param \Magento\TestModuleExtensionAttributes\Api\Data\FakeAddressExtensionInterface $extensionAttributes
185186
* @return $this
186187
*/
187188
public function setExtensionAttributes(
188-
\Magento\Wonderland\Api\Data\FakeAddressExtensionInterface $extensionAttributes
189+
\Magento\TestModuleExtensionAttributes\Api\Data\FakeAddressExtensionInterface $extensionAttributes
189190
);
190191
}
Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,9 @@
33
* Copyright © Magento, Inc. All rights reserved.
44
* See COPYING.txt for license details.
55
*/
6+
declare(strict_types=1);
67

7-
namespace Magento\Wonderland\Api\Data;
8+
namespace Magento\TestModuleExtensionAttributes\Api\Data;
89

910
/**
1011
* Customer attribute metadata interface.
Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,9 @@
33
* Copyright © Magento, Inc. All rights reserved.
44
* See COPYING.txt for license details.
55
*/
6-
namespace Magento\Wonderland\Api\Data;
6+
declare(strict_types=1);
7+
8+
namespace Magento\TestModuleExtensionAttributes\Api\Data;
79

810
/**
911
* Customer interface.
@@ -98,17 +100,17 @@ public function setPrefix($prefix);
98100
/**
99101
* Retrieve existing extension attributes object or create a new one.
100102
*
101-
* @return \Magento\Wonderland\Api\Data\FakeCustomerExtensionInterface|null
103+
* @return \Magento\TestModuleExtensionAttributes\Api\Data\FakeCustomerExtensionInterface|null
102104
*/
103105
public function getExtensionAttributes();
104106

105107
/**
106108
* Set an extension attributes object.
107109
*
108-
* @param \Magento\Wonderland\Api\Data\FakeCustomerExtensionInterface $extensionAttributes
110+
* @param \Magento\TestModuleExtensionAttributes\Api\Data\FakeCustomerExtensionInterface $extensionAttributes
109111
* @return $this
110112
*/
111113
public function setExtensionAttributes(
112-
\Magento\Wonderland\Api\Data\FakeCustomerExtensionInterface $extensionAttributes
114+
\Magento\TestModuleExtensionAttributes\Api\Data\FakeCustomerExtensionInterface $extensionAttributes
113115
);
114116
}
Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,9 @@
44
* Copyright © Magento, Inc. All rights reserved.
55
* See COPYING.txt for license details.
66
*/
7+
declare(strict_types=1);
78

8-
namespace Magento\Wonderland\Api\Data;
9+
namespace Magento\TestModuleExtensionAttributes\Api\Data;
910

1011
use Magento\Framework\Api\ExtensibleDataInterface;
1112

0 commit comments

Comments
 (0)