77
88namespace Magento \Version \Test \Unit \Controller \Index ;
99
10- use Magento \Version \Controller \Index \Index as VersionIndex ;
1110use Magento \Framework \App \Action \Context ;
1211use Magento \Framework \App \ProductMetadataInterface ;
1312use Magento \Framework \App \ResponseInterface ;
1413use Magento \Framework \TestFramework \Unit \Helper \ObjectManager ;
14+ use Magento \Version \Controller \Index \Index as VersionIndex ;
15+ use PHPUnit \Framework \TestCase ;
1516
16- /**
17- * Class \Magento\Version\Test\Unit\Controller\Index\IndexTest
18- */
19- class IndexTest extends \PHPUnit \Framework \TestCase
17+ class IndexTest extends TestCase
2018{
2119 /**
2220 * @var VersionIndex
@@ -26,72 +24,80 @@ class IndexTest extends \PHPUnit\Framework\TestCase
2624 /**
2725 * @var Context
2826 */
29- private $ context ;
27+ private $ contextMock ;
3028
3129 /**
3230 * @var ProductMetadataInterface
3331 */
34- private $ productMetadata ;
32+ private $ productMetadataMock ;
3533
3634 /**
3735 * @var ResponseInterface
3836 */
39- private $ response ;
37+ private $ responseMock ;
4038
4139 /**
4240 * Prepare test preconditions
4341 */
4442 protected function setUp ()
4543 {
46- $ this ->context = $ this ->getMockBuilder (Context::class)
44+ $ this ->contextMock = $ this ->getMockBuilder (Context::class)
4745 ->disableOriginalConstructor ()
4846 ->getMock ();
4947
50- $ this ->productMetadata = $ this ->getMockBuilder (ProductMetadataInterface::class)
48+ $ this ->productMetadataMock = $ this ->getMockBuilder (ProductMetadataInterface::class)
5149 ->disableOriginalConstructor ()
5250 ->setMethods (['getName ' , 'getEdition ' , 'getVersion ' ])
5351 ->getMock ();
5452
55- $ this ->response = $ this ->getMockBuilder (ResponseInterface::class)
53+ $ this ->responseMock = $ this ->getMockBuilder (ResponseInterface::class)
5654 ->disableOriginalConstructor ()
5755 ->setMethods (['setBody ' , 'sendResponse ' ])
5856 ->getMock ();
5957
60- $ this ->context ->expects ($ this ->any ())
58+ $ this ->contextMock ->expects ($ this ->any ())
6159 ->method ('getResponse ' )
62- ->willReturn ($ this ->response );
60+ ->willReturn ($ this ->responseMock );
6361
64- $ helper = new ObjectManager ($ this );
62+ $ objectManager = new ObjectManager ($ this );
6563
66- $ this ->model = $ helper ->getObject (
67- ' Magento\Version\Controller\Index\Index ' ,
64+ $ this ->model = $ objectManager ->getObject (
65+ VersionIndex::class ,
6866 [
69- 'context ' => $ this ->context ,
70- 'productMetadata ' => $ this ->productMetadata
67+ 'context ' => $ this ->contextMock ,
68+ 'productMetadata ' => $ this ->productMetadataMock
7169 ]
7270 );
7371 }
7472
7573 /**
76- * Test with Git Base version
74+ * Git Base version does not return information about version
7775 */
78- public function testExecuteWithGitBase ()
76+ public function testGitBasedInstallationDoesNotReturnVersion (): void
7977 {
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+
8185 $ this ->assertNull ($ this ->model ->execute ());
8286 }
8387
8488 /**
85- * Test with Community Version
89+ * Magento Community returns information about major and minor version of product
8690 */
87- public function testExecuteWithCommunityVersion ()
91+ public function testCommunityVersionDisplaysMajorMinorVersionAndEditionName (): void
8892 {
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 ' )
9398 ->with ('Magento/2.3 (Community) ' )
9499 ->will ($ this ->returnSelf ());
100+
95101 $ this ->model ->execute ();
96102 }
97103}
0 commit comments