Skip to content

Commit e849f39

Browse files
committed
Implement ActionInterface for /version/
1 parent 8ec21ff commit e849f39

File tree

2 files changed

+14
-34
lines changed

2 files changed

+14
-34
lines changed

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

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,31 +8,34 @@
88

99
namespace Magento\Version\Controller\Index;
1010

11-
use Magento\Framework\App\Action\Action;
12-
use Magento\Framework\App\Action\Context;
1311
use Magento\Framework\App\Action\HttpGetActionInterface as HttpGetActionInterface;
1412
use Magento\Framework\App\ProductMetadataInterface;
13+
use Magento\Framework\App\ResponseInterface;
1514

1615
/**
1716
* Magento Version controller
1817
*/
19-
class Index extends Action implements HttpGetActionInterface
18+
class Index implements HttpGetActionInterface
2019
{
2120
const DEV_PREFIX = 'dev-';
2221

2322
/**
2423
* @var ProductMetadataInterface
2524
*/
2625
protected $productMetadata;
26+
/**
27+
* @var ResponseInterface
28+
*/
29+
private $response;
2730

2831
/**
29-
* @param Context $context
32+
* @param ResponseInterface $response
3033
* @param ProductMetadataInterface $productMetadata
3134
*/
32-
public function __construct(Context $context, ProductMetadataInterface $productMetadata)
35+
public function __construct(ResponseInterface $response, ProductMetadataInterface $productMetadata)
3336
{
3437
$this->productMetadata = $productMetadata;
35-
parent::__construct($context);
38+
$this->response = $response;
3639
}
3740

3841
/**
@@ -48,7 +51,7 @@ public function execute(): void
4851
return;
4952
}
5053

51-
$this->getResponse()->setBody(
54+
$this->response->setBody(
5255
$this->productMetadata->getName() . '/' .
5356
$this->getMajorMinorVersion($versionParts) .
5457
' (' . $this->productMetadata->getEdition() . ')'

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

Lines changed: 4 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,8 @@
77

88
namespace Magento\Version\Test\Unit\Controller\Index;
99

10-
use Magento\Framework\App\Action\Context;
1110
use Magento\Framework\App\ProductMetadataInterface;
1211
use Magento\Framework\App\ResponseInterface;
13-
use Magento\Framework\TestFramework\Unit\Helper\ObjectManager;
1412
use Magento\Version\Controller\Index\Index as VersionIndex;
1513
use PHPUnit\Framework\TestCase;
1614

@@ -19,12 +17,7 @@ class IndexTest extends TestCase
1917
/**
2018
* @var VersionIndex
2119
*/
22-
private $model;
23-
24-
/**
25-
* @var Context
26-
*/
27-
private $contextMock;
20+
private $versionController;
2821

2922
/**
3023
* @var ProductMetadataInterface
@@ -41,10 +34,6 @@ class IndexTest extends TestCase
4134
*/
4235
protected function setUp()
4336
{
44-
$this->contextMock = $this->getMockBuilder(Context::class)
45-
->disableOriginalConstructor()
46-
->getMock();
47-
4837
$this->productMetadataMock = $this->getMockBuilder(ProductMetadataInterface::class)
4938
->disableOriginalConstructor()
5039
->setMethods(['getName', 'getEdition', 'getVersion'])
@@ -55,19 +44,7 @@ protected function setUp()
5544
->setMethods(['setBody', 'sendResponse'])
5645
->getMock();
5746

58-
$this->contextMock->expects($this->any())
59-
->method('getResponse')
60-
->willReturn($this->responseMock);
61-
62-
$objectManager = new ObjectManager($this);
63-
64-
$this->model = $objectManager->getObject(
65-
VersionIndex::class,
66-
[
67-
'context' => $this->contextMock,
68-
'productMetadata' => $this->productMetadataMock
69-
]
70-
);
47+
$this->versionController = new VersionIndex($this->responseMock, $this->productMetadataMock);
7148
}
7249

7350
/**
@@ -82,7 +59,7 @@ public function testGitBasedInstallationDoesNotReturnVersion(): void
8259
$this->responseMock->expects($this->never())
8360
->method('setBody');
8461

85-
$this->assertNull($this->model->execute());
62+
$this->assertNull($this->versionController->execute());
8663
}
8764

8865
/**
@@ -98,6 +75,6 @@ public function testCommunityVersionDisplaysMajorMinorVersionAndEditionName(): v
9875
->with('Magento/2.3 (Community)')
9976
->will($this->returnSelf());
10077

101-
$this->model->execute();
78+
$this->versionController->execute();
10279
}
10380
}

0 commit comments

Comments
 (0)