Skip to content

Commit a67d063

Browse files
committed
Fix failing Integration test
1 parent e849f39 commit a67d063

File tree

2 files changed

+39
-40
lines changed

2 files changed

+39
-40
lines changed

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

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,18 @@
11
<?php
22
/**
3-
*
43
* Copyright © Magento, Inc. All rights reserved.
54
* See COPYING.txt for license details.
65
*/
76
declare(strict_types=1);
87

98
namespace Magento\Version\Controller\Index;
109

11-
use Magento\Framework\App\Action\HttpGetActionInterface as HttpGetActionInterface;
10+
use Magento\Framework\App\Action\HttpGetActionInterface;
1211
use Magento\Framework\App\ProductMetadataInterface;
13-
use Magento\Framework\App\ResponseInterface;
12+
use Magento\Framework\Controller\Result\RawFactory as RawResponseFactory;
1413

1514
/**
16-
* Magento Version controller
15+
* Magento Version controller: Sets the response body to ProductName/Major.MinorVersion (Edition).
1716
*/
1817
class Index implements HttpGetActionInterface
1918
{
@@ -22,40 +21,41 @@ class Index implements HttpGetActionInterface
2221
/**
2322
* @var ProductMetadataInterface
2423
*/
25-
protected $productMetadata;
24+
private $productMetadata;
25+
2626
/**
27-
* @var ResponseInterface
27+
* @var RawResponseFactory
2828
*/
29-
private $response;
29+
private $rawFactory;
3030

3131
/**
32-
* @param ResponseInterface $response
32+
* @param RawResponseFactory $rawFactory
3333
* @param ProductMetadataInterface $productMetadata
3434
*/
35-
public function __construct(ResponseInterface $response, ProductMetadataInterface $productMetadata)
35+
public function __construct(RawResponseFactory $rawFactory, ProductMetadataInterface $productMetadata)
3636
{
37+
$this->rawFactory = $rawFactory;
3738
$this->productMetadata = $productMetadata;
38-
$this->response = $response;
3939
}
4040

4141
/**
42-
* Sets the response body to ProductName/Major.MinorVersion (Edition).
43-
*
44-
* @return void
42+
* @inheritDoc
4543
*/
46-
public function execute(): void
44+
public function execute()
4745
{
46+
$rawResponse = $this->rawFactory->create();
47+
4848
$version = $this->productMetadata->getVersion();
4949
$versionParts = explode('.', $version);
50-
if ($this->isGitBasedInstallation($version) || !$this->isCorrectVersion($versionParts)) {
51-
return;
50+
if (!$this->isGitBasedInstallation($version) && $this->isCorrectVersion($versionParts)) {
51+
$rawResponse->setContents(
52+
$this->productMetadata->getName() . '/' .
53+
$this->getMajorMinorVersion($versionParts) .
54+
' (' . $this->productMetadata->getEdition() . ')'
55+
);
5256
}
5357

54-
$this->response->setBody(
55-
$this->productMetadata->getName() . '/' .
56-
$this->getMajorMinorVersion($versionParts) .
57-
' (' . $this->productMetadata->getEdition() . ')'
58-
);
58+
return $rawResponse;
5959
}
6060

6161
/**

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

Lines changed: 18 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -9,25 +9,25 @@
99

1010
use Magento\Framework\App\ProductMetadataInterface;
1111
use Magento\Framework\App\ResponseInterface;
12+
use Magento\Framework\Controller\Result\Raw;
13+
use Magento\Framework\Controller\Result\RawFactory;
1214
use Magento\Version\Controller\Index\Index as VersionIndex;
15+
use PHPUnit\Framework\MockObject\MockObject;
1316
use PHPUnit\Framework\TestCase;
1417

1518
class IndexTest extends TestCase
1619
{
17-
/**
18-
* @var VersionIndex
19-
*/
20+
/** @var VersionIndex */
2021
private $versionController;
2122

22-
/**
23-
* @var ProductMetadataInterface
24-
*/
23+
/** @var MockObject|ProductMetadataInterface */
2524
private $productMetadataMock;
2625

27-
/**
28-
* @var ResponseInterface
29-
*/
30-
private $responseMock;
26+
/** @var MockObject|RawFactory */
27+
private $rawResponseFactoryMock;
28+
29+
/** @var MockObject|Raw */
30+
private $rawResponseMock;
3131

3232
/**
3333
* Prepare test preconditions
@@ -39,12 +39,11 @@ protected function setUp()
3939
->setMethods(['getName', 'getEdition', 'getVersion'])
4040
->getMock();
4141

42-
$this->responseMock = $this->getMockBuilder(ResponseInterface::class)
43-
->disableOriginalConstructor()
44-
->setMethods(['setBody', 'sendResponse'])
45-
->getMock();
42+
$this->rawResponseFactoryMock = $this->createPartialMock(RawFactory::class, ['create']);
43+
$this->rawResponseMock = $this->createPartialMock(Raw::class, ['setContents']);
44+
$this->rawResponseFactoryMock->method('create')->willReturn($this->rawResponseMock);
4645

47-
$this->versionController = new VersionIndex($this->responseMock, $this->productMetadataMock);
46+
$this->versionController = new VersionIndex($this->rawResponseFactoryMock, $this->productMetadataMock);
4847
}
4948

5049
/**
@@ -56,10 +55,10 @@ public function testGitBasedInstallationDoesNotReturnVersion(): void
5655
->method('getVersion')
5756
->willReturn('dev-2.3');
5857

59-
$this->responseMock->expects($this->never())
60-
->method('setBody');
58+
$this->rawResponseMock->expects($this->never())
59+
->method('setContents');
6160

62-
$this->assertNull($this->versionController->execute());
61+
$this->versionController->execute();
6362
}
6463

6564
/**
@@ -71,7 +70,7 @@ public function testCommunityVersionDisplaysMajorMinorVersionAndEditionName(): v
7170
$this->productMetadataMock->expects($this->any())->method('getEdition')->willReturn('Community');
7271
$this->productMetadataMock->expects($this->any())->method('getName')->willReturn('Magento');
7372

74-
$this->responseMock->expects($this->once())->method('setBody')
73+
$this->rawResponseMock->expects($this->once())->method('setContents')
7574
->with('Magento/2.3 (Community)')
7675
->will($this->returnSelf());
7776

0 commit comments

Comments
 (0)