|
| 1 | +<?php |
| 2 | +/** |
| 3 | + * Copyright © Magento, Inc. All rights reserved. |
| 4 | + * See COPYING.txt for license details. |
| 5 | + */ |
| 6 | + |
| 7 | +declare(strict_types=1); |
| 8 | + |
| 9 | +namespace Magento\GiftMessage\Test\Unit\Observer; |
| 10 | + |
| 11 | +use Magento\GiftMessage\Observer\SalesEventQuoteMerge; |
| 12 | +use Magento\Framework\TestFramework\Unit\Helper\ObjectManager; |
| 13 | +use Magento\Framework\Event\Observer; |
| 14 | +use Magento\Quote\Model\Quote; |
| 15 | + |
| 16 | +/** |
| 17 | + * SalesEventQuoteMergeTest |
| 18 | + */ |
| 19 | +class SalesEventQuoteMergeTest extends \PHPUnit\Framework\TestCase |
| 20 | +{ |
| 21 | + |
| 22 | + /** |
| 23 | + * @var SalesEventQuoteMerge |
| 24 | + */ |
| 25 | + private $salesEventQuoteMerge; |
| 26 | + |
| 27 | + /** |
| 28 | + * @return void |
| 29 | + */ |
| 30 | + public function setUp(): void |
| 31 | + { |
| 32 | + $objectManger = new ObjectManager($this); |
| 33 | + $this->salesEventQuoteMerge = $objectManger->getObject(SalesEventQuoteMerge::class); |
| 34 | + } |
| 35 | + |
| 36 | + /** |
| 37 | + * @dataProvider dataProviderGiftMessageId |
| 38 | + * |
| 39 | + * @param null|int $giftMessageId |
| 40 | + * |
| 41 | + * @return void |
| 42 | + */ |
| 43 | + public function testExecute($giftMessageId): void |
| 44 | + { |
| 45 | + $sourceQuoteMock = $this->createPartialMock(Quote::class, ['getGiftMessageId']); |
| 46 | + $sourceQuoteMock->expects($this->once()) |
| 47 | + ->method('getGiftMessageId') |
| 48 | + ->willReturn($giftMessageId); |
| 49 | + |
| 50 | + $targetQuoteMock = $this->createPartialMock(Quote::class, ['setGiftMessageId']); |
| 51 | + |
| 52 | + if ($giftMessageId) { |
| 53 | + $targetQuoteMock->expects($this->once()) |
| 54 | + ->method('setGiftMessageId'); |
| 55 | + } else { |
| 56 | + $targetQuoteMock->expects($this->never()) |
| 57 | + ->method('setGiftMessageId'); |
| 58 | + } |
| 59 | + |
| 60 | + $observer = $this->createMock(Observer::class); |
| 61 | + $observer->expects($this->exactly(2)) |
| 62 | + ->method('getData') |
| 63 | + ->willReturnMap([ |
| 64 | + ['quote', null, $targetQuoteMock], |
| 65 | + ['source', null, $sourceQuoteMock] |
| 66 | + ]); |
| 67 | + |
| 68 | + $this->salesEventQuoteMerge->execute($observer); |
| 69 | + } |
| 70 | + |
| 71 | + /** |
| 72 | + * @return array |
| 73 | + */ |
| 74 | + public function dataProviderGiftMessageId(): array |
| 75 | + { |
| 76 | + return [ |
| 77 | + [null], |
| 78 | + [1] |
| 79 | + ]; |
| 80 | + } |
| 81 | +} |
0 commit comments