From 6cf13db2afa4679da922c5973a70a792011804d7 Mon Sep 17 00:00:00 2001 From: Patrick McLain Date: Thu, 26 Dec 2019 14:56:16 -0500 Subject: [PATCH 1/6] Allow wishlist share when all items are out of stock Clicking `Share` on the wishlist view page updates and saves the wishlist before redirecting to the share page. The redirection to the share page only happens when the post body includes wishlist descriptions. Because qty and comment are disabled for out of stock wishlist items these properties are not sent with the post resulting in the share redirect being unreachable when all items are out of stock. This commit updates the controller flow separating the logic conditions for saving and sharing. This allows sharing wishlist where all items are out of stock. --- .../Magento/Wishlist/Controller/Index/Update.php | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/app/code/Magento/Wishlist/Controller/Index/Update.php b/app/code/Magento/Wishlist/Controller/Index/Update.php index e5fbd4b93f82e..ca096217ab9cb 100644 --- a/app/code/Magento/Wishlist/Controller/Index/Update.php +++ b/app/code/Magento/Wishlist/Controller/Index/Update.php @@ -70,7 +70,12 @@ public function execute() } $post = $this->getRequest()->getPostValue(); - if ($post && isset($post['description']) && is_array($post['description'])) { + $resultRedirect->setPath('*', ['wishlist_id' => $wishlist->getId()]); + if (!$post) { + return $resultRedirect; + } + + if (isset($post['description']) && is_array($post['description'])) { $updatedItems = 0; foreach ($post['description'] as $itemId => $description) { @@ -136,13 +141,12 @@ public function execute() $this->messageManager->addErrorMessage(__('Can\'t update wish list')); } } + } - if (isset($post['save_and_share'])) { - $resultRedirect->setPath('*/*/share', ['wishlist_id' => $wishlist->getId()]); - return $resultRedirect; - } + if (isset($post['save_and_share'])) { + $resultRedirect->setPath('*/*/share', ['wishlist_id' => $wishlist->getId()]); } - $resultRedirect->setPath('*', ['wishlist_id' => $wishlist->getId()]); + return $resultRedirect; } } From 860af386adae830d5ba50b5ae3fb66946ad6badd Mon Sep 17 00:00:00 2001 From: Patrick McLain Date: Thu, 26 Dec 2019 16:20:15 -0500 Subject: [PATCH 2/6] Fix static tests --- app/code/Magento/Wishlist/Controller/Index/Update.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/code/Magento/Wishlist/Controller/Index/Update.php b/app/code/Magento/Wishlist/Controller/Index/Update.php index ca096217ab9cb..ceb001a61c405 100644 --- a/app/code/Magento/Wishlist/Controller/Index/Update.php +++ b/app/code/Magento/Wishlist/Controller/Index/Update.php @@ -11,7 +11,7 @@ use Magento\Framework\Controller\ResultFactory; /** - * Class Update + * Controller for updating wishlists */ class Update extends \Magento\Wishlist\Controller\AbstractIndex implements HttpPostActionInterface { From 21bdc6731bc22af6aee7d1fdd5433e5c9ab2f3d5 Mon Sep 17 00:00:00 2001 From: Nazar Klovanych Date: Mon, 30 Dec 2019 15:05:17 +0200 Subject: [PATCH 3/6] Cover changes with Unit test --- .../Test/Unit/Controller/Index/UpdateTest.php | 119 ++++++++++++++++++ 1 file changed, 119 insertions(+) create mode 100644 app/code/Magento/Wishlist/Test/Unit/Controller/Index/UpdateTest.php diff --git a/app/code/Magento/Wishlist/Test/Unit/Controller/Index/UpdateTest.php b/app/code/Magento/Wishlist/Test/Unit/Controller/Index/UpdateTest.php new file mode 100644 index 0000000000000..db21ff5de13c6 --- /dev/null +++ b/app/code/Magento/Wishlist/Test/Unit/Controller/Index/UpdateTest.php @@ -0,0 +1,119 @@ +formKeyValidator = $this->createMock(Validator::class); + $this->wishlistProvider = $this->createMock(WishlistProviderInterface::class); + $this->quantityProcessor = $this->createMock(LocaleQuantityProcessor::class); + $this->context = $this->createMock(Context::class); + $this->resultRedirect = $this->createMock(Redirect::class); + $this->resultFactory = $this->createPartialMock(ResultFactory::class, ['create']); + $this->requestMock = $this->getMockBuilder(RequestInterface::class) + ->setMethods(['getPostValue']) + ->getMockForAbstractClass(); + + $this->context->expects($this->once()) + ->method('getResultFactory') + ->willReturn($this->resultFactory); + + $this->resultFactory->expects($this->any()) + ->method('create') + ->willReturn($this->resultRedirect); + $this->context->expects($this->any()) + ->method('getRequest') + ->willReturn($this->requestMock); + + $this->updateController = new Update( + $this->context, + $this->formKeyValidator, + $this->wishlistProvider, + $this->quantityProcessor + ); + } + + /** + * Test for update method Wishlist controller. + * + * Check if there is not post value result redirect returned. + * + * @return void + */ + public function testUpdate(): void + { + $this->formKeyValidator->expects($this->once()) + ->method('validate') + ->willReturn(true); + + $wishlist = $this->createMock(\Magento\Wishlist\Model\Wishlist::class); + $this->wishlistProvider->expects($this->once()) + ->method('getWishlist') + ->willReturn($wishlist); + $this->requestMock->expects($this->once()) + ->method('getPostValue') + ->willReturn(null); + $this->assertEquals($this->resultRedirect, $this->updateController->execute()); + } +} From 3c3018d3ce6132c28072cda40a9edf73d1de3915 Mon Sep 17 00:00:00 2001 From: Nazar Klovanych Date: Mon, 30 Dec 2019 18:14:17 +0200 Subject: [PATCH 4/6] Cover changes with unit test --- .../Test/Unit/Controller/Index/UpdateTest.php | 149 +++++++++++++++++- 1 file changed, 141 insertions(+), 8 deletions(-) diff --git a/app/code/Magento/Wishlist/Test/Unit/Controller/Index/UpdateTest.php b/app/code/Magento/Wishlist/Test/Unit/Controller/Index/UpdateTest.php index db21ff5de13c6..86de21fd7f983 100644 --- a/app/code/Magento/Wishlist/Test/Unit/Controller/Index/UpdateTest.php +++ b/app/code/Magento/Wishlist/Test/Unit/Controller/Index/UpdateTest.php @@ -10,13 +10,19 @@ use Magento\Framework\App\RequestInterface; use Magento\Framework\Controller\ResultFactory; use Magento\Framework\Data\Form\FormKey\Validator; +use Magento\Framework\Exception\NotFoundException; +use Magento\Framework\Message\ManagerInterface; +use Magento\Framework\ObjectManagerInterface; use Magento\Wishlist\Controller\Index\Update; use Magento\Wishlist\Controller\WishlistProviderInterface; +use Magento\Wishlist\Helper\Data; +use Magento\Wishlist\Model\Item; use Magento\Wishlist\Model\LocaleQuantityProcessor; use PHPUnit\Framework\TestCase; /** * Test for upate controller wishlist + * @SuppressWarnings(PHPMD.CouplingBetweenObjects) */ class UpdateTest extends TestCase { @@ -60,6 +66,16 @@ class UpdateTest extends TestCase */ private $requestMock; + /** + * @var ObjectManagerInterface $objectManagerMock + */ + private $objectManagerMock; + + /** + * @var ManagerInterface $messageManager + */ + private $messageManager; + /** * @inheritdoc */ @@ -74,10 +90,14 @@ protected function setUp() $this->requestMock = $this->getMockBuilder(RequestInterface::class) ->setMethods(['getPostValue']) ->getMockForAbstractClass(); + $this->objectManagerMock = $this->createMock(ObjectManagerInterface::class); $this->context->expects($this->once()) - ->method('getResultFactory') - ->willReturn($this->resultFactory); + ->method('getResultFactory') + ->willReturn($this->resultFactory); + $this->context->expects($this->once()) + ->method('getObjectManager') + ->willReturn($this->objectManagerMock); $this->resultFactory->expects($this->any()) ->method('create') @@ -86,6 +106,11 @@ protected function setUp() ->method('getRequest') ->willReturn($this->requestMock); + $this->messageManager = $this->createMock(ManagerInterface::class); + $this->context->expects($this->any()) + ->method('getMessageManager') + ->willReturn($this->messageManager); + $this->updateController = new Update( $this->context, $this->formKeyValidator, @@ -97,23 +122,131 @@ protected function setUp() /** * Test for update method Wishlist controller. * - * Check if there is not post value result redirect returned. - * + * @dataProvider getWishlistDataProvider * @return void */ - public function testUpdate(): void + public function testUpdate(array $wishlistDataProvider): void { $this->formKeyValidator->expects($this->once()) - ->method('validate') - ->willReturn(true); + ->method('validate') + ->willReturn(true); $wishlist = $this->createMock(\Magento\Wishlist\Model\Wishlist::class); + $this->wishlistProvider->expects($this->once()) ->method('getWishlist') ->willReturn($wishlist); + $wishlist->expects($this->exactly(2)) + ->method('getId') + ->willReturn($wishlistDataProvider['wishlist_data']['id']); $this->requestMock->expects($this->once()) ->method('getPostValue') - ->willReturn(null); + ->willReturn($wishlistDataProvider['post_data']); + $this->resultRedirect->expects($this->once()) + ->method('setPath') + ->with('*', ['wishlist_id' => $wishlistDataProvider['wishlist_data']['id']]); + $itemMock = $this->getMockBuilder(Item::class) + ->disableOriginalConstructor() + ->setMethods( + [ + 'load', + 'getId', + 'getWishlistId', + 'setQty', + 'save', + 'getDescription', + 'setDescription', + 'getProduct', + 'getName' + ] + )->getMock(); + + $this->objectManagerMock->expects($this->once()) + ->method('create') + ->with(Item::class) + ->willReturn($itemMock); + $itemMock->expects($this->once()) + ->method('load') + ->with(1) + ->willReturnSelf(); + $itemMock->expects($this->once()) + ->method('getWishLIstId') + ->willReturn($wishlistDataProvider['wishlist_data']['id']); + $itemMock->expects($this->once()) + ->method('getDescription') + ->willReturn(''); + $itemMock->expects($this->once()) + ->method('setDescription') + ->willReturnSelf(); + $itemMock->expects($this->once()) + ->method('setQty') + ->willReturnSelf(); + $dataMock = $this->createMock(Data::class); + + $this->objectManagerMock->expects($this->exactly(2)) + ->method('get') + ->with(Data::class) + ->willReturn($dataMock); + $dataMock->expects($this->once()) + ->method('defaultCommentString') + ->willReturn(''); + $dataMock->expects($this->once()) + ->method('calculate'); + $this->quantityProcessor->expects($this->once()) + ->method('process') + ->willReturn($wishlistDataProvider['post_data']['qty']); + + $productMock = $this->getMockBuilder(\Magento\Catalog\Model\Product::class) + ->disableOriginalConstructor() + ->getMock(); + $itemMock->expects($this->once()) + ->method('getProduct') + ->willReturn($productMock); + $productMock->expects($this->once()) + ->method('getName') + ->willReturn('product'); + $this->messageManager->expects($this->once()) + ->method('addSuccessMessage'); $this->assertEquals($this->resultRedirect, $this->updateController->execute()); } + + /** + * Check if wishlist not availbale, and exception is shown + */ + public function testUpdateWithNotFoundException() + { + $this->formKeyValidator->expects($this->once()) + ->method('validate') + ->willReturn(true); + $this->wishlistProvider->expects($this->once()) + ->method('getWishlist') + ->willReturn(null); + $this->expectException(NotFoundException::class); + $this->updateController->execute(); + } + + /** + * Dataprovider for Update test + * + * @return array + */ + public function getWishlistDataProvider(): array + { + return [ + [ + [ + 'wishlist_data' => [ + 'id' => 1, + + ], + 'post_data' => [ + 'qty' => [1 => 12], + 'description' => [ + 1 => 'Description for item_id 1' + ] + ] + ] + ] + ]; + } } From 74a244f10fc0b945960167b713489df22b202154 Mon Sep 17 00:00:00 2001 From: Nazar Klovanych Date: Fri, 10 Jan 2020 12:15:31 +0200 Subject: [PATCH 5/6] Refactor per review comments, add new test case --- .../Test/Unit/Controller/Index/UpdateTest.php | 214 +++++++++++------- 1 file changed, 130 insertions(+), 84 deletions(-) diff --git a/app/code/Magento/Wishlist/Test/Unit/Controller/Index/UpdateTest.php b/app/code/Magento/Wishlist/Test/Unit/Controller/Index/UpdateTest.php index 86de21fd7f983..e6c07d35b46fd 100644 --- a/app/code/Magento/Wishlist/Test/Unit/Controller/Index/UpdateTest.php +++ b/app/code/Magento/Wishlist/Test/Unit/Controller/Index/UpdateTest.php @@ -13,12 +13,15 @@ use Magento\Framework\Exception\NotFoundException; use Magento\Framework\Message\ManagerInterface; use Magento\Framework\ObjectManagerInterface; +use Magento\Framework\TestFramework\Unit\Helper\ObjectManager as ObjectManagerHelper; use Magento\Wishlist\Controller\Index\Update; use Magento\Wishlist\Controller\WishlistProviderInterface; use Magento\Wishlist\Helper\Data; use Magento\Wishlist\Model\Item; use Magento\Wishlist\Model\LocaleQuantityProcessor; +use Magento\Wishlist\Model\Wishlist; use PHPUnit\Framework\TestCase; +use PHPUnit_Framework_MockObject_MockObject as MockObject; /** * Test for upate controller wishlist @@ -27,19 +30,33 @@ class UpdateTest extends TestCase { /** - * @var Validator $formKeyValidator + * Wishlist item id + * + * @var int + */ + private const ITEM_ID = 1; + + /** + * Product qty for wishlist + * + * @var int */ - private $formKeyValidator; + private const WISHLIST_PRODUCT_QTY = 21; /** - * @var WishlistProviderInterface $wishlistProvider + * @var MockObject|Validator $formKeyValidatorMock */ - private $wishlistProvider; + private $formKeyValidatorMock; /** - * @var LocaleQuantityProcessor $quantityProcessor + * @var MockObject|WishlistProviderInterface $wishlistProviderMock */ - private $quantityProcessor; + private $wishlistProviderMock; + + /** + * @var MockObject|LocaleQuantityProcessor $quantityProcessorMock + */ + private $quantityProcessorMock; /** * @var Update $updateController @@ -47,75 +64,76 @@ class UpdateTest extends TestCase private $updateController; /** - * @var $context + * @var MockObject|Context$contextMock */ - private $context; + private $contextMock; /** - * @var Redirect $resultRedirect + * @var MockObject|Redirect $resultRedirectMock */ - private $resultRedirect; + private $resultRedirectMock; /** - * @var ResultFactory $resultFatory + * @var MockObject|ResultFactory $resultFatoryMock */ - private $resultFactory; + private $resultFactoryMock; /** - * @var RequestInterface $requestMock + * @var MockObject|RequestInterface $requestMock */ private $requestMock; /** - * @var ObjectManagerInterface $objectManagerMock + * @var MockObject|ObjectManagerInterface $objectManagerMock */ private $objectManagerMock; /** - * @var ManagerInterface $messageManager + * @var MockObject|ManagerInterface $messageManagerMock */ - private $messageManager; + private $messageManagerMock; /** * @inheritdoc */ protected function setUp() { - $this->formKeyValidator = $this->createMock(Validator::class); - $this->wishlistProvider = $this->createMock(WishlistProviderInterface::class); - $this->quantityProcessor = $this->createMock(LocaleQuantityProcessor::class); - $this->context = $this->createMock(Context::class); - $this->resultRedirect = $this->createMock(Redirect::class); - $this->resultFactory = $this->createPartialMock(ResultFactory::class, ['create']); + $this->formKeyValidatorMock = $this->createMock(Validator::class); + $this->wishlistProviderMock = $this->createMock(WishlistProviderInterface::class); + $this->quantityProcessorMock = $this->createMock(LocaleQuantityProcessor::class); + $this->contextMock = $this->createMock(Context::class); + $this->resultRedirectMock = $this->createMock(Redirect::class); + $this->resultFactoryMock = $this->createPartialMock(ResultFactory::class, ['create']); + $this->messageManagerMock = $this->createMock(ManagerInterface::class); + $this->objectManagerMock = $this->createMock(ObjectManagerInterface::class); $this->requestMock = $this->getMockBuilder(RequestInterface::class) ->setMethods(['getPostValue']) ->getMockForAbstractClass(); - $this->objectManagerMock = $this->createMock(ObjectManagerInterface::class); - $this->context->expects($this->once()) + $this->resultFactoryMock->expects($this->any()) + ->method('create') + ->willReturn($this->resultRedirectMock); + $this->contextMock->expects($this->once()) ->method('getResultFactory') - ->willReturn($this->resultFactory); - $this->context->expects($this->once()) + ->willReturn($this->resultFactoryMock); + $this->contextMock->expects($this->once()) ->method('getObjectManager') ->willReturn($this->objectManagerMock); - - $this->resultFactory->expects($this->any()) - ->method('create') - ->willReturn($this->resultRedirect); - $this->context->expects($this->any()) + $this->contextMock->expects($this->any()) ->method('getRequest') ->willReturn($this->requestMock); - - $this->messageManager = $this->createMock(ManagerInterface::class); - $this->context->expects($this->any()) + $this->contextMock->expects($this->any()) ->method('getMessageManager') - ->willReturn($this->messageManager); + ->willReturn($this->messageManagerMock); - $this->updateController = new Update( - $this->context, - $this->formKeyValidator, - $this->wishlistProvider, - $this->quantityProcessor + $this->updateController = (new ObjectManagerHelper($this))->getObject( + Update::class, + [ + 'context' => $this->contextMock, + '_formKeyValidator' => $this->formKeyValidatorMock, + 'wishlistProvider' => $this->wishlistProviderMock, + 'quantityProcessor' => $this->quantityProcessorMock + ] ); } @@ -123,28 +141,13 @@ protected function setUp() * Test for update method Wishlist controller. * * @dataProvider getWishlistDataProvider + * @param array $wishlistDataProvider + * @param array $postData * @return void */ - public function testUpdate(array $wishlistDataProvider): void + public function testUpdate(array $wishlistDataProvider, array $postData): void { - $this->formKeyValidator->expects($this->once()) - ->method('validate') - ->willReturn(true); - - $wishlist = $this->createMock(\Magento\Wishlist\Model\Wishlist::class); - - $this->wishlistProvider->expects($this->once()) - ->method('getWishlist') - ->willReturn($wishlist); - $wishlist->expects($this->exactly(2)) - ->method('getId') - ->willReturn($wishlistDataProvider['wishlist_data']['id']); - $this->requestMock->expects($this->once()) - ->method('getPostValue') - ->willReturn($wishlistDataProvider['post_data']); - $this->resultRedirect->expects($this->once()) - ->method('setPath') - ->with('*', ['wishlist_id' => $wishlistDataProvider['wishlist_data']['id']]); + $wishlist = $this->createMock(Wishlist::class); $itemMock = $this->getMockBuilder(Item::class) ->disableOriginalConstructor() ->setMethods( @@ -160,7 +163,27 @@ public function testUpdate(array $wishlistDataProvider): void 'getName' ] )->getMock(); + $dataMock = $this->createMock(Data::class); + $productMock = $this->getMockBuilder(\Magento\Catalog\Model\Product::class) + ->disableOriginalConstructor() + ->getMock(); + $this->formKeyValidatorMock->expects($this->once()) + ->method('validate') + ->with($this->requestMock) + ->willReturn(true); + $this->wishlistProviderMock->expects($this->once()) + ->method('getWishlist') + ->willReturn($wishlist); + $wishlist->expects($this->exactly(2)) + ->method('getId') + ->willReturn($wishlistDataProvider['id']); + $this->requestMock->expects($this->once()) + ->method('getPostValue') + ->willReturn($postData); + $this->resultRedirectMock->expects($this->once()) + ->method('setPath') + ->with('*', ['wishlist_id' => $wishlistDataProvider['id']]); $this->objectManagerMock->expects($this->once()) ->method('create') ->with(Item::class) @@ -171,7 +194,7 @@ public function testUpdate(array $wishlistDataProvider): void ->willReturnSelf(); $itemMock->expects($this->once()) ->method('getWishLIstId') - ->willReturn($wishlistDataProvider['wishlist_data']['id']); + ->willReturn($wishlistDataProvider['id']); $itemMock->expects($this->once()) ->method('getDescription') ->willReturn(''); @@ -181,8 +204,6 @@ public function testUpdate(array $wishlistDataProvider): void $itemMock->expects($this->once()) ->method('setQty') ->willReturnSelf(); - $dataMock = $this->createMock(Data::class); - $this->objectManagerMock->expects($this->exactly(2)) ->method('get') ->with(Data::class) @@ -192,33 +213,62 @@ public function testUpdate(array $wishlistDataProvider): void ->willReturn(''); $dataMock->expects($this->once()) ->method('calculate'); - $this->quantityProcessor->expects($this->once()) + $this->quantityProcessorMock->expects($this->once()) ->method('process') - ->willReturn($wishlistDataProvider['post_data']['qty']); - - $productMock = $this->getMockBuilder(\Magento\Catalog\Model\Product::class) - ->disableOriginalConstructor() - ->getMock(); + ->willReturn($postData['qty']); $itemMock->expects($this->once()) ->method('getProduct') ->willReturn($productMock); $productMock->expects($this->once()) ->method('getName') ->willReturn('product'); - $this->messageManager->expects($this->once()) + $this->messageManagerMock->expects($this->once()) ->method('addSuccessMessage'); - $this->assertEquals($this->resultRedirect, $this->updateController->execute()); + + $this->assertEquals($this->resultRedirectMock, $this->updateController->execute()); + } + + /** + * Verify update method if post data not available + * + * @dataProvider getWishlistDataProvider + * @param array $wishlistDataProvider + * @return void + */ + public function testUpdateRedirectWhenNoPostData(array $wishlistDataProvider): void + { + $wishlist = $this->createMock(Wishlist::class); + + $this->formKeyValidatorMock->expects($this->once()) + ->method('validate') + ->willReturn(true); + $this->wishlistProviderMock->expects($this->once()) + ->method('getWishlist') + ->willReturn($wishlist); + $wishlist->expects($this->exactly(1)) + ->method('getId') + ->willReturn($wishlistDataProvider['id']); + $this->resultRedirectMock->expects($this->once()) + ->method('setPath') + ->with('*', ['wishlist_id' => $wishlistDataProvider['id']]); + $this->requestMock->expects($this->once()) + ->method('getPostValue') + ->willReturn(null); + + $this->assertEquals($this->resultRedirectMock, $this->updateController->execute()); } /** * Check if wishlist not availbale, and exception is shown + * + * @return void */ - public function testUpdateWithNotFoundException() + public function testUpdateThrowsNotFoundExceptionWhenWishlistDoNotExist(): void { - $this->formKeyValidator->expects($this->once()) + $this->formKeyValidatorMock->expects($this->once()) ->method('validate') ->willReturn(true); - $this->wishlistProvider->expects($this->once()) + $this->wishlistProviderMock->expects($this->once()) ->method('getWishlist') ->willReturn(null); $this->expectException(NotFoundException::class); @@ -232,21 +282,17 @@ public function testUpdateWithNotFoundException() */ public function getWishlistDataProvider(): array { - return [ + return [ [ - 'wishlist_data' => [ - 'id' => 1, - + [ + 'id' => self::ITEM_ID ], - 'post_data' => [ - 'qty' => [1 => 12], - 'description' => [ - 1 => 'Description for item_id 1' - ] + [ + 'qty' => [self::ITEM_ID => self::WISHLIST_PRODUCT_QTY], + 'description' => [self::ITEM_ID => 'Description for item_id 1'] ] ] - ] - ]; + ]; } } From 1748633667a1a0eef94b47ebd54963b33e338068 Mon Sep 17 00:00:00 2001 From: Nazar Klovanych Date: Fri, 10 Jan 2020 12:56:24 +0200 Subject: [PATCH 6/6] rename const with prefix "stub" move Object Manager to separate variable --- .../Test/Unit/Controller/Index/UpdateTest.php | 24 +++++++------------ 1 file changed, 8 insertions(+), 16 deletions(-) diff --git a/app/code/Magento/Wishlist/Test/Unit/Controller/Index/UpdateTest.php b/app/code/Magento/Wishlist/Test/Unit/Controller/Index/UpdateTest.php index e6c07d35b46fd..88aeec5e5a924 100644 --- a/app/code/Magento/Wishlist/Test/Unit/Controller/Index/UpdateTest.php +++ b/app/code/Magento/Wishlist/Test/Unit/Controller/Index/UpdateTest.php @@ -29,19 +29,9 @@ */ class UpdateTest extends TestCase { - /** - * Wishlist item id - * - * @var int - */ - private const ITEM_ID = 1; + private const STUB_ITEM_ID = 1; - /** - * Product qty for wishlist - * - * @var int - */ - private const WISHLIST_PRODUCT_QTY = 21; + private const STUB_WISHLIST_PRODUCT_QTY = 21; /** * @var MockObject|Validator $formKeyValidatorMock @@ -126,7 +116,9 @@ protected function setUp() ->method('getMessageManager') ->willReturn($this->messageManagerMock); - $this->updateController = (new ObjectManagerHelper($this))->getObject( + $objectManager = new ObjectManagerHelper($this); + + $this->updateController = $objectManager->getObject( Update::class, [ 'context' => $this->contextMock, @@ -286,11 +278,11 @@ public function getWishlistDataProvider(): array [ [ [ - 'id' => self::ITEM_ID + 'id' => self::STUB_ITEM_ID ], [ - 'qty' => [self::ITEM_ID => self::WISHLIST_PRODUCT_QTY], - 'description' => [self::ITEM_ID => 'Description for item_id 1'] + 'qty' => [self::STUB_ITEM_ID => self::STUB_WISHLIST_PRODUCT_QTY], + 'description' => [self::STUB_ITEM_ID => 'Description for item_id 1'] ] ] ];