3
3
* Copyright © Magento, Inc. All rights reserved.
4
4
* See COPYING.txt for license details.
5
5
*/
6
+ declare (strict_types=1 );
6
7
7
8
namespace Magento \Robots \Test \Unit \Controller \Index ;
8
9
9
- class IndexTest extends \PHPUnit \Framework \TestCase
10
+ use Magento \Framework \TestFramework \Unit \Helper \ObjectManager ;
11
+ use Magento \Framework \View \Result \Page ;
12
+ use Magento \Framework \View \Result \PageFactory ;
13
+ use Magento \Robots \Controller \Index \Index ;
14
+ use PHPUnit \Framework \MockObject \MockObject ;
15
+ use PHPUnit \Framework \TestCase ;
16
+
17
+ class IndexTest extends TestCase
10
18
{
11
19
/**
12
- * @var \Magento\Framework\App\Action\Context|\PHPUnit_Framework_MockObject_MockObject
20
+ * @var Index
13
21
*/
14
- private $ contextMock ;
22
+ private $ controller ;
15
23
16
24
/**
17
- * @var \Magento\Framework\Controller\Result\RawFactory|\PHPUnit_Framework_MockObject_MockObject
25
+ * @var PageFactory|MockObject
18
26
*/
19
- private $ resultPageFactory ;
20
-
21
- /**
22
- * @var \Magento\Robots\Controller\Index\Index
23
- */
24
- private $ controller ;
27
+ private $ resultPageFactoryMock ;
25
28
26
29
protected function setUp ()
27
30
{
28
- $ this ->contextMock = $ this ->getMockBuilder (\Magento \Framework \App \Action \Context::class)
29
- ->disableOriginalConstructor ()
30
- ->getMock ();
31
-
32
- $ this ->resultPageFactory = $ this ->getMockBuilder (\Magento \Framework \View \Result \PageFactory::class)
31
+ $ this ->resultPageFactoryMock = $ this ->getMockBuilder (PageFactory::class)
33
32
->disableOriginalConstructor ()
34
33
->setMethods (['create ' ])
35
34
->getMock ();
36
35
37
- $ this ->controller = new \Magento \Robots \Controller \Index \Index (
38
- $ this ->contextMock ,
39
- $ this ->resultPageFactory
36
+ $ objectManager = new ObjectManager ($ this );
37
+ $ this ->controller = $ objectManager ->getObject (
38
+ Index::class,
39
+ [
40
+ 'resultPageFactory ' => $ this ->resultPageFactoryMock
41
+ ]
40
42
);
41
43
}
42
44
@@ -45,7 +47,7 @@ protected function setUp()
45
47
*/
46
48
public function testExecute ()
47
49
{
48
- $ resultPageMock = $ this ->getMockBuilder (\ Magento \ Framework \ View \ Result \ Page::class)
50
+ $ resultPageMock = $ this ->getMockBuilder (Page::class)
49
51
->disableOriginalConstructor ()
50
52
->getMock ();
51
53
$ resultPageMock ->expects ($ this ->once ())
@@ -55,13 +57,12 @@ public function testExecute()
55
57
->method ('setHeader ' )
56
58
->with ('Content-Type ' , 'text/plain ' );
57
59
58
- $ this ->resultPageFactory ->expects ($ this ->any ())
59
- ->method ('create ' )
60
+ $ this ->resultPageFactoryMock ->method ('create ' )
60
61
->with (true )
61
62
->willReturn ($ resultPageMock );
62
63
63
64
$ this ->assertInstanceOf (
64
- \ Magento \ Framework \ View \ Result \ Page::class,
65
+ Page::class,
65
66
$ this ->controller ->execute ()
66
67
);
67
68
}
0 commit comments