7
7
8
8
namespace Magento \Version \Test \Unit \Controller \Index ;
9
9
10
- use Magento \Version \Controller \Index \Index as VersionIndex ;
11
10
use Magento \Framework \App \Action \Context ;
12
11
use Magento \Framework \App \ProductMetadataInterface ;
13
12
use Magento \Framework \App \ResponseInterface ;
14
13
use Magento \Framework \TestFramework \Unit \Helper \ObjectManager ;
14
+ use Magento \Version \Controller \Index \Index as VersionIndex ;
15
+ use PHPUnit \Framework \TestCase ;
15
16
16
- /**
17
- * Class \Magento\Version\Test\Unit\Controller\Index\IndexTest
18
- */
19
- class IndexTest extends \PHPUnit \Framework \TestCase
17
+ class IndexTest extends TestCase
20
18
{
21
19
/**
22
20
* @var VersionIndex
@@ -26,72 +24,80 @@ class IndexTest extends \PHPUnit\Framework\TestCase
26
24
/**
27
25
* @var Context
28
26
*/
29
- private $ context ;
27
+ private $ contextMock ;
30
28
31
29
/**
32
30
* @var ProductMetadataInterface
33
31
*/
34
- private $ productMetadata ;
32
+ private $ productMetadataMock ;
35
33
36
34
/**
37
35
* @var ResponseInterface
38
36
*/
39
- private $ response ;
37
+ private $ responseMock ;
40
38
41
39
/**
42
40
* Prepare test preconditions
43
41
*/
44
42
protected function setUp ()
45
43
{
46
- $ this ->context = $ this ->getMockBuilder (Context::class)
44
+ $ this ->contextMock = $ this ->getMockBuilder (Context::class)
47
45
->disableOriginalConstructor ()
48
46
->getMock ();
49
47
50
- $ this ->productMetadata = $ this ->getMockBuilder (ProductMetadataInterface::class)
48
+ $ this ->productMetadataMock = $ this ->getMockBuilder (ProductMetadataInterface::class)
51
49
->disableOriginalConstructor ()
52
50
->setMethods (['getName ' , 'getEdition ' , 'getVersion ' ])
53
51
->getMock ();
54
52
55
- $ this ->response = $ this ->getMockBuilder (ResponseInterface::class)
53
+ $ this ->responseMock = $ this ->getMockBuilder (ResponseInterface::class)
56
54
->disableOriginalConstructor ()
57
55
->setMethods (['setBody ' , 'sendResponse ' ])
58
56
->getMock ();
59
57
60
- $ this ->context ->expects ($ this ->any ())
58
+ $ this ->contextMock ->expects ($ this ->any ())
61
59
->method ('getResponse ' )
62
- ->willReturn ($ this ->response );
60
+ ->willReturn ($ this ->responseMock );
63
61
64
- $ helper = new ObjectManager ($ this );
62
+ $ objectManager = new ObjectManager ($ this );
65
63
66
- $ this ->model = $ helper ->getObject (
67
- ' Magento\Version\Controller\Index\Index ' ,
64
+ $ this ->model = $ objectManager ->getObject (
65
+ VersionIndex::class ,
68
66
[
69
- 'context ' => $ this ->context ,
70
- 'productMetadata ' => $ this ->productMetadata
67
+ 'context ' => $ this ->contextMock ,
68
+ 'productMetadata ' => $ this ->productMetadataMock
71
69
]
72
70
);
73
71
}
74
72
75
73
/**
76
- * Test with Git Base version
74
+ * Git Base version does not return information about version
77
75
*/
78
- public function testExecuteWithGitBase ()
76
+ public function testGitBasedInstallationDoesNotReturnVersion (): void
79
77
{
80
- $ this ->productMetadata ->expects ($ this ->any ())->method ('getVersion ' )->willReturn ('dev-2.3 ' );
78
+ $ this ->productMetadataMock ->expects ($ this ->any ())
79
+ ->method ('getVersion ' )
80
+ ->willReturn ('dev-2.3 ' );
81
+
82
+ $ this ->responseMock ->expects ($ this ->never ())
83
+ ->method ('setBody ' );
84
+
81
85
$ this ->assertNull ($ this ->model ->execute ());
82
86
}
83
87
84
88
/**
85
- * Test with Community Version
89
+ * Magento Community returns information about major and minor version of product
86
90
*/
87
- public function testExecuteWithCommunityVersion ()
91
+ public function testCommunityVersionDisplaysMajorMinorVersionAndEditionName (): void
88
92
{
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
+ $ this ->productMetadataMock ->expects ($ this ->any ())->method ('getVersion ' )->willReturn ('2.3.3 ' );
94
+ $ this ->productMetadataMock ->expects ($ this ->any ())->method ('getEdition ' )->willReturn ('Community ' );
95
+ $ this ->productMetadataMock ->expects ($ this ->any ())->method ('getName ' )->willReturn ('Magento ' );
96
+
97
+ $ this ->responseMock ->expects ($ this ->once ())->method ('setBody ' )
93
98
->with ('Magento/2.3 (Community) ' )
94
99
->will ($ this ->returnSelf ());
100
+
95
101
$ this ->model ->execute ();
96
102
}
97
103
}
0 commit comments