mirror of
https://github.com/phpv8/v8js.git
synced 2024-11-09 15:18:41 +00:00
Add tests with multiple V8Js instances
This commit is contained in:
parent
35685ed96c
commit
e57e3eed1d
43
tests/multi-object.phpt
Normal file
43
tests/multi-object.phpt
Normal file
@ -0,0 +1,43 @@
|
|||||||
|
--TEST--
|
||||||
|
Test V8::executeString() : Use multiple V8js instances with objects
|
||||||
|
--SKIPIF--
|
||||||
|
<?php require_once(dirname(__FILE__) . '/skipif.inc'); ?>
|
||||||
|
--FILE--
|
||||||
|
<?php
|
||||||
|
|
||||||
|
class TestClass {
|
||||||
|
protected $_instNo;
|
||||||
|
|
||||||
|
public function __construct($num) {
|
||||||
|
$this->_instNo = $num;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function sayHello() {
|
||||||
|
echo 'Hello World! This is instance '.$this->_instNo."\n";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
$instances = array();
|
||||||
|
for($i = 0; $i < 5; $i ++) {
|
||||||
|
$v8 = new V8Js();
|
||||||
|
$v8->test = new TestClass($i);
|
||||||
|
$instances[] = $v8;
|
||||||
|
}
|
||||||
|
|
||||||
|
$JS = <<< EOT
|
||||||
|
php.test.sayHello();
|
||||||
|
EOT;
|
||||||
|
|
||||||
|
foreach($instances as $v8) {
|
||||||
|
$v8->executeString($JS, 'basic.js');
|
||||||
|
}
|
||||||
|
|
||||||
|
?>
|
||||||
|
===EOF===
|
||||||
|
--EXPECT--
|
||||||
|
Hello World! This is instance 0
|
||||||
|
Hello World! This is instance 1
|
||||||
|
Hello World! This is instance 2
|
||||||
|
Hello World! This is instance 3
|
||||||
|
Hello World! This is instance 4
|
||||||
|
===EOF===
|
32
tests/multi.phpt
Normal file
32
tests/multi.phpt
Normal file
@ -0,0 +1,32 @@
|
|||||||
|
--TEST--
|
||||||
|
Test V8::executeString() : Use multiple V8js instances
|
||||||
|
--SKIPIF--
|
||||||
|
<?php require_once(dirname(__FILE__) . '/skipif.inc'); ?>
|
||||||
|
--FILE--
|
||||||
|
<?php
|
||||||
|
|
||||||
|
$instances = array();
|
||||||
|
for($i = 0; $i < 5; $i ++) {
|
||||||
|
$v8 = new V8Js();
|
||||||
|
$v8->executeString('var instNo = '.$i);
|
||||||
|
$instances[] = $v8;
|
||||||
|
}
|
||||||
|
|
||||||
|
$JS = <<< EOT
|
||||||
|
len = print('Hello' + ' ' + 'World! This is instance ' + instNo + "\\n");
|
||||||
|
len;
|
||||||
|
EOT;
|
||||||
|
|
||||||
|
foreach($instances as $v8) {
|
||||||
|
$v8->executeString($JS, 'basic.js');
|
||||||
|
}
|
||||||
|
|
||||||
|
?>
|
||||||
|
===EOF===
|
||||||
|
--EXPECT--
|
||||||
|
Hello World! This is instance 0
|
||||||
|
Hello World! This is instance 1
|
||||||
|
Hello World! This is instance 2
|
||||||
|
Hello World! This is instance 3
|
||||||
|
Hello World! This is instance 4
|
||||||
|
===EOF===
|
Loading…
Reference in New Issue
Block a user