6
6
7
7
namespace Magento \ConfigurableProduct \Test \Unit \Controller \Adminhtml \Product ;
8
8
9
+ use Magento \Framework \Controller \ResultFactory ;
9
10
use Magento \Framework \TestFramework \Unit \Helper \ObjectManager as ObjectManagerHelper ;
10
11
11
12
class AddAttributeTest extends \PHPUnit_Framework_TestCase
12
13
{
14
+ /** @var \Magento\Framework\Controller\ResultFactory|\PHPUnit_Framework_MockObject_MockObject */
15
+ private $ resultFactory ;
16
+
13
17
/** @var \Magento\ConfigurableProduct\Controller\Adminhtml\Product\AddAttribute */
14
18
protected $ controller ;
15
19
@@ -45,35 +49,39 @@ protected function setUp()
45
49
{
46
50
$ this ->objectManagerHelper = new ObjectManagerHelper ($ this );
47
51
48
- $ this ->context = $ this ->getMockBuilder (' \Magento\Backend\App\Action\Context ' )
52
+ $ this ->context = $ this ->getMockBuilder (\Magento \Backend \App \Action \Context::class )
49
53
->disableOriginalConstructor ()
50
54
->getMock ();
51
- $ this ->request = $ this ->getMock ('Magento\Framework\App\RequestInterface ' );
55
+ $ this ->request = $ this ->getMock (\Magento \Framework \App \RequestInterface::class);
56
+ $ this ->resultFactory = $ this ->getMock (\Magento \Framework \Controller \ResultFactory::class, [], [], '' , false );
52
57
$ this ->response = $ this ->getMock (
53
- ' \Magento\Framework\App\ResponseInterface ' ,
58
+ \Magento \Framework \App \ResponseInterface::class ,
54
59
[
55
60
'sendResponse ' ,
56
61
'setBody '
57
62
]
58
63
);
59
- $ this ->productBuilder = $ this ->getMockBuilder (' \Magento\Catalog\Controller\Adminhtml\Product\Builder ' )
64
+ $ this ->productBuilder = $ this ->getMockBuilder (\Magento \Catalog \Controller \Adminhtml \Product \Builder::class )
60
65
->disableOriginalConstructor ()
61
66
->setMethods (['build ' ])
62
67
->getMock ();
63
- $ this ->view = $ this ->getMock (' \Magento\Framework\App\ViewInterface ' );
68
+ $ this ->view = $ this ->getMock (\Magento \Framework \App \ViewInterface::class );
64
69
65
70
$ this ->context ->expects ($ this ->any ())
66
71
->method ('getRequest ' )
67
72
->will ($ this ->returnValue ($ this ->request ));
68
73
$ this ->context ->expects ($ this ->any ())
69
74
->method ('getResponse ' )
70
75
->will ($ this ->returnValue ($ this ->response ));
76
+ $ this ->context ->expects ($ this ->any ())
77
+ ->method ('getResultFactory ' )
78
+ ->will ($ this ->returnValue ($ this ->resultFactory ));
71
79
$ this ->context ->expects ($ this ->any ())
72
80
->method ('getView ' )
73
81
->will ($ this ->returnValue ($ this ->view ));
74
82
75
83
$ this ->controller = $ this ->objectManagerHelper ->getObject (
76
- ' \Magento\ConfigurableProduct\Controller\Adminhtml\Product\AddAttribute ' ,
84
+ \Magento \ConfigurableProduct \Controller \Adminhtml \Product \AddAttribute::class ,
77
85
[
78
86
'context ' => $ this ->context ,
79
87
'productBuilder ' => $ this ->productBuilder
@@ -83,22 +91,16 @@ protected function setUp()
83
91
84
92
public function testExecute ()
85
93
{
86
- $ product = $ this ->getMockBuilder (' \Magento\Catalog\Model\Product ' )
94
+ $ product = $ this ->getMockBuilder (\Magento \Catalog \Model \Product::class )
87
95
->disableOriginalConstructor ()
88
96
->setMethods (['_wakeup ' , 'getId ' ])
89
97
->getMock ();
90
- $ layout = $ this ->getMock ('\Magento\Framework\View\LayoutInterface ' );
91
- $ block = $ this ->getMockBuilder (
92
- 'Magento\ConfigurableProduct\Block\Adminhtml\Product\Attribute\NewAttribute\Product\Created '
93
- )
94
- ->disableOriginalConstructor ()
95
- ->setMethods (['setIndex ' , 'toHtml ' ])
96
- ->getMock ();
97
98
98
99
$ this ->productBuilder ->expects ($ this ->once ())->method ('build ' )->with ($ this ->request )->willReturn ($ product );
99
- $ this ->view ->expects ($ this ->once ())->method ('getLayout ' )->willReturn ($ layout );
100
- $ layout ->expects ($ this ->once ())->method ('createBlock ' )->willReturn ($ block );
100
+ $ resultLayout = $ this ->getMock (\Magento \Framework \View \Result \Layout::class, [], [], '' , false );
101
+ $ this ->resultFactory ->expects ($ this ->once ())->method ('create ' )->with (ResultFactory::TYPE_LAYOUT )
102
+ ->willReturn ($ resultLayout );
101
103
102
- $ this ->controller ->execute ();
104
+ $ this ->assertInstanceOf (\ Magento \ Framework \ View \ Result \Layout::class, $ this -> controller ->execute () );
103
105
}
104
106
}
0 commit comments