Skip to content

Commit 57a2979

Browse files
committed
Add test
1 parent e66d3d6 commit 57a2979

4 files changed

Lines changed: 80 additions & 0 deletions

File tree

tests/OutputDebugTraceTest.php

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
<?php
2+
namespace PHPJava\Tests;
3+
4+
use PHPUnit\Framework\TestCase;
5+
6+
class OutputDebugTraceTest extends Base
7+
{
8+
protected $fixtures = [
9+
'OutputDebugTraceTest',
10+
];
11+
12+
/**
13+
* @var \PHPJava\Core\JavaClass
14+
*/
15+
private $javaClass;
16+
17+
public function setUp(): void
18+
{
19+
parent::setUp();
20+
21+
$this->javaClass = new \PHPJava\Core\JavaClass(
22+
new \PHPJava\Core\JavaClassReader($this->getClassName('OutputDebugTraceTest'))
23+
);
24+
}
25+
26+
public function testCallMain()
27+
{
28+
ob_start();
29+
$this->javaClass->getInvoker()->getStaticMethods()->call(
30+
'main',
31+
["Hello", " ", "World"]
32+
);
33+
ob_end_clean();
34+
35+
ob_start();
36+
$this->javaClass->debug();
37+
$result = ob_get_clean();
38+
$this->assertEquals(
39+
file_get_contents(__DIR__ . '/templates/DebugTraceTest.txt'),
40+
$result
41+
);
42+
}
43+
}

tests/fixtures/.gitkeep

Whitespace-only changes.
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
class OutputDebugTraceTest
2+
{
3+
public static void main(String[] args)
4+
{
5+
System.out.print(args[0]);
6+
System.out.print(args[1]);
7+
System.out.print(args[2]);
8+
}
9+
}

tests/templates/DebugTraceTest.txt

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
[method]
2+
public static void main(java.lang.String[])
3+
4+
[code]
5+
<0xb2> <0x00> <0x02> <0x2a> <0x03> <0x32> <0xb6> <0x00> <0x03> <0xb2> <0x00> <0x02> <0x2a> <0x04> <0x32> <0xb6> <0x00> <0x03> <0xb2> <0x00>
6+
<0x02> <0x2a> <0x05> <0x32> <0xb6> <0x00> <0x03> <0xb1>
7+
8+
[executed]
9+
PC | OPCODE | MNEMONIC | OPERANDS | LOCAL STORAGE
10+
---------+--------+----------------------+------------+-----------------
11+
0 | 0xB2 | getstatic | 0 | 1
12+
3 | 0x2A | aload_0 | 1 | 1
13+
4 | 0x03 | iconst_0 | 2 | 1
14+
5 | 0x32 | aaload | 3 | 1
15+
6 | 0xB6 | invokevirtual | 2 | 1
16+
9 | 0xB2 | getstatic | 0 | 1
17+
12 | 0x2A | aload_0 | 1 | 1
18+
13 | 0x04 | iconst_1 | 2 | 1
19+
14 | 0x32 | aaload | 3 | 1
20+
15 | 0xB6 | invokevirtual | 2 | 1
21+
18 | 0xB2 | getstatic | 0 | 1
22+
21 | 0x2A | aload_0 | 1 | 1
23+
22 | 0x05 | iconst_2 | 2 | 1
24+
23 | 0x32 | aaload | 3 | 1
25+
24 | 0xB6 | invokevirtual | 2 | 1
26+
27 | 0xB1 | return | 0 | 1
27+
---------+--------+----------------------+------------+-----------------
28+

0 commit comments

Comments
 (0)