Skip to content

Commit 70dc3ec

Browse files
ENGCOM-5810: Unit Test to Cover Magento_Version Module #24514
- Merge Pull Request #24514 from edenduong/magento2:2.3-testcover/version_module_controller_cover - Merged commits: 1. deebd85 2. 80fc9b8
2 parents 004da75 + 80fc9b8 commit 70dc3ec

File tree

1 file changed

+97
-0
lines changed

1 file changed

+97
-0
lines changed
Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
declare(strict_types=1);
7+
8+
namespace Magento\Version\Test\Unit\Controller\Index;
9+
10+
use Magento\Version\Controller\Index\Index as VersionIndex;
11+
use Magento\Framework\App\Action\Context;
12+
use Magento\Framework\App\ProductMetadataInterface;
13+
use Magento\Framework\App\ResponseInterface;
14+
use Magento\Framework\TestFramework\Unit\Helper\ObjectManager;
15+
16+
/**
17+
* Class \Magento\Version\Test\Unit\Controller\Index\IndexTest
18+
*/
19+
class IndexTest extends \PHPUnit\Framework\TestCase
20+
{
21+
/**
22+
* @var VersionIndex
23+
*/
24+
private $model;
25+
26+
/**
27+
* @var Context
28+
*/
29+
private $context;
30+
31+
/**
32+
* @var ProductMetadataInterface
33+
*/
34+
private $productMetadata;
35+
36+
/**
37+
* @var ResponseInterface
38+
*/
39+
private $response;
40+
41+
/**
42+
* Prepare test preconditions
43+
*/
44+
protected function setUp()
45+
{
46+
$this->context = $this->getMockBuilder(Context::class)
47+
->disableOriginalConstructor()
48+
->getMock();
49+
50+
$this->productMetadata = $this->getMockBuilder(ProductMetadataInterface::class)
51+
->disableOriginalConstructor()
52+
->setMethods(['getName', 'getEdition', 'getVersion'])
53+
->getMock();
54+
55+
$this->response = $this->getMockBuilder(ResponseInterface::class)
56+
->disableOriginalConstructor()
57+
->setMethods(['setBody', 'sendResponse'])
58+
->getMock();
59+
60+
$this->context->expects($this->any())
61+
->method('getResponse')
62+
->willReturn($this->response);
63+
64+
$helper = new ObjectManager($this);
65+
66+
$this->model = $helper->getObject(
67+
'Magento\Version\Controller\Index\Index',
68+
[
69+
'context' => $this->context,
70+
'productMetadata' => $this->productMetadata
71+
]
72+
);
73+
}
74+
75+
/**
76+
* Test with Git Base version
77+
*/
78+
public function testExecuteWithGitBase()
79+
{
80+
$this->productMetadata->expects($this->any())->method('getVersion')->willReturn('dev-2.3');
81+
$this->assertNull($this->model->execute());
82+
}
83+
84+
/**
85+
* Test with Community Version
86+
*/
87+
public function testExecuteWithCommunityVersion()
88+
{
89+
$this->productMetadata->expects($this->any())->method('getVersion')->willReturn('2.3.3');
90+
$this->productMetadata->expects($this->any())->method('getEdition')->willReturn('Community');
91+
$this->productMetadata->expects($this->any())->method('getName')->willReturn('Magento');
92+
$this->response->expects($this->once())->method('setBody')
93+
->with('Magento/2.3 (Community)')
94+
->will($this->returnSelf());
95+
$this->model->execute();
96+
}
97+
}

0 commit comments

Comments
 (0)