Skip to content

Commit 257f0f5

Browse files
committed
Add tests
1 parent f883604 commit 257f0f5

4 files changed

Lines changed: 76 additions & 2 deletions

File tree

tests/Base.php

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,21 @@ public function setUp(): void
2525
}
2626
}
2727

28+
public function createJAR($name, $entrypoint, array $fixtures = [])
29+
{
30+
$classes = implode(
31+
' ',
32+
array_map(
33+
function ($fixture) {
34+
return $fixture . '.class';
35+
},
36+
$fixtures
37+
)
38+
);
39+
exec('cd ' . __DIR__ . '/caches && jar -cvfe ' . $name . ' ' . $entrypoint . ' ' . $classes);
40+
return $this;
41+
}
42+
2843
protected function getClassName($fixtureName)
2944
{
3045
return __DIR__ . '/caches/' . $fixtureName . '.class';

tests/JarTest.php

Lines changed: 42 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,37 @@ class JarTest extends Base
99
'OuterClassTest',
1010
'JarCalleeTest',
1111
'JarCallerTest',
12+
'CalleeEnclosingMethodInJarTest',
13+
'CallerEnclosingMethodInJarTest',
1214
];
1315

1416
public function setUp(): void
1517
{
1618
parent::setUp();
17-
exec('cd ' . __DIR__ . '/caches && jar -cvfe JarTest.jar OuterClassTest OuterClassTest.class');
18-
exec('cd ' . __DIR__ . '/caches && jar -cvfe JarCallTest.jar JarCallerTest JarCalleeTest.class JarCallerTest.class');
19+
$this
20+
->createJAR(
21+
'JarTest.jar',
22+
'OuterClassTest',
23+
[
24+
'OuterClassTest',
25+
]
26+
)
27+
->createJAR(
28+
'JarCallTest.jar',
29+
'JarCallerTest',
30+
[
31+
'JarCalleeTest',
32+
'JarCallerTest',
33+
]
34+
)
35+
->createJAR(
36+
'CallEnclosingMethodInJarTest.jar',
37+
'CallerEnclosingMethodInJarTest',
38+
[
39+
'CalleeEnclosingMethodInJarTest',
40+
'CallerEnclosingMethodInJarTest',
41+
]
42+
);
1943
}
2044

2145
public function testCallWithEntryPoint()
@@ -65,4 +89,20 @@ public function testSamePlaceClass()
6589
$result = ob_get_clean();
6690
$this->assertEquals("TEST\n", $result);
6791
}
92+
93+
public function testEnclosingMethodInJar()
94+
{
95+
ob_start();
96+
(new JavaArchive(__DIR__ . '/caches/CallEnclosingMethodInJarTest.jar'))
97+
->getClassByName('CallerEnclosingMethodInJarTest')
98+
->getInvoker()
99+
->getStatic()
100+
->getMethods()
101+
->call(
102+
'main',
103+
[]
104+
);
105+
$result = ob_get_clean();
106+
$this->assertEquals("Hello World!\n", $result);
107+
}
68108
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
class CalleeEnclosingMethodInJarTest
2+
{
3+
public String text;
4+
5+
public void callHelloWorld()
6+
{
7+
System.out.println(this.text);
8+
}
9+
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
class CallerEnclosingMethodInJarTest
2+
{
3+
public static void main(String[] args)
4+
{
5+
new CalleeEnclosingMethodInJarTest() {{
6+
this.text = "Hello World!";
7+
callHelloWorld();
8+
}};
9+
}
10+
}

0 commit comments

Comments
 (0)