1212use Magento \ConfigurableProduct \Model \ResourceModel \Product \Type \Configurable \Attribute ;
1313use Magento \Eav \Model \Entity \Attribute \AbstractAttribute ;
1414use Magento \Eav \Model \Entity \Attribute \Source \AbstractSource ;
15- use Magento \Framework \App \ScopeInterface ;
16- use Magento \Framework \App \ScopeResolverInterface ;
1715use Magento \Framework \DB \Adapter \AdapterInterface ;
1816use Magento \Framework \DB \Select ;
19- use Magento \Framework \TestFramework \Unit \Helper \ObjectManager as ObjectManagerHelper ;
2017use PHPUnit \Framework \MockObject \MockObject ;
2118use PHPUnit \Framework \TestCase ;
2219
@@ -30,16 +27,6 @@ class AttributeOptionProviderTest extends TestCase
3027 */
3128 private $ model ;
3229
33- /**
34- * @var ObjectManagerHelper
35- */
36- private $ objectManagerHelper ;
37-
38- /**
39- * @var ScopeResolverInterface|MockObject
40- */
41- private $ scopeResolver ;
42-
4330 /**
4431 * @var Select|MockObject
4532 */
@@ -55,11 +42,6 @@ class AttributeOptionProviderTest extends TestCase
5542 */
5643 private $ abstractAttribute ;
5744
58- /**
59- * @var ScopeInterface|MockObject
60- */
61- private $ scope ;
62-
6345 /**
6446 * @var Attribute|MockObject
6547 */
@@ -72,45 +54,13 @@ class AttributeOptionProviderTest extends TestCase
7254
7355 protected function setUp (): void
7456 {
75- $ this ->select = $ this ->getMockBuilder (Select::class)
76- ->setMethods ([])
77- ->disableOriginalConstructor ()
78- ->getMock ();
79-
80- $ this ->connectionMock = $ this ->getMockBuilder (AdapterInterface::class)
81- ->disableOriginalConstructor ()
82- ->getMockForAbstractClass ();
57+ $ this ->select = $ this ->createMock (Select::class);
58+ $ this ->connectionMock = $ this ->createMock (AdapterInterface::class);
59+ $ this ->attributeResource = $ this ->createMock (Attribute::class);
60+ $ this ->optionSelectBuilder = $ this ->createMock (OptionSelectBuilderInterface::class);
61+ $ this ->abstractAttribute = $ this ->createMock (AbstractAttribute::class);
8362
84- $ this ->scope = $ this ->getMockBuilder (ScopeInterface::class)
85- ->disableOriginalConstructor ()
86- ->getMockForAbstractClass ();
87-
88- $ this ->scopeResolver = $ this ->getMockBuilder (ScopeResolverInterface::class)
89- ->disableOriginalConstructor ()
90- ->getMockForAbstractClass ();
91-
92- $ this ->attributeResource = $ this ->getMockBuilder (Attribute::class)
93- ->disableOriginalConstructor ()
94- ->getMock ();
95-
96- $ this ->optionSelectBuilder = $ this ->getMockBuilder (OptionSelectBuilderInterface::class)
97- ->disableOriginalConstructor ()
98- ->getMockForAbstractClass ();
99-
100- $ this ->abstractAttribute = $ this ->getMockBuilder (AbstractAttribute::class)
101- ->setMethods (['getSourceModel ' , 'getSource ' ])
102- ->disableOriginalConstructor ()
103- ->getMockForAbstractClass ();
104-
105- $ this ->objectManagerHelper = new ObjectManagerHelper ($ this );
106- $ this ->model = $ this ->objectManagerHelper ->getObject (
107- AttributeOptionProvider::class,
108- [
109- 'attributeResource ' => $ this ->attributeResource ,
110- 'scopeResolver ' => $ this ->scopeResolver ,
111- 'optionSelectBuilder ' => $ this ->optionSelectBuilder ,
112- ]
113- );
63+ $ this ->model = new AttributeOptionProvider ($ this ->attributeResource , $ this ->optionSelectBuilder );
11464 }
11565
11666 /**
@@ -119,13 +69,9 @@ protected function setUp(): void
11969 */
12070 public function testGetAttributeOptions (array $ options )
12171 {
122- $ this ->scopeResolver ->expects ($ this ->any ())
123- ->method ('getScope ' )
124- ->willReturn ($ this ->scope );
125-
126- $ this ->optionSelectBuilder ->expects ($ this ->any ())
72+ $ this ->optionSelectBuilder ->expects ($ this ->once ())
12773 ->method ('getSelect ' )
128- ->with ($ this ->abstractAttribute , 4 , $ this -> scope )
74+ ->with ($ this ->abstractAttribute , 4 )
12975 ->willReturn ($ this ->select );
13076
13177 $ this ->attributeResource ->expects ($ this ->once ())
@@ -149,14 +95,7 @@ public function testGetAttributeOptions(array $options)
14995 */
15096 public function testGetAttributeOptionsWithBackendModel (array $ options )
15197 {
152- $ this ->scopeResolver ->expects ($ this ->any ())
153- ->method ('getScope ' )
154- ->willReturn ($ this ->scope );
155-
156- $ source = $ this ->getMockBuilder (AbstractSource::class)
157- ->disableOriginalConstructor ()
158- ->setMethods (['getAllOptions ' ])
159- ->getMockForAbstractClass ();
98+ $ source = $ this ->createMock (AbstractSource::class);
16099 $ source ->expects ($ this ->once ())
161100 ->method ('getAllOptions ' )
162101 ->willReturn ([
@@ -165,16 +104,16 @@ public function testGetAttributeOptionsWithBackendModel(array $options)
165104 ['value ' => 15 , 'label ' => 'Option Value for index 15 ' ]
166105 ]);
167106
168- $ this ->abstractAttribute ->expects ($ this ->any ())
107+ $ this ->abstractAttribute ->expects ($ this ->atLeastOnce ())
169108 ->method ('getSource ' )
170109 ->willReturn ($ source );
171110 $ this ->abstractAttribute ->expects ($ this ->atLeastOnce ())
172111 ->method ('getSourceModel ' )
173112 ->willReturn ('getSourceModel value ' );
174113
175- $ this ->optionSelectBuilder ->expects ($ this ->any ())
114+ $ this ->optionSelectBuilder ->expects ($ this ->once ())
176115 ->method ('getSelect ' )
177- ->with ($ this ->abstractAttribute , 1 , $ this -> scope )
116+ ->with ($ this ->abstractAttribute , 1 )
178117 ->willReturn ($ this ->select );
179118
180119 $ this ->attributeResource ->expects ($ this ->once ())
0 commit comments