Skip to content

Commit 26d260f

Browse files
committed
GhostscriptAPITest and GhostscriptTest load tests
1 parent e5a559d commit 26d260f

4 files changed

Lines changed: 57 additions & 29 deletions

File tree

Ghostscript/GhostscriptAPI.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -99,12 +99,12 @@ class GhostscriptAPI {
9999
protected function __construct (protected FFI $ffi) {
100100
}
101101

102-
public static function create (string $lib_path) : self|false {
103-
if (!is_file($lib_path)) {
102+
public static function create (string $gslib_path) : self|false {
103+
if (!is_file($gslib_path)) {
104104
return false;
105105
}
106106

107-
$ffi = FFI::cdef(self::HEADER, $lib_path);
107+
$ffi = FFI::cdef(self::HEADER, $gslib_path);
108108

109109
return new self($ffi);
110110
}

tests/GhostscriptAPITest.php

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
<?php
2+
declare(strict_types=1);
3+
4+
namespace Fawno\PDFOptimizer\Tests;
5+
6+
use Fawno\Ghostscript\GhostscriptAPI;
7+
use PHPUnit\Framework\Attributes\RequiresPhpExtension;;
8+
9+
#[RequiresPhpExtension('ffi')]
10+
class GhostscriptAPITest extends TestCase {
11+
public const GSLIB_PATH_LINUX = '/usr/lib/x86_64-linux-gnu/libgs.so';
12+
public const GSLIB_PATH_WINDOWS = '\\usr\\gs\\bin\\gsdll64.dll';
13+
readonly public string $gslib_path;
14+
15+
protected function setUp(): void {
16+
$this->gslib_path = (PHP_OS == 'Linux') ? self::GSLIB_PATH_LINUX : self::GSLIB_PATH_WINDOWS;
17+
18+
if (!is_file($this->gslib_path)) {
19+
$this->markTestSkipped('Not found GSLIB: ' . $this->gslib_path);
20+
}
21+
}
22+
23+
public function testGhostscriptAPILoad () : void {
24+
$gs = GhostscriptAPI::create($this->gslib_path);
25+
26+
$this->assertInstanceOf(GhostscriptAPI::class, $gs);
27+
}
28+
}

tests/GhostscriptPathFinderTest.php

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

tests/GhostscriptTest.php

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
<?php
2+
declare(strict_types=1);
3+
4+
namespace Fawno\PDFOptimizer\Tests;
5+
6+
use Fawno\Ghostscript\Ghostscript;
7+
8+
class GhostscriptTest extends TestCase {
9+
public const GSBIN_PATH_LINUX = '/usr/bin/gs';
10+
public const GSBIN_PATH_WINDOWS = '\\usr\\gs\\bin\\gswin64c.exe';
11+
readonly public string $gsbin_path;
12+
13+
protected function setUp(): void {
14+
$this->gsbin_path = (PHP_OS == 'Linux') ? self::GSBIN_PATH_LINUX : self::GSBIN_PATH_WINDOWS;
15+
16+
if (!is_file($this->gsbin_path)) {
17+
$this->markTestSkipped('Not found GSBIN: ' . $this->gsbin_path);
18+
}
19+
}
20+
21+
public function testGhostscriptLoad () : void {
22+
$gs = Ghostscript::create($this->gsbin_path);
23+
24+
$this->assertInstanceOf(Ghostscript::class, $gs);
25+
}
26+
}

0 commit comments

Comments
 (0)