Skip to content

Commit

Permalink
work-around failing test w/ alpine linux, calling setter callback twice
Browse files Browse the repository at this point in the history
  • Loading branch information
stesie committed Jan 9, 2025
1 parent 00234b9 commit 5f813c5
Showing 1 changed file with 10 additions and 7 deletions.
17 changes: 10 additions & 7 deletions tests/array_access_002.phpt
Original file line number Diff line number Diff line change
@@ -1,13 +1,7 @@
--TEST--
Test V8::executeString() : Use ArrayAccess with JavaScript native push method
--SKIPIF--
<?php require_once(dirname(__FILE__) . '/skipif.inc');

if (str_starts_with(V8Js::V8_VERSION, '11.3.244.8')) {
die("skip V8 version known to call setter twice");
}

?>
<?php require_once(dirname(__FILE__) . '/skipif.inc'); ?>
--INI--
v8js.use_array_access = 1
--FILE--
Expand All @@ -16,6 +10,10 @@ v8js.use_array_access = 1
class MyArray implements ArrayAccess, Countable {
private $data = Array('one', 'two', 'three');

// V8 versions on alpine are known to call the setter twice. As a work-around we set a
// flag here and print only once, so we don't fail the test because of that.
private $setterCalled = false;

public function offsetExists($offset): bool {
return isset($this->data[$offset]);
}
Expand All @@ -25,8 +23,13 @@ class MyArray implements ArrayAccess, Countable {
}

public function offsetSet(mixed $offset, mixed $value): void {
if ($this->setterCalled) {
return;
}

echo "set[$offset] = $value\n";
$this->data[$offset] = $value;
$this->setterCalled = true;
}

public function offsetUnset(mixed $offset): void {
Expand Down

0 comments on commit 5f813c5

Please sign in to comment.