1010use Magento \Framework \App \Config \Initial ;
1111use Magento \Framework \App \Config \ScopeConfigInterface ;
1212use Magento \Framework \App \ResourceConnection ;
13- use Magento \Framework \DB \Adapter \AdapterInterface ;
14- use Magento \Framework \DB \Select ;
1513use Magento \MediaGalleryRenditions \Model \Config ;
1614use PHPUnit \Framework \MockObject \MockObject ;
1715use PHPUnit \Framework \TestCase ;
@@ -38,30 +36,11 @@ class ConfigTest extends TestCase
3836 */
3937 private $ config ;
4038
41- /**
42- * @var AdapterInterface|MockObject
43- */
44- private $ connectionMock ;
45-
46- /**
47- * @var Select|MockObject
48- */
49- private $ selectMock ;
50-
5139 protected function setUp (): void
5240 {
5341 $ this ->scopeConfigMock = $ this ->createMock (ScopeConfigInterface::class);
5442 $ this ->initialConfigMock = $ this ->createMock (Initial::class);
5543 $ this ->resourceConnectionMock = $ this ->createMock (ResourceConnection::class);
56- $ this ->connectionMock = $ this ->getMockBuilder (AdapterInterface::class)
57- ->addMethods (['fetchColumn ' ])
58- ->getMockForAbstractClass ();
59- $ this ->selectMock = $ this ->createMock (Select::class);
60- $ this ->resourceConnectionMock ->method ('getConnection ' )
61- ->willReturn ($ this ->connectionMock );
62- $ this ->resourceConnectionMock ->method ('getTableName ' )
63- ->with ('core_config_data ' )
64- ->willReturn ('core_config_data ' );
6544 $ this ->config = new Config (
6645 $ this ->scopeConfigMock ,
6746 $ this ->initialConfigMock ,
@@ -70,43 +49,29 @@ protected function setUp(): void
7049 }
7150
7251 /**
73- * Test getWidth() with successful database retrieval
52+ * Test getWidth() using scopeConfig value
7453 */
75- public function testGetWidthSuccess (): void
54+ public function testGetWidthFromScopeConfig (): void
7655 {
7756 $ expectedWidth = 800 ;
78- $ this ->connectionMock ->method ('select ' )
79- ->willReturn ($ this ->selectMock );
80- $ this ->selectMock ->method ('from ' )
81- ->willReturnSelf ();
82- $ this ->selectMock ->method ('where ' )
83- ->willReturnSelf ();
84- $ this ->connectionMock ->method ('query ' )
85- ->with ($ this ->selectMock )
86- ->willReturnSelf ();
87- $ this ->connectionMock ->method ('fetchColumn ' )
88- ->willReturn ((string )$ expectedWidth );
57+ $ widthPath = 'system/media_gallery_renditions/width ' ;
58+ $ this ->scopeConfigMock ->method ('getValue ' )
59+ ->with ($ widthPath )
60+ ->willReturn ($ expectedWidth );
8961 $ result = $ this ->config ->getWidth ();
9062 $ this ->assertEquals ($ expectedWidth , $ result );
9163 }
9264
9365 /**
94- * Test getWidth() with empty database result falling back to initial config
66+ * Test getWidth() falling back to initial config
9567 */
96- public function testGetWidthFallback (): void
68+ public function testGetWidthFromInitialConfig (): void
9769 {
9870 $ expectedWidth = 600 ;
99- $ this ->connectionMock ->method ('select ' )
100- ->willReturn ($ this ->selectMock );
101- $ this ->selectMock ->method ('from ' )
102- ->willReturnSelf ();
103- $ this ->selectMock ->method ('where ' )
104- ->willReturnSelf ();
105- $ this ->connectionMock ->method ('query ' )
106- ->with ($ this ->selectMock )
107- ->willReturnSelf ();
108- $ this ->connectionMock ->method ('fetchColumn ' )
109- ->willReturn (false );
71+ $ widthPath = 'system/media_gallery_renditions/width ' ;
72+ $ this ->scopeConfigMock ->method ('getValue ' )
73+ ->with ($ widthPath )
74+ ->willReturn (null );
11075 $ this ->initialConfigMock ->method ('getData ' )
11176 ->with ('default ' )
11277 ->willReturn ([
@@ -121,42 +86,28 @@ public function testGetWidthFallback(): void
12186 }
12287
12388 /**
124- * Test getHeight() with successful database retrieval
89+ * Test getHeight() using scopeConfig value
12590 */
126- public function testGetHeightSuccess (): void
91+ public function testGetHeightFromScopeConfig (): void
12792 {
12893 $ expectedHeight = 600 ;
129- $ this ->connectionMock ->method ('select ' )
130- ->willReturn ($ this ->selectMock );
131- $ this ->selectMock ->method ('from ' )
132- ->willReturnSelf ();
133- $ this ->selectMock ->method ('where ' )
134- ->willReturnSelf ();
135- $ this ->connectionMock ->method ('query ' )
136- ->with ($ this ->selectMock )
137- ->willReturnSelf ();
138- $ this ->connectionMock ->method ('fetchColumn ' )
139- ->willReturn ((string )$ expectedHeight );
94+ $ heightPath = 'system/media_gallery_renditions/height ' ;
95+ $ this ->scopeConfigMock ->method ('getValue ' )
96+ ->with ($ heightPath )
97+ ->willReturn ($ expectedHeight );
14098 $ result = $ this ->config ->getHeight ();
14199 $ this ->assertEquals ($ expectedHeight , $ result );
142100 }
143101
144102 /**
145- * Test getHeight() with empty database result falling back to initial config
103+ * Test getHeight() falling back to initial config
146104 */
147- public function testGetHeightFallback (): void
105+ public function testGetHeightFromInitialConfig (): void
148106 {
149107 $ expectedHeight = 400 ;
150- $ this ->connectionMock ->method ('select ' )
151- ->willReturn ($ this ->selectMock );
152- $ this ->selectMock ->method ('from ' )
153- ->willReturnSelf ();
154- $ this ->selectMock ->method ('where ' )
155- ->willReturnSelf ();
156- $ this ->connectionMock ->method ('query ' )
157- ->with ($ this ->selectMock )
158- ->willReturnSelf ();
159- $ this ->connectionMock ->method ('fetchColumn ' )
108+ $ heightPath = 'system/media_gallery_renditions/height ' ;
109+ $ this ->scopeConfigMock ->method ('getValue ' )
110+ ->with ($ heightPath )
160111 ->willReturn (null );
161112 $ this ->initialConfigMock ->method ('getData ' )
162113 ->with ('default ' )
0 commit comments