Skip to content

Commit 3a0a30f

Browse files
authored
ENGCOM-7779: Implement ActionInterface for wishlist/shared #27494
2 parents df3b84f + f9ad1c8 commit 3a0a30f

File tree

4 files changed

+137
-154
lines changed

4 files changed

+137
-154
lines changed

app/code/Magento/Wishlist/Controller/Shared/Allcart.php

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,21 +3,32 @@
33
* Copyright © Magento, Inc. All rights reserved.
44
* See COPYING.txt for license details.
55
*/
6+
7+
declare(strict_types=1);
8+
69
namespace Magento\Wishlist\Controller\Shared;
710

11+
use Magento\Framework\App\Action\Action;
812
use Magento\Framework\App\Action\Context;
9-
use Magento\Wishlist\Model\ItemCarrier;
13+
use Magento\Framework\App\Action\HttpGetActionInterface;
14+
use Magento\Framework\App\Action\HttpPostActionInterface;
15+
use Magento\Framework\Controller\Result\Forward;
16+
use Magento\Framework\Controller\Result\Redirect;
1017
use Magento\Framework\Controller\ResultFactory;
18+
use Magento\Wishlist\Model\ItemCarrier;
1119

12-
class Allcart extends \Magento\Framework\App\Action\Action
20+
/**
21+
* Wishlist Allcart Controller
22+
*/
23+
class Allcart extends Action implements HttpGetActionInterface, HttpPostActionInterface
1324
{
1425
/**
1526
* @var WishlistProvider
1627
*/
1728
protected $wishlistProvider;
1829

1930
/**
20-
* @var \Magento\Wishlist\Model\ItemCarrier
31+
* @var ItemCarrier
2132
*/
2233
protected $itemCarrier;
2334

@@ -39,21 +50,22 @@ public function __construct(
3950
/**
4051
* Add all items from wishlist to shopping cart
4152
*
42-
* @return \Magento\Framework\Controller\ResultInterface
53+
* {@inheritDoc}
4354
*/
4455
public function execute()
4556
{
4657
$wishlist = $this->wishlistProvider->getWishlist();
4758
if (!$wishlist) {
48-
/** @var \Magento\Framework\Controller\Result\Forward $resultForward */
59+
/** @var Forward $resultForward */
4960
$resultForward = $this->resultFactory->create(ResultFactory::TYPE_FORWARD);
5061
$resultForward->forward('noroute');
5162
return $resultForward;
5263
}
5364
$redirectUrl = $this->itemCarrier->moveAllToCart($wishlist, $this->getRequest()->getParam('qty'));
54-
/** @var \Magento\Framework\Controller\Result\Redirect $resultRedirect */
65+
/** @var Redirect $resultRedirect */
5566
$resultRedirect = $this->resultFactory->create(ResultFactory::TYPE_REDIRECT);
5667
$resultRedirect->setUrl($redirectUrl);
68+
5769
return $resultRedirect;
5870
}
5971
}

app/code/Magento/Wishlist/Controller/Shared/Cart.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
use Magento\Framework\App\Action\Action;
1414
use Magento\Framework\App\Action\Context as ActionContext;
1515
use Magento\Framework\App\Action\HttpPostActionInterface;
16-
use Magento\Framework\Controller\Result\Redirect;
16+
use Magento\Framework\Controller\Result\Redirect as ResultRedirect;
1717
use Magento\Framework\Controller\ResultFactory;
1818
use Magento\Framework\Escaper;
1919
use Magento\Framework\Exception\LocalizedException;
@@ -124,9 +124,11 @@ public function execute()
124124
} catch (\Exception $e) {
125125
$this->messageManager->addExceptionMessage($e, __('We can\'t add the item to the cart right now.'));
126126
}
127-
/** @var Redirect $resultRedirect */
127+
128+
/** @var ResultRedirect $resultRedirect */
128129
$resultRedirect = $this->resultFactory->create(ResultFactory::TYPE_REDIRECT);
129130
$resultRedirect->setUrl($redirectUrl);
131+
130132
return $resultRedirect;
131133
}
132134
}

app/code/Magento/Wishlist/Test/Unit/Controller/Shared/AllcartTest.php

Lines changed: 28 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
* Copyright © Magento, Inc. All rights reserved.
44
* See COPYING.txt for license details.
55
*/
6+
67
declare(strict_types=1);
78

89
namespace Magento\Wishlist\Test\Unit\Controller\Shared;
@@ -20,83 +21,60 @@
2021
use PHPUnit\Framework\MockObject\MockObject;
2122
use PHPUnit\Framework\TestCase;
2223

