1717use ReflectionProperty ;
1818
1919use function file_put_contents ;
20- use function function_exists ;
21- use function gd_info ;
20+ use function get_defined_constants ;
2221use function md5 ;
23- use function ob_get_clean ;
24- use function ob_start ;
25- use function phpinfo ;
26- use function preg_match ;
2722use function realpath ;
28- use function str_contains ;
29- use function strip_tags ;
3023use function stristr ;
3124use function sys_get_temp_dir ;
3225use function tempnam ;
3528use const CHANGELOG_FILE ;
3629use const CONFIG_FILE ;
3730use const DIRECTORY_SEPARATOR ;
38- use const INFO_MODULES ;
3931use const PHP_OS ;
4032
4133#[CoversClass(Config::class)]
@@ -123,7 +115,7 @@ public function testLoadConfigs(): void
123115 }
124116
125117 /**
126- * test for CheckGd2
118+ * test for isGd2Available
127119 */
128120 public function testCheckGd2 (): void
129121 {
@@ -134,38 +126,10 @@ public function testCheckGd2(): void
134126 self ::assertFalse ($ this ->object ->isGd2Available ());
135127
136128 $ this ->object ->set ('GD2Available ' , 'auto ' );
137-
138- if (! function_exists ('imagecreatetruecolor ' )) {
139- self ::assertFalse (
140- $ this ->object ->isGd2Available (),
141- 'imagecreatetruecolor does not exist, isGd2 should be false ' ,
142- );
143- }
144-
145- if (function_exists ('gd_info ' )) {
146- $ gdNfo = gd_info ();
147- if (str_contains ($ gdNfo ['GD Version ' ], '2. ' )) {
148- self ::assertTrue ($ this ->object ->isGd2Available (), 'GD Version >= 2, isGd2 should be true ' );
149- } else {
150- self ::assertFalse ($ this ->object ->isGd2Available (), 'GD Version < 2, isGd2 should be false ' );
151- }
152- }
153-
154- /* Get GD version string from phpinfo output */
155- ob_start ();
156- phpinfo (INFO_MODULES ); /* Only modules */
157- $ a = strip_tags ((string ) ob_get_clean ());
158-
159- if (preg_match ('@GD Version[[:space:]]*\(.*\)@ ' , $ a , $ v ) !== 1 ) {
160- return ;
161- }
162-
163- // TODO: The variable $v clearly is incorrect. Was this meant to be $a?
164- if (str_contains ($ v , '2. ' )) {
165- self ::assertTrue ($ this ->object ->isGd2Available (), 'isGd2 should be true ' );
166- } else {
167- self ::assertFalse ($ this ->object ->isGd2Available (), 'isGd2 should be false ' );
168- }
129+ self ::assertSame (
130+ (get_defined_constants ()['GD_MAJOR_VERSION ' ] ?? 0 ) >= 2 ,
131+ $ this ->object ->isGd2Available (),
132+ );
169133 }
170134
171135 /**
0 commit comments