Skip to content

Commit 30a14ca

Browse files
Merge remote-tracking branch 'remotes/github/MAGETWO-92712' into EPAM-PR-64
2 parents 8cb16a3 + d32d595 commit 30a14ca

File tree

3 files changed

+34
-18
lines changed

3 files changed

+34
-18
lines changed

app/code/Magento/Catalog/Model/CategoryList.php

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,9 @@
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\Catalog\Model;
710

811
use Magento\Catalog\Api\CategoryListInterface;
@@ -50,7 +53,7 @@ class CategoryList implements CategoryListInterface
5053
* @param JoinProcessorInterface $extensionAttributesJoinProcessor
5154
* @param CategorySearchResultsInterfaceFactory $categorySearchResultsFactory
5255
* @param CategoryRepositoryInterface $categoryRepository
53-
* @param CollectionProcessorInterface $collectionProcessor
56+
* @param CollectionProcessorInterface|null $collectionProcessor
5457
*/
5558
public function __construct(
5659
CollectionFactory $categoryCollectionFactory,
@@ -74,12 +77,13 @@ public function getList(SearchCriteriaInterface $searchCriteria)
7477
/** @var Collection $collection */
7578
$collection = $this->categoryCollectionFactory->create();
7679
$this->extensionAttributesJoinProcessor->process($collection);
77-
7880
$this->collectionProcessor->process($searchCriteria, $collection);
7981

8082
$items = [];
81-
foreach ($collection->getAllIds() as $id) {
82-
$items[] = $this->categoryRepository->get($id);
83+
foreach ($collection->getData() as $categoryData) {
84+
$items[] = $this->categoryRepository->get(
85+
$categoryData[$collection->getEntity()->getIdFieldName()]
86+
);
8387
}
8488

8589
/** @var CategorySearchResultsInterface $searchResult */

app/code/Magento/Catalog/Test/Unit/Model/CategoryListTest.php

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,9 @@
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\Catalog\Test\Unit\Model;
710

811
use Magento\Catalog\Api\CategoryRepositoryInterface;
@@ -52,6 +55,9 @@ class CategoryListTest extends \PHPUnit\Framework\TestCase
5255
*/
5356
private $collectionProcessorMock;
5457

58+
/**
59+
* @inheritdoc
60+
*/
5561
protected function setUp()
5662
{
5763
$this->categoryCollectionFactory = $this->getMockBuilder(CollectionFactory::class)
@@ -93,7 +99,12 @@ public function testGetList()
9399

94100
$collection = $this->getMockBuilder(Collection::class)->disableOriginalConstructor()->getMock();
95101
$collection->expects($this->once())->method('getSize')->willReturn($totalCount);
96-
$collection->expects($this->once())->method('getAllIds')->willReturn([$categoryIdFirst, $categoryIdSecond]);
102+
$collection->expects($this->once())->method('getData')->willReturn(
103+
[['entity_id' => $categoryIdFirst], ['entity_id' => $categoryIdSecond]]
104+
);
105+
$collection->expects($this->any())->method('getEntity')->willReturn(
106+
new \Magento\Framework\DataObject(['id_field_name' => 'entity_id'])
107+
);
97108

98109
$this->collectionProcessorMock->expects($this->once())
99110
->method('process')
@@ -106,10 +117,7 @@ public function testGetList()
106117

107118
$this->categoryRepository->expects($this->exactly(2))
108119
->method('get')
109-
->willReturnMap([
110-
[$categoryIdFirst, $categoryFirst],
111-
[$categoryIdSecond, $categorySecond],
112-
])
120+
->willReturnMap([[$categoryIdFirst, $categoryFirst], [$categoryIdSecond, $categorySecond]])
113121
->willReturn($categoryFirst);
114122

115123
$this->categorySearchResultsFactory->expects($this->once())->method('create')->willReturn($searchResult);

dev/tests/api-functional/testsuite/Magento/Catalog/Api/CategoryListTest.php

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,17 @@
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\Catalog\Api;
710

811
use Magento\Framework\Webapi\Rest\Request;
912
use Magento\TestFramework\TestCase\WebapiAbstract;
1013

14+
/**
15+
* Checks the categories/list api
16+
*/
1117
class CategoryListTest extends WebapiAbstract
1218
{
1319
const RESOURCE_PATH = '/V1/categories/list';
@@ -35,14 +41,11 @@ public function testGetList()
3541
],
3642
],
3743
],
44+
],
45+
'sort_orders' => [
3846
[
39-
'filters' => [
40-
[
41-
'field' => 'level',
42-
'value' => 2,
43-
'condition_type' => 'eq',
44-
],
45-
],
47+
'field' => 'name',
48+
'direction' => 'DESC',
4649
],
4750
],
4851
'current_page' => 1,
@@ -69,9 +72,10 @@ public function testGetList()
6972

7073
$this->assertEquals($searchCriteria['searchCriteria'], $response['search_criteria']);
7174
$this->assertTrue($response['total_count'] > 0);
72-
$this->assertTrue(count($response['items']) > 0);
75+
$this->assertTrue(count($response['items']) === 2);
7376

7477
$this->assertNotNull($response['items'][0]['name']);
75-
$this->assertEquals('Category 1', $response['items'][0]['name']);
78+
$this->assertEquals('Category 1.1', $response['items'][0]['name']);
79+
$this->assertEquals('Category 1', $response['items'][1]['name']);
7680
}
7781
}

0 commit comments

Comments
 (0)