@@ -20,6 +20,31 @@ class BinaryCompatibilityTestCase extends TestCase
2020{
2121 private const DIR_STORAGE = __DIR__ . '/storage ' ;
2222
23+ protected function skipIfVersionNotCompatible (Version $ version , string $ binary ): void
24+ {
25+ $ this ->skipIfNoFFISupport ();
26+
27+ $ ffi = \FFI ::cdef (<<<'CPP'
28+ typedef struct SDL_version {
29+ uint8_t major;
30+ uint8_t minor;
31+ uint8_t patch;
32+ } SDL_version;
33+
34+ extern const SDL_version * TTF_Linked_Version(void);
35+ CPP, $ binary );
36+
37+ $ ver = $ ffi ->TTF_Linked_Version ();
38+ $ actual = \sprintf ('%d.%d.%d ' , $ ver ->major , $ ver ->minor , $ ver ->patch );
39+
40+ if (\version_compare ($ version ->toString (), $ actual , '> ' )) {
41+ $ message = 'Unable to check compatibility because the installed version of the '
42+ . 'library (v%s) is lower than the tested headers (v%s) ' ;
43+
44+ $ this ->markTestSkipped (\sprintf ($ message , $ actual , $ version ->toString ()));
45+ }
46+ }
47+
2348 /**
2449 * @requires OSFAMILY Windows
2550 *
@@ -34,15 +59,13 @@ public function testWindowsBinaryCompatibility(Version $version): void
3459 ->extract ('SDL2.dll ' , self ::DIR_STORAGE . '/SDL2.dll ' );
3560 }
3661
37- if (!\is_file (self ::DIR_STORAGE . '/SDL2_ttf.dll ' )) {
62+ if (!\is_file ($ binary = self ::DIR_STORAGE . '/SDL2_ttf.dll ' )) {
3863 Downloader::zip ('https://github.com/libsdl-org/SDL_ttf/releases/download/release-2.0.18/SDL2_ttf-2.0.18-win32-x64.zip ' )
3964 ->extract ('SDL2_ttf.dll ' , self ::DIR_STORAGE . '/SDL2_ttf.dll ' );
4065 }
4166
42- $ this ->assertHeadersCompatibleWith (
43- SDL2TTF ::create ($ version ),
44- self ::DIR_STORAGE . '/SDL2_ttf.dll '
45- );
67+ $ this ->skipIfVersionNotCompatible ($ version , $ binary );
68+ $ this ->assertHeadersCompatibleWith (SDL2TTF ::create ($ version ), $ binary );
4669 }
4770
4871 /**
@@ -52,14 +75,14 @@ public function testWindowsBinaryCompatibility(Version $version): void
5275 */
5376 public function testDarwinBinaryCompatibility (Version $ version ): void
5477 {
55- if (!Locator::exists ('libSDL2_ttf-2.0.0.dylib ' )) {
78+ $ binary = Locator::resolve ('libSDL2_ttf-2.0.0.dylib ' );
79+
80+ if ($ binary === null ) {
5681 $ this ->markTestSkipped ('sdl2_ttf not installed ' );
5782 }
5883
59- $ this ->assertHeadersCompatibleWith (
60- SDL2TTF ::create ($ version ),
61- Locator::resolve ('libSDL2_ttf-2.0.0.dylib ' )
62- );
84+ $ this ->skipIfVersionNotCompatible ($ version , $ binary );
85+ $ this ->assertHeadersCompatibleWith (SDL2TTF ::create ($ version ), $ binary );
6386 }
6487
6588 /**
@@ -69,13 +92,13 @@ public function testDarwinBinaryCompatibility(Version $version): void
6992 */
7093 public function testLinuxBinaryCompatibility (Version $ version ): void
7194 {
72- if (!Locator::exists ('libSDL2_ttf-2.0.so.0 ' )) {
95+ $ binary = Locator::resolve ('libSDL2_ttf-2.0.so.0 ' );
96+
97+ if ($ binary === null ) {
7398 $ this ->markTestSkipped ('sdl2_ttf not installed ' );
7499 }
75100
76- $ this ->assertHeadersCompatibleWith (
77- SDL2TTF ::create ($ version ),
78- Locator::resolve ('libSDL2_ttf-2.0.so.0 ' )
79- );
101+ $ this ->skipIfVersionNotCompatible ($ version , $ binary );
102+ $ this ->assertHeadersCompatibleWith (SDL2TTF ::create ($ version ), $ binary );
80103 }
81104}
0 commit comments