forked from magento/magento2
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathIndexTest.php
110 lines (87 loc) · 3.72 KB
/
IndexTest.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
<?php
/**
* Copyright 2019 Adobe
* All Rights Reserved.
*/
declare(strict_types=1);
namespace Magento\Version\Test\Unit\Controller\Index;
use Magento\Framework\App\Action\Context;
use Magento\Framework\App\ProductMetadataInterface;
use Magento\Framework\App\State as AppState;
use Magento\Framework\Controller\Result\Raw;
use Magento\Framework\Controller\Result\RawFactory;
use Magento\Version\Controller\Index\Index as VersionIndex;
use PHPUnit\Framework\MockObject\MockObject;
use PHPUnit\Framework\TestCase;
class IndexTest extends TestCase
{
/** @var VersionIndex */
private $versionController;
/** @var MockObject|ProductMetadataInterface */
private $productMetadataMock;
/** @var MockObject|AppState */
private $appStateMock;
/** @var MockObject|RawFactory */
private $rawResponseFactoryMock;
/** @var MockObject|Raw */
private $rawResponseMock;
/** @var MockObject|Context */
private $contextMock;
/**
* Prepare test preconditions
*/
protected function setUp(): void
{
$this->contextMock = $this->createMock(Context::class);
$this->productMetadataMock = $this->getMockBuilder(ProductMetadataInterface::class)
->disableOriginalConstructor()
->onlyMethods(['getName', 'getEdition', 'getVersion'])
->getMockForAbstractClass();
$this->appStateMock = $this->createMock(AppState::class);
$this->rawResponseFactoryMock = $this->createPartialMock(RawFactory::class, ['create']);
$this->rawResponseMock = $this->createPartialMock(Raw::class, ['setContents']);
$this->rawResponseFactoryMock->method('create')->willReturn($this->rawResponseMock);
$this->versionController = new VersionIndex(
$this->contextMock,
$this->rawResponseFactoryMock,
$this->productMetadataMock,
$this->appStateMock
);
}
/**
* Git Base version does not return information about version
*/
public function testGitBasedInstallationDoesNotReturnVersion(): void
{
$this->productMetadataMock->expects($this->any())
->method('getVersion')
->willReturn('dev-2.3');
$this->rawResponseMock->expects($this->never())
->method('setContents');
$this->versionController->execute();
}
/**
* Magento Community returns information about major and minor version of product
*/
public function testCommunityVersionDisplaysMajorMinorVersionAndEditionName(): void
{
$this->productMetadataMock->expects($this->any())->method('getVersion')->willReturn('2.3.3');
$this->productMetadataMock->expects($this->any())->method('getEdition')->willReturn('Community');
$this->productMetadataMock->expects($this->any())->method('getName')->willReturn('Magento');
$this->rawResponseMock->expects($this->once())->method('setContents')
->with('Magento/2.3 (Community)')
->willReturnSelf();
$this->versionController->execute();
}
public function testCommunityVersionDisplaysMajorMinorVersionAndEditionNameProductionMode(): void
{
$this->productMetadataMock->expects($this->any())->method('getVersion')->willReturn('2.3.3');
$this->productMetadataMock->expects($this->any())->method('getEdition')->willReturn('Community');
$this->productMetadataMock->expects($this->any())->method('getName')->willReturn('Magento');
$this->appStateMock->expects($this->any())->method('getMode')->willReturn(AppState::MODE_PRODUCTION);
$this->rawResponseMock->expects($this->once())->method('setContents')
->with('Magento')
->willReturnSelf();
$this->versionController->execute();
}
}