-
Notifications
You must be signed in to change notification settings - Fork 36
Expand file tree
/
Copy pathJarTest.php
More file actions
106 lines (97 loc) Β· 2.71 KB
/
JarTest.php
File metadata and controls
106 lines (97 loc) Β· 2.71 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
<?php
declare(strict_types=1);
namespace PHPJava\Tests\Cases;
use PHPJava\Core\JavaArchive;
use PHPJava\IO\Standard\Output;
class JarTest extends Base
{
protected $fixtures = [
'OuterClassTest',
'JarCalleeTest',
'JarCallerTest',
'CalleeEnclosingMethodInJarTest',
'CallerEnclosingMethodInJarTest',
];
public function setUp(): void
{
parent::setUp();
$this
->createJAR(
'JarTest.jar',
'OuterClassTest',
[
'OuterClassTest',
]
)
->createJAR(
'JarCallTest.jar',
'JarCallerTest',
[
'JarCalleeTest',
'JarCallerTest',
]
)
->createJAR(
'CallEnclosingMethodInJarTest.jar',
'CallerEnclosingMethodInJarTest',
[
'CalleeEnclosingMethodInJarTest',
'CallerEnclosingMethodInJarTest',
]
);
}
public function testCallWithEntryPoint()
{
(new JavaArchive(__DIR__ . '/caches/JarTest.jar'))->execute([]);
$result = Output::getHeapspace();
$this->assertEquals(
'Called Static Method AND Called Dynamic Method',
$result
);
}
public function testCallWithTargetedMethod()
{
(new JavaArchive(__DIR__ . '/caches/JarTest.jar'))
->getClassByName('OuterClassTest')
->getInvoker()
->getStatic()
->getMethods()
->call(
'main',
[]
);
$result = Output::getHeapspace();
$this->assertEquals(
'Called Static Method AND Called Dynamic Method',
$result
);
}
public function testSamePlaceClass()
{
(new JavaArchive(__DIR__ . '/caches/JarCallTest.jar'))
->getClassByName('JarCallerTest')
->getInvoker()
->getStatic()
->getMethods()
->call(
'main',
[]
);
$result = Output::getHeapspace();
$this->assertEquals("TEST\n", $result);
}
public function testEnclosingMethodInJar()
{
(new JavaArchive(__DIR__ . '/caches/CallEnclosingMethodInJarTest.jar'))
->getClassByName('CallerEnclosingMethodInJarTest')
->getInvoker()
->getStatic()
->getMethods()
->call(
'main',
[]
);
$result = Output::getHeapspace();
$this->assertEquals("Hello World!\n", $result);
}
}