Skip to content

Commit ae62eef

Browse files
committed
Github #31984: improved unit test from feedback
1 parent 6da61df commit ae62eef

File tree

1 file changed

+45
-45
lines changed

1 file changed

+45
-45
lines changed

app/code/Magento/CatalogUrlRewrite/Test/Unit/Model/Storage/DynamicStorageTest.php

Lines changed: 45 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -33,119 +33,119 @@ class DynamicStorageTest extends TestCase
3333
/**
3434
* @var UrlRewriteFactory|MockObject
3535
*/
36-
private $urlRewriteFactory;
36+
private $urlRewriteFactoryMock;
3737

3838
/**
3939
* @var DataObjectHelper|MockObject
4040
*/
41-
private $dataObjectHelper;
41+
private $dataObjectHelperMock;
4242

4343
/**
4444
* @var AdapterInterface|MockObject
4545
*/
46-
private $connection;
46+
private $connectionMock;
4747

4848
/**
4949
* @var Select|MockObject
5050
*/
51-
private $select;
51+
private $selectMock;
5252

5353
/**
5454
* @var ResourceConnection|MockObject
5555
*/
56-
private $resourceConnection;
56+
private $resourceConnectionMock;
5757

5858
/**
5959
* @var ScopeConfigInterface|MockObject
6060
*/
61-
private $scopeConfig;
61+
private $scopeConfigMock;
6262

6363
/**
6464
* @var Product|MockObject
6565
*/
66-
private $productResource;
66+
private $productResourceMock;
6767

6868
/**
6969
* @var ProductFactory|MockObject
7070
*/
71-
private $productFactory;
71+
private $productFactoryMock;
7272

7373
/**
7474
* @inheritdoc
7575
*/
7676
protected function setUp(): void
7777
{
78-
$this->urlRewriteFactory = $this->getMockBuilder(UrlRewriteFactory::class)
78+
$this->urlRewriteFactoryMock = $this->getMockBuilder(UrlRewriteFactory::class)
7979
->disableOriginalConstructor()
8080
->getMock();
8181

82-
$this->dataObjectHelper = $this->getMockBuilder(DataObjectHelper::class)
82+
$this->dataObjectHelperMock = $this->getMockBuilder(DataObjectHelper::class)
8383
->disableOriginalConstructor()
8484
->getMock();
8585

86-
$this->connection = $this->getMockBuilder(AdapterInterface::class)
86+
$this->connectionMock = $this->getMockBuilder(AdapterInterface::class)
8787
->disableOriginalConstructor()
8888
->getMock();
8989

90-
$this->select = $this->getMockBuilder(Select::class)
90+
$this->selectMock = $this->getMockBuilder(Select::class)
9191
->disableOriginalConstructor()
9292
->getMock();
9393

94-
$this->resourceConnection = $this->getMockBuilder(ResourceConnection::class)
94+
$this->resourceConnectionMock = $this->getMockBuilder(ResourceConnection::class)
9595
->disableOriginalConstructor()
9696
->getMock();
9797

98-
$this->connection
98+
$this->connectionMock
9999
->method('select')
100-
->willReturn($this->select);
100+
->willReturn($this->selectMock);
101101

102-
$this->resourceConnection
102+
$this->resourceConnectionMock
103103
->method('getConnection')
104-
->willReturn($this->connection);
104+
->willReturn($this->connectionMock);
105105

106-
$this->scopeConfig = $this->getMockBuilder(ScopeConfigInterface::class)
106+
$this->scopeConfigMock = $this->getMockBuilder(ScopeConfigInterface::class)
107107
->getMock();
108108

109-
$this->productResource = $this->getMockBuilder(Product::class)
109+
$this->productResourceMock = $this->getMockBuilder(Product::class)
110110
->disableOriginalConstructor()
111111
->getMock();
112112

113-
$this->productFactory = $this->getMockBuilder(ProductFactory::class)
113+
$this->productFactoryMock = $this->getMockBuilder(ProductFactory::class)
114114
->disableOriginalConstructor()
115115
->getMock();
116116

117-
$this->productFactory
117+
$this->productFactoryMock
118118
->method('create')
119-
->willReturn($this->productResource);
119+
->willReturn($this->productResourceMock);
120120

121121
$this->object = new DynamicStorage(
122-
$this->urlRewriteFactory,
123-
$this->dataObjectHelper,
124-
$this->resourceConnection,
125-
$this->scopeConfig,
126-
$this->productFactory
122+
$this->urlRewriteFactoryMock,
123+
$this->dataObjectHelperMock,
124+
$this->resourceConnectionMock,
125+
$this->scopeConfigMock,
126+
$this->productFactoryMock
127127
);
128128
}
129129

130130
/**
131-
* @param $data
132-
* @param $productFromDb
133-
* @param $categorySuffix
134-
* @param $categoryFromDb
135-
* @param $canBeShownInCategory
136-
* @param $expectedProductRewrite
137-
* @throws \ReflectionException
138131
* @dataProvider findProductRewriteByRequestPathDataProvider
132+
* @param array $data
133+
* @param array|false $productFromDb
134+
* @param string $categorySuffix
135+
* @param array|false $categoryFromDb
136+
* @param bool $canBeShownInCategory
137+
* @param array|null $expectedProductRewrite
138+
* @throws \ReflectionException
139139
*/
140140
public function testFindProductRewriteByRequestPath(
141-
$data,
141+
array $data,
142142
$productFromDb,
143-
$categorySuffix,
143+
string $categorySuffix,
144144
$categoryFromDb,
145-
$canBeShownInCategory,
146-
$expectedProductRewrite
147-
) {
148-
$this->connection->expects($this->any())
145+
bool $canBeShownInCategory,
146+
?array $expectedProductRewrite
147+
): void {
148+
$this->connectionMock->expects($this->any())
149149
->method('fetchRow')
150150
->will($this->onConsecutiveCalls($productFromDb, $categoryFromDb));
151151

@@ -158,11 +158,11 @@ public function testFindProductRewriteByRequestPath(
158158
]
159159
];
160160

161-
$this->scopeConfig
161+
$this->scopeConfigMock
162162
->method('getValue')
163163
->willReturnMap($scopeConfigMap);
164164

165-
$this->productResource
165+
$this->productResourceMock
166166
->method('canBeShowInCategory')
167167
->willReturn($canBeShownInCategory);
168168

@@ -185,9 +185,9 @@ public function findProductRewriteByRequestPathDataProvider(): array
185185
'store_id' => 1
186186
],
187187
false,
188+
'',
188189
null,
189-
null,
190-
null,
190+
true,
191191
null
192192
],
193193
[
@@ -205,7 +205,7 @@ public function findProductRewriteByRequestPathDataProvider(): array
205205
],
206206
'.html',
207207
false,
208-
null,
208+
true,
209209
null
210210
],
211211
[

0 commit comments

Comments
 (0)