Skip to content

Commit f9db7a0

Browse files
author
Alex Paliarush
committed
MAGETWO-90358: Auto-generate ExtensionAttributes object
1 parent 71d4da5 commit f9db7a0

File tree

4 files changed

+42
-12
lines changed

4 files changed

+42
-12
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/Test/Unit/Model/CustomOptions/CustomOptionTest.php

Lines changed: 19 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,13 @@ 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+
24+
/** @var \Magento\Catalog\Api\Data\CustomOptionExtensionInterface | \PHPUnit_Framework_MockObject_MockObject */
25+
private $extensionMock;
26+
1827
/**
1928
* @var FileProcessor | \PHPUnit_Framework_MockObject_MockObject
2029
*/
@@ -30,7 +39,7 @@ protected function setUp()
3039
->disableOriginalConstructor()
3140
->getMock();
3241

33-
$extensionAttributesFactory = $this->getMockBuilder(\Magento\Framework\Api\ExtensionAttributesFactory::class)
42+
$this->extensionAttributesFactoryMock = $this->getMockBuilder(ExtensionAttributesFactory::class)
3443
->disableOriginalConstructor()
3544
->getMock();
3645

@@ -52,10 +61,17 @@ protected function setUp()
5261
->disableOriginalConstructor()
5362
->getMock();
5463

64+
$this->extensionMock = $this->getMockBuilder(\Magento\Catalog\Api\Data\CustomOptionExtensionInterface::class)
65+
->setMethods(['getFileInfo'])
66+
->getMockForAbstractClass();
67+
68+
$this->extensionAttributesFactoryMock->expects(self::any())
69+
->method('create')->willReturn($this->extensionMock);
70+
5571
$this->model = new CustomOption(
5672
$context,
5773
$registry,
58-
$extensionAttributesFactory,
74+
$this->extensionAttributesFactoryMock,
5975
$attributeValueFactory,
6076
$this->fileProcessor,
6177
$resource,
@@ -84,14 +100,10 @@ public function testGetOptionValue()
84100

85101
public function testGetOptionValueWithFileInfo()
86102
{
87-
$customOption = $this->getMockBuilder(\Magento\Catalog\Api\Data\CustomOptionExtensionInterface::class)
88-
->setMethods(['getFileInfo'])
89-
->getMockForAbstractClass();
90-
91103
$imageContent = $this->getMockBuilder(\Magento\Framework\Api\Data\ImageContentInterface::class)
92104
->getMockForAbstractClass();
93105

94-
$customOption->expects($this->once())
106+
$this->extensionMock->expects($this->once())
95107
->method('getFileInfo')
96108
->willReturn($imageContent);
97109

@@ -112,7 +124,6 @@ public function testGetOptionValueWithFileInfo()
112124
->with($imageContent)
113125
->willReturn($imageResult);
114126

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

0 commit comments

Comments
 (0)