Skip to content

Commit 5000cd9

Browse files
committed
#CoreReview Improve test readability with const STUB and extracting assertions, using Phrase placeholder
1 parent 1c6a7a3 commit 5000cd9

File tree

1 file changed

+28
-7
lines changed

1 file changed

+28
-7
lines changed

dev/tests/integration/testsuite/Magento/Catalog/Controller/Adminhtml/Category/Delete/DeleteCategoryWithEnabledFlatTest.php

Lines changed: 28 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@
2424
*/
2525
class DeleteCategoryWithEnabledFlatTest extends AbstractBackendController
2626
{
27+
const STUB_CATEGORY_ID = 333;
28+
2729
/**
2830
* @var IndexerRegistry
2931
*/
@@ -79,13 +81,16 @@ protected function tearDown()
7981
*/
8082
public function testDeleteCategory(): void
8183
{
82-
$this->assertEquals(1, $this->getFlatCategoryCollectionSizeByCategoryId(333));
83-
$this->getRequest()->setMethod(HttpRequest::METHOD_POST);
84-
$this->getRequest()->setPostValue(['id' => 333]);
85-
$this->dispatch('backend/catalog/category/delete');
84+
// Given
85+
$this->assertEquals(1, $this->getFlatCategoryCollectionSizeByCategoryId(self::STUB_CATEGORY_ID));
86+
87+
// When
88+
$this->sendDeleteCategoryRequest(self::STUB_CATEGORY_ID);
89+
90+
// Then
8691
$this->assertSessionMessages($this->equalTo([(string)__('You deleted the category.')]));
87-
$this->assertEquals(0, $this->getFlatCategoryCollectionSizeByCategoryId(333));
88-
$this->checkCategoryIsDeleted(333);
92+
$this->assertEquals(0, $this->getFlatCategoryCollectionSizeByCategoryId(self::STUB_CATEGORY_ID));
93+
$this->checkCategoryIsDeleted(self::STUB_CATEGORY_ID);
8994
}
9095

9196
/**
@@ -106,10 +111,26 @@ private function getFlatCategoryCollectionSizeByCategoryId(int $categoryId): int
106111
* Assert that category is deleted.
107112
*
108113
* @param int $categoryId
114+
* @return void
109115
*/
110116
private function checkCategoryIsDeleted(int $categoryId): void
111117
{
112-
$this->expectExceptionObject(new NoSuchEntityException(__("No such entity with id = {$categoryId}")));
118+
$this->expectExceptionObject(
119+
new NoSuchEntityException(__("No such entity with id = %entityId", ['entityId' => $categoryId]))
120+
);
113121
$this->categoryRepository->get($categoryId);
114122
}
123+
124+
/**
125+
* Method passes the request to Backend to remove given category.
126+
*
127+
* @param int $categoryId
128+
* @return void
129+
*/
130+
private function sendDeleteCategoryRequest(int $categoryId): void
131+
{
132+
$this->getRequest()->setMethod(HttpRequest::METHOD_POST);
133+
$this->getRequest()->setPostValue(['id' => $categoryId]);
134+
$this->dispatch('backend/catalog/category/delete');
135+
}
115136
}

0 commit comments

Comments
 (0)