Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement ActionInterface for /swagger/ #27427

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 14 additions & 18 deletions app/code/Magento/Swagger/Controller/Index/Index.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,42 +3,38 @@
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
declare(strict_types=1);

namespace Magento\Swagger\Controller\Index;

/**
* Class Index
*
* @package Magento\Swagger\Controller\Index
*/
class Index extends \Magento\Framework\App\Action\Action
use Magento\Framework\App\Action\HttpGetActionInterface;
use Magento\Framework\View\Page\Config as PageConfig;
use Magento\Framework\View\Result\PageFactory as PageFactory;

class Index implements HttpGetActionInterface
{
/**
* @var \Magento\Framework\View\Page\Config
* @var PageConfig
*/
private $pageConfig;

/**
* @var \Magento\Framework\View\Result\PageFactory
* @var PageFactory
*/
private $pageFactory;

/**
* @param \Magento\Framework\App\Action\Context $context
* @param \Magento\Framework\View\Page\Config $pageConfig
* @param \Magento\Framework\View\Result\PageFactory $pageFactory
* @param PageConfig $pageConfig
* @param PageFactory $pageFactory
*/
public function __construct(
\Magento\Framework\App\Action\Context $context,
\Magento\Framework\View\Page\Config $pageConfig,
\Magento\Framework\View\Result\PageFactory $pageFactory
) {
parent::__construct($context);
public function __construct(PageConfig $pageConfig, PageFactory $pageFactory)
{
$this->pageConfig = $pageConfig;
$this->pageFactory = $pageFactory;
}

/**
* @return \Magento\Framework\View\Result\Page
* @inheritDoc
*/
public function execute()
{
Expand Down
26 changes: 13 additions & 13 deletions app/code/Magento/Swagger/Test/Unit/Controller/Index/IndexTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,29 +8,29 @@

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

class IndexTest extends \PHPUnit\Framework\TestCase
use Magento\Framework\View\Page\Config as PageConfig;
use Magento\Framework\View\Result\PageFactory;
use Magento\Swagger\Controller\Index\Index;
use PHPUnit\Framework\MockObject\MockObject;
use PHPUnit\Framework\TestCase;

class IndexTest extends TestCase
{
public function testExecute()
{
$objectManager = new \Magento\Framework\TestFramework\Unit\Helper\ObjectManager($this);

$pageConfigMock = $this->getMockBuilder(\Magento\Framework\View\Page\Config::class)
/** @var MockObject|PageConfig $pageConfigMock */
$pageConfigMock = $this->getMockBuilder(PageConfig::class)
->disableOriginalConstructor()
->getMock();
$resultPageFactory = $this->getMockBuilder(\Magento\Framework\View\Result\PageFactory::class)
/** @var MockObject|PageFactory $resultPageFactory */
$resultPageFactory = $this->getMockBuilder(PageFactory::class)
->disableOriginalConstructor()
->getMock();

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

$model = $objectManager->getObject(
\Magento\Swagger\Controller\Index\Index::class,
[
'pageConfig' => $pageConfigMock,
'pageFactory' => $resultPageFactory
]
);
$model->execute();
$indexAction = new Index($pageConfigMock, $resultPageFactory);
$indexAction->execute();
}
}