10
10
use Magento \Framework \App \Config \Initial ;
11
11
use Magento \Framework \App \Config \ScopeConfigInterface ;
12
12
use Magento \Framework \App \ResourceConnection ;
13
- use Magento \Framework \DB \Adapter \AdapterInterface ;
14
- use Magento \Framework \DB \Select ;
15
13
use Magento \MediaGalleryRenditions \Model \Config ;
16
14
use PHPUnit \Framework \MockObject \MockObject ;
17
15
use PHPUnit \Framework \TestCase ;
@@ -38,30 +36,11 @@ class ConfigTest extends TestCase
38
36
*/
39
37
private $ config ;
40
38
41
- /**
42
- * @var AdapterInterface|MockObject
43
- */
44
- private $ connectionMock ;
45
-
46
- /**
47
- * @var Select|MockObject
48
- */
49
- private $ selectMock ;
50
-
51
39
protected function setUp (): void
52
40
{
53
41
$ this ->scopeConfigMock = $ this ->createMock (ScopeConfigInterface::class);
54
42
$ this ->initialConfigMock = $ this ->createMock (Initial::class);
55
43
$ 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 ' );
65
44
$ this ->config = new Config (
66
45
$ this ->scopeConfigMock ,
67
46
$ this ->initialConfigMock ,
@@ -70,43 +49,29 @@ protected function setUp(): void
70
49
}
71
50
72
51
/**
73
- * Test getWidth() with successful database retrieval
52
+ * Test getWidth() using scopeConfig value
74
53
*/
75
- public function testGetWidthSuccess (): void
54
+ public function testGetWidthFromScopeConfig (): void
76
55
{
77
56
$ 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 );
89
61
$ result = $ this ->config ->getWidth ();
90
62
$ this ->assertEquals ($ expectedWidth , $ result );
91
63
}
92
64
93
65
/**
94
- * Test getWidth() with empty database result falling back to initial config
66
+ * Test getWidth() falling back to initial config
95
67
*/
96
- public function testGetWidthFallback (): void
68
+ public function testGetWidthFromInitialConfig (): void
97
69
{
98
70
$ 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 );
110
75
$ this ->initialConfigMock ->method ('getData ' )
111
76
->with ('default ' )
112
77
->willReturn ([
@@ -121,42 +86,28 @@ public function testGetWidthFallback(): void
121
86
}
122
87
123
88
/**
124
- * Test getHeight() with successful database retrieval
89
+ * Test getHeight() using scopeConfig value
125
90
*/
126
- public function testGetHeightSuccess (): void
91
+ public function testGetHeightFromScopeConfig (): void
127
92
{
128
93
$ 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 );
140
98
$ result = $ this ->config ->getHeight ();
141
99
$ this ->assertEquals ($ expectedHeight , $ result );
142
100
}
143
101
144
102
/**
145
- * Test getHeight() with empty database result falling back to initial config
103
+ * Test getHeight() falling back to initial config
146
104
*/
147
- public function testGetHeightFallback (): void
105
+ public function testGetHeightFromInitialConfig (): void
148
106
{
149
107
$ 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 )
160
111
->willReturn (null );
161
112
$ this ->initialConfigMock ->method ('getData ' )
162
113
->with ('default ' )
0 commit comments