1010use Jeidison \JSignPDF \Sign \JSignParam ;
1111use PharData ;
1212use PHPUnit \Framework \TestCase ;
13- use RuntimeException ;
14- use UnexpectedValueException ;
1513
1614class JavaRuntimeServiceTest extends TestCase
1715{
@@ -32,15 +30,21 @@ public function testGetPathWhenJavaIsInstalled(): void {
3230 public function testGetPathWithCustomAndValidJavaPath (): void {
3331 $ jsignParam = new JSignParam ();
3432 $ service = new JavaRuntimeService ();
35- $ jsignParam ->setJavaPath (PHP_BINARY );
33+ vfsStream::setup ('download ' );
34+ mkdir ('vfs://download/bin ' );
35+ touch ('vfs://download/bin/java ' );
36+ chmod ('vfs://download/bin/java ' , 0755 );
37+ $ jsignParam ->setJavaPath ('vfs://download/bin/java ' );
38+ $ jsignParam ->setJavaDownloadUrl ('' );
3639 $ path = $ service ->getPath ($ jsignParam );
37- $ this ->assertEquals (PHP_BINARY , $ path );
40+ $ this ->assertEquals (' vfs://download/bin/java ' , $ path );
3841 }
3942
4043 public function testGetPathWithCustomAndInvalidJavaPath (): void {
4144 $ jsignParam = new JSignParam ();
4245 $ service = new JavaRuntimeService ();
4346 $ jsignParam ->setJavaPath (__FILE__ );
47+ $ jsignParam ->setJavaDownloadUrl ('' );
4448 $ this ->expectException (InvalidArgumentException::class);
4549 $ this ->expectExceptionMessageMatches ('/not executable/ ' );
4650 $ service ->getPath ($ jsignParam );
@@ -49,7 +53,12 @@ public function testGetPathWithCustomAndInvalidJavaPath(): void {
4953 public function testGetPathWithDownloadUrlAndNotRealDirectory (): void {
5054 $ jsignParam = new JSignParam ();
5155 $ service = new JavaRuntimeService ();
52- $ jsignParam ->setJavaPath (__FILE__ );
56+ $ root = vfsStream::setup ('download ' );
57+ $ root ->chmod (0770 )
58+ ->chgrp (vfsStream::GROUP_USER_1 )
59+ ->chown (vfsStream::OWNER_USER_1 );
60+ chgrp ('vfs://download ' , 44 );
61+ $ jsignParam ->setJavaPath ('vfs://download/not_real_directory ' );
5362 $ jsignParam ->setJavaDownloadUrl ('https://fake.url ' );
5463 $ this ->expectException (InvalidArgumentException::class);
5564 $ this ->expectExceptionMessageMatches ('/not a real directory/ ' );
@@ -59,8 +68,7 @@ public function testGetPathWithDownloadUrlAndNotRealDirectory(): void {
5968 public function testGetPathWithDownloadUrlAndEmptyJavaVersion (): void {
6069 $ jsignParam = new JSignParam ();
6170 $ service = new JavaRuntimeService ();
62- $ jsignParam ->setJavaPath (realpath (__DIR__ . '/../../tmp/ ' ));
63- $ jsignParam ->setJavaDownloadUrl ('https://fake.url ' );
71+ $ jsignParam ->setJavaVersion ('' );
6472 $ this ->expectException (InvalidArgumentException::class);
6573 $ this ->expectExceptionMessageMatches ('/Java version required/ ' );
6674 $ service ->getPath ($ jsignParam );
@@ -157,7 +165,7 @@ public function testGetPathWithoutJavaFallback(): void {
157165 $ jsignParam = new JSignParam ();
158166 $ service = new JavaRuntimeService ();
159167
160- $ jsignParam ->setJavaVersion ( ' 21.0.0 ' );
168+ $ jsignParam ->setJavaPath ( ' ' );
161169 $ this ->expectException (InvalidArgumentException::class);
162170 $ this ->expectExceptionMessageMatches ('/Java not found/ ' );
163171 $ service ->getPath ($ jsignParam );
0 commit comments