4
4
* See COPYING.txt for license details.
5
5
*/
6
6
7
+ declare (strict_types=1 );
8
+
7
9
namespace Magento \Eav \Test \Unit \Model \Validator \Attribute ;
8
10
9
11
/**
@@ -21,11 +23,17 @@ class DataTest extends \PHPUnit\Framework\TestCase
21
23
*/
22
24
private $ model ;
23
25
26
+ /**
27
+ * @var \Magento\Framework\TestFramework\Unit\Helper\ObjectManager
28
+ */
29
+ private $ objectManager ;
30
+
24
31
/**
25
32
* @inheritdoc
26
33
*/
27
34
protected function setUp ()
28
35
{
36
+ $ this ->objectManager = new \Magento \Framework \TestFramework \Unit \Helper \ObjectManager ($ this );
29
37
$ this ->attrDataFactory = $ this ->getMockBuilder (\Magento \Eav \Model \AttributeDataFactory::class)
30
38
->setMethods (['create ' ])
31
39
->setConstructorArgs (
@@ -36,8 +44,11 @@ protected function setUp()
36
44
)
37
45
->getMock ();
38
46
39
- $ this ->model = new \Magento \Eav \Model \Validator \Attribute \Data (
40
- $ this ->attrDataFactory
47
+ $ this ->model = $ this ->objectManager ->getObject (
48
+ \Magento \Eav \Model \Validator \Attribute \Data::class,
49
+ [
50
+ '_attrDataFactory ' => $ this ->attrDataFactory
51
+ ]
41
52
);
42
53
}
43
54
@@ -468,7 +479,7 @@ protected function _getDataModelMock($returnValue, $argument = null)
468
479
$ dataModel = $ this ->getMockBuilder (
469
480
\Magento \Eav \Model \Attribute \Data \AbstractData::class
470
481
)->disableOriginalConstructor ()->setMethods (
471
- ['validateValue ' ]
482
+ ['setExtractedData ' , ' validateValue ' ]
472
483
)->getMockForAbstractClass ();
473
484
if ($ argument ) {
474
485
$ dataModel ->expects (
@@ -509,24 +520,13 @@ public function testIsValidWithoutData() : void
509
520
$ attributeData = ['attribute_code ' => 'attribute ' , 'frontend_input ' => 'text ' , 'is_visible ' => true ];
510
521
$ entity = $ this ->_getEntityMock ();
511
522
$ attribute = $ this ->_getAttributeMock ($ attributeData );
512
- $ this ->model ->setAttributes ([$ attribute ])->setData ([]);
513
- $ dataModel = $ this ->getMockBuilder (\Magento \Eav \Model \Attribute \Data \AbstractData::class)
514
- ->disableOriginalConstructor ()
515
- ->setMethods (['validateValue ' ])
516
- ->getMockForAbstractClass ();
517
- $ dataModel ->expects ($ this ->once ())
518
- ->method ('validateValue ' )
519
- // only empty string
520
- ->with (
521
- $ this ->logicalAnd (
522
- $ this ->isEmpty (),
523
- $ this ->isType ('string ' )
524
- )
525
- )->willReturn (true );
523
+ $ dataModel = $ this ->_getDataModelMock (true , $ this ->logicalAnd ($ this ->isEmpty (), $ this ->isType ('string ' )));
524
+ $ dataModel ->expects ($ this ->once ())->method ('setExtractedData ' )->with ([])->willReturnSelf ();
526
525
$ this ->attrDataFactory ->expects ($ this ->once ())
527
526
->method ('create ' )
528
527
->with ($ attribute , $ entity )
529
528
->willReturn ($ dataModel );
530
- $ this ->assertEquals (true , $ this ->model ->isValid ($ entity ));
529
+ $ this ->model ->setAttributes ([$ attribute ])->setData ([]);
530
+ $ this ->assertTrue ($ this ->model ->isValid ($ entity ));
531
531
}
532
532
}
0 commit comments