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