Skip to content

Commit d59d740

Browse files
Barny ShergoldBarny Shergold
authored andcommitted
Updated code as per reviewer
1 parent e100822 commit d59d740

File tree

2 files changed

+14
-14
lines changed

2 files changed

+14
-14
lines changed

app/code/Magento/CatalogUrlRewrite/Model/ProductScopeRewriteGenerator.php

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
namespace Magento\CatalogUrlRewrite\Model;
77

88
use Magento\Catalog\Api\CategoryRepositoryInterface;
9+
use Magento\Catalog\Api\Data\CategoryInterface;
910
use Magento\Catalog\Model\Category;
1011
use Magento\Catalog\Model\Product;
1112
use Magento\CatalogUrlRewrite\Model\Product\AnchorUrlRewriteGenerator;
@@ -15,13 +16,12 @@
1516
use Magento\CatalogUrlRewrite\Service\V1\StoreViewService;
1617
use Magento\Framework\App\Config\ScopeConfigInterface;
1718
use Magento\Framework\App\ObjectManager;
19+
use Magento\Framework\Exception\NoSuchEntityException;
1820
use Magento\Store\Model\Store;
1921
use Magento\Store\Model\StoreManagerInterface;
2022
use Magento\UrlRewrite\Model\MergeDataProviderFactory;
2123

2224
/**
23-
* Class ProductScopeRewriteGenerator
24-
*
2525
* Generates Product/Category URLs for different scopes
2626
*
2727
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
@@ -237,14 +237,18 @@ public function isCategoryProperForGenerating(Category $category, $storeId)
237237
}
238238

239239
/**
240-
* Check if URL key has been changed
241-
*
242240
* Checks if URL key has been changed for provided category and returns reloaded category,
243241
* in other case - returns provided category.
244242
*
243+
* Category should be loaded per appropriate store at all times. This is because whilst the URL key on the
244+
* category in focus might be unchanged, parent category URL keys might be. If the category store ID
245+
* and passed store ID are the same then return current category as it is correct but may have changed in memory
246+
*
245247
* @param int $storeId
246248
* @param Category $category
247-
* @return Category
249+
*
250+
* @return CategoryInterface
251+
* @throws NoSuchEntityException
248252
*/
249253
private function getCategoryWithOverriddenUrlKey($storeId, Category $category)
250254
{
@@ -254,11 +258,7 @@ private function getCategoryWithOverriddenUrlKey($storeId, Category $category)
254258
Category::ENTITY
255259
);
256260

257-
// Category should be loaded per appropriate store at all times. This is because whilst the URL key on the
258-
// category in focus might be unchanged, parent category URL keys might be. If the category store ID
259-
// and passed store ID are the same then return current category as it is correct but may have changed in memory
260-
261-
if (!$isUrlKeyOverridden && $storeId == $category->getStoreId()) {
261+
if (!$isUrlKeyOverridden && $storeId === $category->getStoreId()) {
262262
return $category;
263263
}
264264

app/code/Magento/CatalogUrlRewrite/Test/Unit/Model/ProductScopeRewriteGeneratorTest.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ class ProductScopeRewriteGeneratorTest extends TestCase
7171
private $configMock;
7272

7373
/** @var CategoryRepositoryInterface|MockObject */
74-
private $categoryRepository;
74+
private $categoryRepositoryMock;
7575

7676
protected function setUp(): void
7777
{
@@ -130,7 +130,7 @@ function ($value) {
130130
$this->configMock = $this->getMockBuilder(ScopeConfigInterface::class)
131131
->getMock();
132132

133-
$this->categoryRepository = $this->getMockForAbstractClass(CategoryRepositoryInterface::class);
133+
$this->categoryRepositoryMock = $this->getMockForAbstractClass(CategoryRepositoryInterface::class);
134134

135135
$this->productScopeGenerator = (new ObjectManager($this))->getObject(
136136
ProductScopeRewriteGenerator::class,
@@ -144,7 +144,7 @@ function ($value) {
144144
'storeManager' => $this->storeManager,
145145
'mergeDataProviderFactory' => $mergeDataProviderFactory,
146146
'config' => $this->configMock,
147-
'categoryRepository' => $this->categoryRepository
147+
'categoryRepository' => $this->categoryRepositoryMock
148148
]
149149
);
150150
$this->categoryMock = $this->getMockBuilder(Category::class)
@@ -222,7 +222,7 @@ public function testGenerationForSpecificStore()
222222
$this->anchorUrlRewriteGenerator->expects($this->any())->method('generate')
223223
->willReturn([]);
224224

225-
$this->categoryRepository->expects($this->once())->method('get')->willReturn($this->categoryMock);
225+
$this->categoryRepositoryMock->expects($this->once())->method('get')->willReturn($this->categoryMock);
226226

227227
$this->assertEquals(
228228
['category-1_1' => $canonical],

0 commit comments

Comments
 (0)