Skip to content

Commit d34a42e

Browse files
committed
Reorganize library tests
1 parent 747f58a commit d34a42e

File tree

7 files changed

+36
-248
lines changed

7 files changed

+36
-248
lines changed

composer.json

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,10 +29,8 @@
2929
}
3030
},
3131
"require-dev": {
32-
"ffi/env": "^0.1|^1.0",
33-
"ffi/location": "^0.1|^1.0",
34-
"vimeo/psalm": "^4.22.0",
35-
"phpunit/phpunit": "^9.5.15"
32+
"ffi-headers/testing": "^1.0",
33+
"vimeo/psalm": "^4.22"
3634
},
3735
"autoload-dev": {
3836
"psr-4": {

tests/BinaryCompatibilityTestCase.php

Lines changed: 15 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -11,24 +11,18 @@
1111

1212
namespace FFI\Headers\Bass\Tests;
1313

14-
use FFI\Env\Runtime;
1514
use FFI\Headers\Bass;
1615
use FFI\Headers\Bass\Platform;
17-
use FFI\Headers\Bass\Tests\BinaryCompatibilityTestCase\Downloader;
1816
use FFI\Headers\Bass\Version;
17+
use FFI\Headers\Testing\Downloader;
1918

20-
/**
21-
* @requires extension ffi
22-
*/
2319
class BinaryCompatibilityTestCase extends TestCase
2420
{
25-
public function setUp(): void
21+
private function skipIfPlatformNotSupported(Version $version, Platform $platform): void
2622
{
27-
if (!Runtime::isAvailable()) {
28-
$this->markTestSkipped('An ext-ffi extension must be available and enabled');
23+
if (!$version->supportedOn($platform)) {
24+
$this->markTestSkipped($platform->name . ' not supported by version ' . $version->toString());
2925
}
30-
31-
parent::setUp();
3226
}
3327

3428
/**
@@ -37,23 +31,16 @@ public function setUp(): void
3731
*/
3832
public function testLinuxBinaryCompatibility(Version $version): void
3933
{
40-
if (!$version->supportedOn(Platform::LINUX)) {
41-
$this->markTestSkipped('Linux not supported by version ' . $version->toString());
42-
}
43-
44-
$binary = __DIR__ . '/storage/libbass-' . $version->toString() . '.so';
34+
$this->skipIfPlatformNotSupported($version, Platform::LINUX);
4535

46-
if (!\is_file($binary)) {
47-
Downloader::download('https://www.un4seen.com/files/bass%s-linux.zip', [
36+
if (!\is_file($binary = __DIR__ . '/storage/libbass-' . $version->toString() . '.so')) {
37+
Downloader::zip('https://www.un4seen.com/files/bass%s-linux.zip', [
4838
\str_replace('.', '', $version->toString()),
4939
])
5040
->extract('x64/libbass.so', $binary);
5141
}
5242

53-
$this->expectNotToPerformAssertions();
54-
$headers = (string)Bass::create(Platform::LINUX, $version);
55-
56-
\FFI::cdef($headers, $binary);
43+
$this->assertHeadersCompatibleWith(Bass::create(Platform::LINUX, $version), $binary);
5744
}
5845

5946
/**
@@ -62,10 +49,8 @@ public function testLinuxBinaryCompatibility(Version $version): void
6249
*/
6350
public function testWindowsBinaryCompatibility(Version $version): void
6451
{
65-
$binary = __DIR__ . '/storage/bass-' . $version->toString() . '.dll';
66-
67-
if (!\is_file($binary)) {
68-
$result = Downloader::download('https://www.un4seen.com/files/bass%s.zip', [
52+
if (!\is_file($binary = __DIR__ . '/storage/bass-' . $version->toString() . '.dll')) {
53+
$result = Downloader::zip('https://www.un4seen.com/files/bass%s.zip', [
6954
\str_replace('.', '', $version->toString()),
7055
]);
7156

@@ -80,10 +65,7 @@ public function testWindowsBinaryCompatibility(Version $version): void
8065
}
8166
}
8267

83-
$this->expectNotToPerformAssertions();
84-
$headers = (string)Bass::create(Platform::WINDOWS, $version);
85-
86-
\FFI::cdef($headers, $binary);
68+
$this->assertHeadersCompatibleWith(Bass::create(Platform::WINDOWS, $version), $binary);
8769
}
8870

8971
/**
@@ -92,14 +74,10 @@ public function testWindowsBinaryCompatibility(Version $version): void
9274
*/
9375
public function testDarwinBinaryCompatibility(Version $version): void
9476
{
95-
if (!$version->supportedOn(Platform::DARWIN)) {
96-
$this->markTestSkipped('OSX not supported by version ' . $version->toString());
97-
}
77+
$this->skipIfPlatformNotSupported($version, Platform::DARWIN);
9878

99-
$binary = __DIR__ . '/storage/libbass-' . $version->toString() . '.dylib';
100-
101-
if (!\is_file($binary)) {
102-
$result = Downloader::download('https://www.un4seen.com/files/bass%s-osx.zip', [
79+
if (!\is_file($binary = __DIR__ . '/storage/libbass-' . $version->toString() . '.dylib')) {
80+
$result = Downloader::zip('https://www.un4seen.com/files/bass%s-osx.zip', [
10381
\str_replace('.', '', $version->toString()),
10482
]);
10583

@@ -114,9 +92,6 @@ public function testDarwinBinaryCompatibility(Version $version): void
11492
}
11593
}
11694

117-
$this->expectNotToPerformAssertions();
118-
$headers = (string)Bass::create(Platform::DARWIN, $version);
119-
120-
\FFI::cdef($headers, $binary);
95+
$this->assertHeadersCompatibleWith(Bass::create(Platform::DARWIN, $version), $binary);
12196
}
12297
}

tests/BinaryCompatibilityTestCase/Downloader.php

Lines changed: 0 additions & 78 deletions
This file was deleted.

tests/BinaryCompatibilityTestCase/DownloaderResult.php

Lines changed: 0 additions & 73 deletions
This file was deleted.

tests/CompilationTestCase.php

Lines changed: 0 additions & 53 deletions
This file was deleted.

tests/ContentRenderingTestCase.php

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,4 +32,20 @@ public function testRenderable(Platform $platform, Version $version): void
3232

3333
(string)Bass::create($platform, $version);
3434
}
35+
36+
/**
37+
* @testdox Testing that headers contain correct syntax
38+
*
39+
* @dataProvider configDataProvider
40+
*/
41+
public function testCompilation(Platform $platform, Version $version): void
42+
{
43+
if (!$platform->supportedBy($version)) {
44+
$this->expectExceptionMessage('not supported by version');
45+
}
46+
47+
$this->assertHeadersSyntaxValid(
48+
Bass::create($platform, $version)
49+
);
50+
}
3551
}

tests/TestCase.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,13 @@
1313

1414
use FFI\Headers\Bass\Platform;
1515
use FFI\Headers\Bass\Version;
16+
use FFI\Headers\Testing\TestingTrait;
1617
use PHPUnit\Framework\TestCase as BaseTestCase;
1718

1819
abstract class TestCase extends BaseTestCase
1920
{
21+
use TestingTrait;
22+
2023
/**
2124
* @return array<array{Platform, Version}>
2225
*/

0 commit comments

Comments
 (0)