Skip to content

Commit 97fafb0

Browse files
ENGCOM-7199: Implement ActionInterface for /swagger/ #27427
- Merge Pull Request #27427 from lbajsarowicz/magento2:refactor/swagger-index - Merged commits: 1. 3d4a8bb 2. 5c433fe
2 parents 8ec21ff + 5c433fe commit 97fafb0

File tree

2 files changed

+27
-31
lines changed

2 files changed

+27
-31
lines changed

app/code/Magento/Swagger/Controller/Index/Index.php

Lines changed: 14 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -3,42 +3,38 @@
33
* Copyright © Magento, Inc. All rights reserved.
44
* See COPYING.txt for license details.
55
*/
6+
declare(strict_types=1);
7+
68
namespace Magento\Swagger\Controller\Index;
79

8-
/**
9-
* Class Index
10-
*
11-
* @package Magento\Swagger\Controller\Index
12-
*/
13-
class Index extends \Magento\Framework\App\Action\Action
10+
use Magento\Framework\App\Action\HttpGetActionInterface;
11+
use Magento\Framework\View\Page\Config as PageConfig;
12+
use Magento\Framework\View\Result\PageFactory as PageFactory;
13+
14+
class Index implements HttpGetActionInterface
1415
{
1516
/**
16-
* @var \Magento\Framework\View\Page\Config
17+
* @var PageConfig
1718
*/
1819
private $pageConfig;
1920

2021
/**
21-
* @var \Magento\Framework\View\Result\PageFactory
22+
* @var PageFactory
2223
*/
2324
private $pageFactory;
2425

2526
/**
26-
* @param \Magento\Framework\App\Action\Context $context
27-
* @param \Magento\Framework\View\Page\Config $pageConfig
28-
* @param \Magento\Framework\View\Result\PageFactory $pageFactory
27+
* @param PageConfig $pageConfig
28+
* @param PageFactory $pageFactory
2929
*/
30-
public function __construct(
31-
\Magento\Framework\App\Action\Context $context,
32-
\Magento\Framework\View\Page\Config $pageConfig,
33-
\Magento\Framework\View\Result\PageFactory $pageFactory
34-
) {
35-
parent::__construct($context);
30+
public function __construct(PageConfig $pageConfig, PageFactory $pageFactory)
31+
{
3632
$this->pageConfig = $pageConfig;
3733
$this->pageFactory = $pageFactory;
3834
}
3935

4036
/**
41-
* @return \Magento\Framework\View\Result\Page
37+
* @inheritDoc
4238
*/
4339
public function execute()
4440
{

app/code/Magento/Swagger/Test/Unit/Controller/Index/IndexTest.php

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -8,29 +8,29 @@
88

99
namespace Magento\Swagger\Test\Unit\Controller\Index;
1010

11-
class IndexTest extends \PHPUnit\Framework\TestCase
11+
use Magento\Framework\View\Page\Config as PageConfig;
12+
use Magento\Framework\View\Result\PageFactory;
13+
use Magento\Swagger\Controller\Index\Index;
14+
use PHPUnit\Framework\MockObject\MockObject;
15+
use PHPUnit\Framework\TestCase;
16+
17+
class IndexTest extends TestCase
1218
{
1319
public function testExecute()
1420
{
15-
$objectManager = new \Magento\Framework\TestFramework\Unit\Helper\ObjectManager($this);
16-
17-
$pageConfigMock = $this->getMockBuilder(\Magento\Framework\View\Page\Config::class)
21+
/** @var MockObject|PageConfig $pageConfigMock */
22+
$pageConfigMock = $this->getMockBuilder(PageConfig::class)
1823
->disableOriginalConstructor()
1924
->getMock();
20-
$resultPageFactory = $this->getMockBuilder(\Magento\Framework\View\Result\PageFactory::class)
25+
/** @var MockObject|PageFactory $resultPageFactory */
26+
$resultPageFactory = $this->getMockBuilder(PageFactory::class)
2127
->disableOriginalConstructor()
2228
->getMock();
2329

2430
$pageConfigMock->expects($this->once())->method('addBodyClass')->with('swagger-section');
2531
$resultPageFactory->expects($this->once())->method('create');
2632

27-
$model = $objectManager->getObject(
28-
\Magento\Swagger\Controller\Index\Index::class,
29-
[
30-
'pageConfig' => $pageConfigMock,
31-
'pageFactory' => $resultPageFactory
32-
]
33-
);
34-
$model->execute();
33+
$indexAction = new Index($pageConfigMock, $resultPageFactory);
34+
$indexAction->execute();
3535
}
3636
}

0 commit comments

Comments
 (0)