Skip to content

Commit cb7b3dc

Browse files
committed
Optimize and fix test reference from @redbullmarky
1 parent 1db8f8d commit cb7b3dc

19 files changed

+520
-236
lines changed

tests/array_access.phpt

Lines changed: 39 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -7,25 +7,49 @@ v8js.use_array_access = 1
77
--FILE--
88
<?php
99

10-
class MyArray implements ArrayAccess, Countable {
11-
public function offsetExists($offset): bool {
12-
return $offset >= 0 && $offset <= 20;
13-
}
10+
if (PHP_VERSION_ID < 80000) {
11+
class MyArray implements ArrayAccess, Countable {
12+
public function offsetExists($offset) {
13+
return $offset >= 0 && $offset <= 20;
14+
}
1415

15-
public function offsetGet($offset): mixed {
16-
return 19 - $offset;
17-
}
16+
public function offsetGet($offset) {
17+
return 19 - $offset;
18+
}
1819

19-
public function offsetSet($offset, $value): void {
20-
throw new Exception('Not implemented');
21-
}
20+
public function offsetSet($offset, $value) {
21+
throw new Exception('Not implemented');
22+
}
2223

23-
public function offsetUnset($offset): void {
24-
throw new Exception('Not implemented');
25-
}
24+
public function offsetUnset($offset) {
25+
throw new Exception('Not implemented');
26+
}
2627

27-
public function count(): int {
28-
return 20;
28+
public function count() {
29+
return 20;
30+
}
31+
}
32+
} else {
33+
class MyArray implements ArrayAccess, Countable {
34+
public function offsetExists($offset): bool {
35+
return $offset >= 0 && $offset <= 20;
36+
}
37+
38+
public function offsetGet(mixed $offset): mixed {
39+
return 19 - $offset;
40+
}
41+
42+
public function offsetSet(mixed $offset, mixed $value): void {
43+
throw new Exception('Not implemented');
44+
}
45+
46+
public function offsetUnset(mixed $offset): void {
47+
throw new Exception('Not implemented');
48+
}
49+
50+
public function count(): int {
51+
return 20;
52+
}
2953
}
3054
}
3155

tests/array_access_001.phpt

Lines changed: 48 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -7,31 +7,61 @@ v8js.use_array_access = 1
77
--FILE--
88
<?php
99

10-
class MyArray implements ArrayAccess, Countable {
11-
private $data = Array('one', 'two', 'three');
10+
if (PHP_VERSION_ID < 80000) {
11+
class MyArray implements ArrayAccess, Countable {
12+
private $data = Array('one', 'two', 'three');
1213

13-
public function offsetExists($offset): bool {
14-
return isset($this->data[$offset]);
15-
}
14+
public function offsetExists($offset) {
15+
return isset($this->data[$offset]);
16+
}
1617

17-
public function offsetGet($offset): mixed {
18-
return $this->data[$offset];
19-
}
18+
public function offsetGet($offset) {
19+
return $this->data[$offset];
20+
}
2021

21-
public function offsetSet($offset, $value): void {
22-
$this->data[$offset] = $value;
23-
}
22+
public function offsetSet($offset, $value) {
23+
$this->data[$offset] = $value;
24+
}
2425

25-
public function offsetUnset($offset): void {
26-
throw new Exception('Not implemented');
27-
}
26+
public function offsetUnset($offset) {
27+
throw new Exception('Not implemented');
28+
}
29+
30+
public function count() {
31+
return count($this->data);
32+
}
2833

29-
public function count(): int {
30-
return count($this->data);
34+
public function push($value) {
35+
$this->data[] = $value;
36+
}
3137
}
38+
} else {
39+
class MyArray implements ArrayAccess, Countable {
40+
private $data = Array('one', 'two', 'three');
41+
42+
public function offsetExists($offset): bool {
43+
return isset($this->data[$offset]);
44+
}
45+
46+
public function offsetGet(mixed $offset): mixed {
47+
return $this->data[$offset];
48+
}
49+
50+
public function offsetSet(mixed $offset, mixed $value): void {
51+
$this->data[$offset] = $value;
52+
}
53+
54+
public function offsetUnset(mixed $offset): void {
55+
throw new Exception('Not implemented');
56+
}
57+
58+
public function count(): int {
59+
return count($this->data);
60+
}
3261

33-
public function push($value) {
34-
$this->data[] = $value;
62+
public function push($value) {
63+
$this->data[] = $value;
64+
}
3565
}
3666
}
3767

tests/array_access_002.phpt

Lines changed: 43 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -6,29 +6,55 @@ Test V8::executeString() : Use ArrayAccess with JavaScript native push method
66
v8js.use_array_access = 1
77
--FILE--
88
<?php
9+
if (PHP_VERSION_ID < 80000) {
10+
class MyArray implements ArrayAccess, Countable {
11+
private $data = Array('one', 'two', 'three');
912

10-
class MyArray implements ArrayAccess, Countable {
11-
private $data = Array('one', 'two', 'three');
13+
public function offsetExists($offset) {
14+
return isset($this->data[$offset]);
15+
}
1216

13-
public function offsetExists($offset): bool {
14-
return isset($this->data[$offset]);
15-
}
17+
public function offsetGet($offset) {
18+
return $this->data[$offset];
19+
}
1620

17-
public function offsetGet($offset): mixed {
18-
return $this->data[$offset];
19-
}
21+
public function offsetSet($offset, $value) {
22+
echo "set[$offset] = $value\n";
23+
$this->data[$offset] = $value;
24+
}
2025

21-
public function offsetSet($offset, $value): void {
22-
echo "set[$offset] = $value\n";
23-
$this->data[$offset] = $value;
24-
}
26+
public function offsetUnset($offset) {
27+
throw new Exception('Not implemented');
28+
}
2529

26-
public function offsetUnset($offset): void {
27-
throw new Exception('Not implemented');
30+
public function count() {
31+
return count($this->data);
32+
}
2833
}
29-
30-
public function count(): int {
31-
return count($this->data);
34+
} else {
35+
class MyArray implements ArrayAccess, Countable {
36+
private $data = Array('one', 'two', 'three');
37+
38+
public function offsetExists($offset): bool {
39+
return isset($this->data[$offset]);
40+
}
41+
42+
public function offsetGet(mixed $offset): mixed {
43+
return $this->data[$offset];
44+
}
45+
46+
public function offsetSet(mixed $offset, mixed $value): void {
47+
echo "set[$offset] = $value\n";
48+
$this->data[$offset] = $value;
49+
}
50+
51+
public function offsetUnset(mixed $offset): void {
52+
throw new Exception('Not implemented');
53+
}
54+
55+
public function count(): int {
56+
return count($this->data);
57+
}
3258
}
3359
}
3460

tests/array_access_003.phpt

Lines changed: 70 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -6,40 +6,77 @@ Test V8::executeString() : Export PHP methods on ArrayAccess objects
66
v8js.use_array_access = 1
77
--FILE--
88
<?php
9-
10-
class MyArray implements ArrayAccess, Countable {
11-
private $data = Array('one', 'two', 'three');
12-
13-
public function offsetExists($offset): bool {
14-
return isset($this->data[$offset]);
15-
}
16-
17-
public function offsetGet($offset): mixed {
18-
return $this->data[$offset];
9+
if (PHP_VERSION_ID < 80000) {
10+
class MyArray implements ArrayAccess, Countable {
11+
private $data = Array('one', 'two', 'three');
12+
13+
public function offsetExists($offset) {
14+
return isset($this->data[$offset]);
15+
}
16+
17+
public function offsetGet($offset) {
18+
return $this->data[$offset];
19+
}
20+
21+
public function offsetSet($offset, $value) {
22+
echo "set[$offset] = $value\n";
23+
$this->data[$offset] = $value;
24+
}
25+
26+
public function offsetUnset($offset) {
27+
throw new Exception('Not implemented');
28+
}
29+
30+
public function count() {
31+
echo 'count() = ', count($this->data), "\n";
32+
return count($this->data);
33+
}
34+
35+
public function phpSidePush($value) {
36+
echo "push << $value\n";
37+
$this->data[] = $value;
38+
}
39+
40+
public function push($value) {
41+
echo "php-side-push << $value\n";
42+
$this->data[] = $value;
43+
}
1944
}
20-
21-
public function offsetSet($offset, $value): void {
22-
echo "set[$offset] = $value\n";
23-
$this->data[$offset] = $value;
24-
}
25-
26-
public function offsetUnset($offset): void {
27-
throw new Exception('Not implemented');
28-
}
29-
30-
public function count(): int {
31-
echo 'count() = ', count($this->data), "\n";
32-
return count($this->data);
33-
}
34-
35-
public function phpSidePush($value) {
36-
echo "push << $value\n";
37-
$this->data[] = $value;
38-
}
39-
40-
public function push($value) {
41-
echo "php-side-push << $value\n";
42-
$this->data[] = $value;
45+
} else {
46+
class MyArray implements ArrayAccess, Countable {
47+
private $data = Array('one', 'two', 'three');
48+
49+
public function offsetExists($offset): bool {
50+
return isset($this->data[$offset]);
51+
}
52+
53+
public function offsetGet(mixed $offset): mixed {
54+
return $this->data[$offset];
55+
}
56+
57+
public function offsetSet(mixed $offset, mixed $value): void {
58+
echo "set[$offset] = $value\n";
59+
$this->data[$offset] = $value;
60+
}
61+
62+
public function offsetUnset(mixed $offset): void {
63+
throw new Exception('Not implemented');
64+
}
65+
66+
public function count(): int {
67+
echo 'count() = ', count($this->data), "\n";
68+
return count($this->data);
69+
}
70+
71+
public function phpSidePush($value) {
72+
echo "push << $value\n";
73+
$this->data[] = $value;
74+
}
75+
76+
public function push($value) {
77+
echo "php-side-push << $value\n";
78+
$this->data[] = $value;
79+
}
4380
}
4481
}
4582

0 commit comments

Comments
 (0)