Skip to content

Commit 4e4e2f6

Browse files
authored
ENGCOM-7178: Implement ActionInterface for /robots/index/index #27393
2 parents e33f0b7 + 74d5b4d commit 4e4e2f6

File tree

2 files changed

+28
-29
lines changed

2 files changed

+28
-29
lines changed

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

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

8-
use Magento\Framework\App\Action\Action;
9-
use Magento\Framework\App\Action\Context;
10+
use Magento\Framework\App\Action\HttpGetActionInterface;
1011
use Magento\Framework\View\Result\Page;
1112
use Magento\Framework\View\Result\PageFactory;
1213

1314
/**
1415
* Processes request to robots.txt file and returns robots.txt content as result
1516
*/
16-
class Index extends Action
17+
class Index implements HttpGetActionInterface
1718
{
1819
/**
1920
* @var PageFactory
2021
*/
2122
private $resultPageFactory;
2223

2324
/**
24-
* @param Context $context
2525
* @param PageFactory $resultPageFactory
2626
*/
2727
public function __construct(
28-
Context $context,
2928
PageFactory $resultPageFactory
3029
) {
3130
$this->resultPageFactory = $resultPageFactory;
32-
33-
parent::__construct($context);
3431
}
3532

3633
/**
@@ -44,6 +41,7 @@ public function execute()
4441
$resultPage = $this->resultPageFactory->create(true);
4542
$resultPage->addHandle('robots_index_index');
4643
$resultPage->setHeader('Content-Type', 'text/plain');
44+
4745
return $resultPage;
4846
}
4947
}

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

Lines changed: 23 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -3,40 +3,42 @@
33
* Copyright © Magento, Inc. All rights reserved.
44
* See COPYING.txt for license details.
55
*/
6+
declare(strict_types=1);
67

78
namespace Magento\Robots\Test\Unit\Controller\Index;
89

9-
class IndexTest extends \PHPUnit\Framework\TestCase
10+
use Magento\Framework\TestFramework\Unit\Helper\ObjectManager;
11+
use Magento\Framework\View\Result\Page;
12+
use Magento\Framework\View\Result\PageFactory;
13+
use Magento\Robots\Controller\Index\Index;
14+
use PHPUnit\Framework\MockObject\MockObject;
15+
use PHPUnit\Framework\TestCase;
16+
17+
class IndexTest extends TestCase
1018
{
1119
/**
12-
* @var \Magento\Framework\App\Action\Context|\PHPUnit_Framework_MockObject_MockObject
20+
* @var Index
1321
*/
14-
private $contextMock;
22+
private $controller;
1523

1624
/**
17-
* @var \Magento\Framework\Controller\Result\RawFactory|\PHPUnit_Framework_MockObject_MockObject
25+
* @var PageFactory|MockObject
1826
*/
19-
private $resultPageFactory;
20-
21-
/**
22-
* @var \Magento\Robots\Controller\Index\Index
23-
*/
24-
private $controller;
27+
private $resultPageFactoryMock;
2528

2629
protected function setUp()
2730
{
28-
$this->contextMock = $this->getMockBuilder(\Magento\Framework\App\Action\Context::class)
29-
->disableOriginalConstructor()
30-
->getMock();
31-
32-
$this->resultPageFactory = $this->getMockBuilder(\Magento\Framework\View\Result\PageFactory::class)
31+
$this->resultPageFactoryMock = $this->getMockBuilder(PageFactory::class)
3332
->disableOriginalConstructor()
3433
->setMethods(['create'])
3534
->getMock();
3635

37-
$this->controller = new \Magento\Robots\Controller\Index\Index(
38-
$this->contextMock,
39-
$this->resultPageFactory
36+
$objectManager = new ObjectManager($this);
37+
$this->controller = $objectManager->getObject(
38+
Index::class,
39+
[
40+
'resultPageFactory' => $this->resultPageFactoryMock
41+
]
4042
);
4143
}
4244

@@ -45,7 +47,7 @@ protected function setUp()
4547
*/
4648
public function testExecute()
4749
{
48-
$resultPageMock = $this->getMockBuilder(\Magento\Framework\View\Result\Page::class)
50+
$resultPageMock = $this->getMockBuilder(Page::class)
4951
->disableOriginalConstructor()
5052
->getMock();
5153
$resultPageMock->expects($this->once())
@@ -55,13 +57,12 @@ public function testExecute()
5557
->method('setHeader')
5658
->with('Content-Type', 'text/plain');
5759

58-
$this->resultPageFactory->expects($this->any())
59-
->method('create')
60+
$this->resultPageFactoryMock->method('create')
6061
->with(true)
6162
->willReturn($resultPageMock);
6263

6364
$this->assertInstanceOf(
64-
\Magento\Framework\View\Result\Page::class,
65+
Page::class,
6566
$this->controller->execute()
6667
);
6768
}

0 commit comments

Comments
 (0)