24+
/**
25+
* Test for \Magento\Wishlist\Controller\Shared\Allcart.
26+
*/
2327
class AllcartTest extends TestCase
2428
{
2529
/**
2630
* @var Allcart
2731
*/
28-
protected $allcartController;
29-
30-
/**
31-
* @var \Magento\Framework\TestFramework\Unit\Helper\ObjectManager
32-
*/
33-
protected $objectManagerHelper;
34-
35-
/**
36-
* @var Context
37-
*/
38-
protected $context;
32+
private $allcartController;
3933

4034
/**
4135
* @var WishlistProvider|MockObject
4236
*/
43-
protected $wishlistProviderMock;
37+
private $wishlistProviderMock;
4438

4539
/**
4640
* @var ItemCarrier|MockObject
4741
*/
48-
protected $itemCarrierMock;
42+
private $itemCarrierMock;
4943

5044
/**
5145
* @var Wishlist|MockObject
5246
*/
53-
protected $wishlistMock;
47+
private $wishlistMock;
5448

5549
/**
5650
* @var Http|MockObject
5751
*/
58-
protected $requestMock;
59-
60-
/**
61-
* @var ResultFactory|MockObject
62-
*/
63-
protected $resultFactoryMock;
52+
private $requestMock;
6453

6554
/**
6655
* @var Redirect|MockObject
6756
*/
68-
protected $resultRedirectMock;
57+
private $resultRedirectMock;
6958

7059
/**
7160
* @var Forward|MockObject
7261
*/
73-
protected $resultForwardMock;
62+
private $resultForwardMock;
7463

64+
/**
65+
* @inheritDoc
66+
*/
7567
protected function setUp(): void
7668
{
77-
$this->wishlistProviderMock = $this->getMockBuilder(WishlistProvider::class)
78-
->disableOriginalConstructor()
79-
->getMock();
80-
$this->itemCarrierMock = $this->getMockBuilder(ItemCarrier::class)
81-
->disableOriginalConstructor()
82-
->getMock();
83-
$this->wishlistMock = $this->getMockBuilder(Wishlist::class)
84-
->disableOriginalConstructor()
85-
->getMock();
86-
$this->requestMock = $this->getMockBuilder(Http::class)
87-
->disableOriginalConstructor()
88-
->getMock();
89-
$this->resultFactoryMock = $this->getMockBuilder(ResultFactory::class)
90-
->disableOriginalConstructor()
91-
->getMock();
92-
$this->resultRedirectMock = $this->getMockBuilder(Redirect::class)
93-
->disableOriginalConstructor()
94-
->getMock();
95-
$this->resultForwardMock = $this->getMockBuilder(Forward::class)
96-
->disableOriginalConstructor()
97-
->getMock();
98-
99-
$this->resultFactoryMock->expects($this->any())
69+
$this->wishlistProviderMock = $this->createMock(WishlistProvider::class);
70+
$this->itemCarrierMock = $this->createMock(ItemCarrier::class);
71+
$this->wishlistMock = $this->createMock(Wishlist::class);
72+
$this->requestMock = $this->createMock(Http::class);
73+
$resultFactoryMock = $this->createMock(ResultFactory::class);
74+
$this->resultRedirectMock = $this->createMock(Redirect::class);
75+
$this->resultForwardMock = $this->createMock(Forward::class);
76+
77+
$resultFactoryMock->expects($this->any())
10078
->method('create')
10179
->willReturnMap(
10280
[
@@ -105,18 +83,18 @@ protected function setUp(): void
10583
]
10684
);
10785

108-
$this->objectManagerHelper = new ObjectManagerHelper($this);
109-
$this->context = $this->objectManagerHelper->getObject(
86+
$objectManagerHelper = new ObjectManagerHelper($this);
87+
$context = $objectManagerHelper->getObject(
11088
Context::class,
11189
[
11290
'request' => $this->requestMock,
113-
'resultFactory' => $this->resultFactoryMock
91+
'resultFactory' => $resultFactoryMock
11492
]
11593
);
116-
$this->allcartController = $this->objectManagerHelper->getObject(
94+
$this->allcartController = $objectManagerHelper->getObject(
11795
Allcart::class,
11896
[
119-
'context' => $this->context,
97+
'context' => $context,
12098
'wishlistProvider' => $this->wishlistProviderMock,
12199
'itemCarrier' => $this->itemCarrierMock
122100
]

0 commit comments

Comments
 (0)