summaryrefslogtreecommitdiff
path: root/tests/php
diff options
context:
space:
mode:
authorvalmat <ufabiz@gmail.com>2014-03-27 01:19:12 +0600
committervalmat <ufabiz@gmail.com>2014-03-27 01:19:12 +0600
commitd0d062b4a05a9eb64b8d2e6d038af96ac532e4b3 (patch)
tree4fc4026b988ca6da18a88d2e34dd1d88c28d24ae /tests/php
parent702c95cf779226550af6b33255a8e1b28ccca428 (diff)
Added new tests.
Due to support zts broke the ability to run tests without installation - fixed.
Diffstat (limited to 'tests/php')
-rw-r--r--tests/php/dbg.php45
-rw-r--r--tests/php/phpt/valueiterator/006.phpt- (renamed from tests/php/phpt/valueiterator/006.phpt)0
-rw-r--r--tests/php/phpt/variables/001-process_globals.phpt-47
-rw-r--r--tests/php/phpt/variables/002-get_complex_array.phpt-33
-rw-r--r--tests/php/phpt/variables/003-value-types.phpt-72
-rw-r--r--tests/php/phpt/variables/004-store-scalar-variables.phpt58
-rw-r--r--tests/php/phpt/variables/005-value-casting-operators.phpt-174
-rw-r--r--tests/php/phpt/variables/006-casting-obj2str.phpt31
-rw-r--r--tests/php/phpt/variables/007-overloaded-operators.phpt51
-rw-r--r--tests/php/phpt/variables/008-value-arrays.phpt-89
-rw-r--r--tests/php/phpt/variables/009-value-object.phpt-24
-rw-r--r--tests/php/phpt/variables/010-value-object2.phpt24
-rw-r--r--tests/php/phpt/variables/readme1
13 files changed, 604 insertions, 45 deletions
diff --git a/tests/php/dbg.php b/tests/php/dbg.php
index 6f1dabc..9a28fc6 100644
--- a/tests/php/dbg.php
+++ b/tests/php/dbg.php
@@ -6,51 +6,6 @@
*/
-function out($obj) {
-
-
- $cl_name = is_object($obj) ?
- get_class($obj) :
- (is_array($obj) ? "Array" : "----");
-
- echo "++++-" , $cl_name , "-++++\n";
-
- echo "\x1b[1;31m";
- echo "\n Native iterate:\n\n";
- foreach($obj as $k => $v) {
- echo "$k\t=>\t$v\n";
- }
- echo "\x1b[0m";
-
-
- TestValueIterator\loopValue($obj);
-}
-
-
-
-require './include/valueiterator/1.php';
-
-#$arr = array('qwe' => 'qweqweqweqw',5,'asd' => '«£¥§©®°±¶⅐⅒⅓⅘⅞Ⅻↆ❄❅❆⚑⚐⌛⌚〰»', 'zxccvx' => 'sdfsecvyh6bug6yfty',);
-#$obj = (object)$arr;
-#$smpl = new SimpleClass;
-#$it = new impIterator;
-#$iag1 = new impIterAggr1;
-$iag2 = new impIterAggr2;
-
-
-//out($arr);
-#out($obj);
-#out($smpl);
-TestValueIterator\loopValue($iag2);
-#out($it);
-#out($iag1);
-#out($iag2);
-
-
-
-
-
-
diff --git a/tests/php/phpt/valueiterator/006.phpt b/tests/php/phpt/valueiterator/006.phpt-
index ea97c2b..ea97c2b 100644
--- a/tests/php/phpt/valueiterator/006.phpt
+++ b/tests/php/phpt/valueiterator/006.phpt-
diff --git a/tests/php/phpt/variables/001-process_globals.phpt- b/tests/php/phpt/variables/001-process_globals.phpt-
new file mode 100644
index 0000000..022e99c
--- /dev/null
+++ b/tests/php/phpt/variables/001-process_globals.phpt-
@@ -0,0 +1,47 @@
+--TEST--
+Global variables in PHP-CPP
+--DESCRIPTION--
+The author of the original: Jasper van Eck<jasper.vaneck@copernica.com>
+--SKIPIF--
+<?php if (!extension_loaded("extension_for_tests")) print "skip"; ?>
+--FILEEOF--
+<?php
+
+// we first need to set a number of globals
+$b = 10;
+$d = function($a,$b,$c) {
+ return $a+$b+$c;
+};
+
+// fun global var
+$e = array(
+ function($a) {
+ return $a;
+ }
+);
+
+
+// call the C++ function that will do something
+$d = TestVariables\process_globals();
+
+// the global variable $a should not have the value 1
+echo("a = $a\n");
+
+// the variable $b should not be 11
+echo("b = $b\n");
+
+// $c should be an array with value 200
+echo("c['member'] = ".$c['member']."\n");
+
+// $d is overwritten and now is 6
+echo("d = $d\n");
+
+// e should be replaced by a string
+echo("e = $e\n");
+
+--EXPECT--
+a = 1
+b = 11
+c['member'] = 200
+d = 6
+e = hello \ No newline at end of file
diff --git a/tests/php/phpt/variables/002-get_complex_array.phpt- b/tests/php/phpt/variables/002-get_complex_array.phpt-
new file mode 100644
index 0000000..f13afa6
--- /dev/null
+++ b/tests/php/phpt/variables/002-get_complex_array.phpt-
@@ -0,0 +1,33 @@
+--TEST--
+get_complex_array
+--SKIPIF--
+<?php if (!extension_loaded("extension_for_tests")) print "skip"; ?>
+--FILEEOF--
+<?php
+
+/*
+function get_complex_array()
+{
+ return array(
+ "a" => 123,
+ "b" => 456,
+ "c" => array("nested_value","example",7)
+ );
+}
+var_export(get_complex_array());
+*/
+var_export(TestVariables\get_complex_array());
+
+
+echo PHP_EOL;
+--EXPECT--
+array (
+ 'a' => 123,
+ 'b' => 456,
+ 'c' =>
+ array (
+ 0 => 'nested_value',
+ 1 => 'example',
+ 2 => 7,
+ ),
+) \ No newline at end of file
diff --git a/tests/php/phpt/variables/003-value-types.phpt- b/tests/php/phpt/variables/003-value-types.phpt-
new file mode 100644
index 0000000..477fbe2
--- /dev/null
+++ b/tests/php/phpt/variables/003-value-types.phpt-
@@ -0,0 +1,72 @@
+--TEST--
+get_complex_array
+--SKIPIF--
+<?php if (!extension_loaded("extension_for_tests")) print "skip"; ?>
+--FILEEOF--
+<?php
+
+
+# check Callable: http://php.net/manual/en/function.is-callable.php
+function ret5() {return 5;}
+class someClass {
+ function someMethod() {return 5;}
+}
+class CallableClass {
+ public function __invoke(){}
+}
+
+$anObject = new someClass();
+$methodVariable = array($anObject, 'someMethod');
+
+
+# check array
+$arr = array(
+ 'Null' => NULL,
+ 'Numeric' => 2014,
+ 'Float' => 3.14,
+ 'Bool' => true,
+ 'Array' => array(5,'a' => 33, 'str'),
+ 'Object' => new stdClass(),
+ 'String' => 'String',
+ 'Resource' => 7,
+ 'Constant' => 5,
+ 'ConstantArray' => 11,
+ 'Callable1' => 'ret5',
+ 'Callable2' => $methodVariable,
+ 'Callable3' => function () {return 5;},
+ 'Callable4' => new CallableClass()
+);
+
+TestVariables\value_types($arr);
+
+//To check uncomment the following lines:
+/*
+echo "\n\nCallable1:";
+var_export(is_callable($arr['Callable1']));
+echo PHP_EOL,'Callable2:';
+var_export(is_callable($arr['Callable2']));
+echo PHP_EOL,'Callable3:';
+var_export(is_callable($arr['Callable3']));
+echo PHP_EOL,'Callable4:';
+var_export(is_callable($arr['Callable4']));
+echo PHP_EOL,'No Callable:';
+var_export(is_callable(new stdClass));
+*/
+
+
+echo PHP_EOL;
+--EXPECT--
+Null: Yes
+Numeric: Yes
+Float: Yes
+Bool: Yes
+Array: Yes
+Object: Yes
+String: Yes
+Resource: No
+Constant: No
+ConstantArray: No
+Callable1: Yes
+Callable2: Yes
+Callable3: Yes
+Callable4: Yes \ No newline at end of file
diff --git a/tests/php/phpt/variables/004-store-scalar-variables.phpt b/tests/php/phpt/variables/004-store-scalar-variables.phpt
new file mode 100644
index 0000000..53cc681
--- /dev/null
+++ b/tests/php/phpt/variables/004-store-scalar-variables.phpt
@@ -0,0 +1,58 @@
+--TEST--
+Test variables defined in PHP-CPP
+--DESCRIPTION--
+in PHP-CPP:
+Php::Value scalar_store(void) {
+
+ Php::Value value1 = 1234;
+ Php::Value value2 = "this is a string";
+ Php::Value value3 = std::string("another string");
+ Php::Value value4 = nullptr;
+ Php::Value value5 = 123.45;
+ Php::Value value6 = true;
+
+ Php::Value r;
+ r[0] = value1;
+ r[1] = value2;
+ r[2] = value3;
+ r[3] = value4;
+ r[4] = value5;
+ r[5] = value6;
+
+ r[6] = 1234;
+ r[7] = "this is a string";
+ r[8] = std::string("another string");
+ r[9] = nullptr; // NULL
+ r[10] = Php::Value(); // NULL
+ r[11] = 123.45;
+ r[12] = false;
+
+ return r;
+}
+
+--SKIPIF--
+<?php if (!extension_loaded("extension_for_tests")) print "skip"; ?>
+--FILEEOF--
+<?php
+
+
+var_export(TestVariables\scalar_store());
+
+
+//echo PHP_EOL;
+--EXPECT--
+array (
+ 0 => 1234,
+ 1 => 'this is a string',
+ 2 => 'another string',
+ 3 => NULL,
+ 4 => 123.45,
+ 5 => true,
+ 6 => 1234,
+ 7 => 'this is a string',
+ 8 => 'another string',
+ 9 => NULL,
+ 10 => NULL,
+ 11 => 123.45,
+ 12 => false,
+)
diff --git a/tests/php/phpt/variables/005-value-casting-operators.phpt- b/tests/php/phpt/variables/005-value-casting-operators.phpt-
new file mode 100644
index 0000000..5e0fb8e
--- /dev/null
+++ b/tests/php/phpt/variables/005-value-casting-operators.phpt-
@@ -0,0 +1,174 @@
+--TEST--
+Test Php::Value casting operators
+--DESCRIPTION--
+The Php::Value class has casting operators to cast the object to almost every thinkable native type.
+
+
+It seems need to replace double on long double
+
+native_value_casting - repeats the behavior of c++ functions TestVariables\value_casting
+the output of each of these functions should be the same
+
+
+--SKIPIF--
+<?php if (!extension_loaded("extension_for_tests")) print "skip"; ?>
+--FILEEOF--
+<?php
+
+
+function bool2str($b) {
+ return $b ? "Yes" : "No";
+}
+function native_value_casting($value) {
+ echo " long:", (int)$value, "\n string:", (string)$value, "\n double:", (double)$value, "\n bool:", bool2str((bool)$value), PHP_EOL;
+}
+
+
+function out($v) {
+ echo 'Test ';
+ var_export($v);
+ echo ':', PHP_EOL;
+ TestVariables\value_casting($v);
+ //native_value_casting($v);
+ echo PHP_EOL;
+}
+
+out(5555555555555555);
+out("9223372036854775807");
+out(9223372036854775807);
+out(5);
+out(-99999999);
+out("18");
+out("3.14159265359");
+out(3.14159265359);
+out(25/7);
+out(" this is a string ");
+out(" 2-nd string ");
+out("false");
+out(false);
+out("true");
+out(true);
+out(0);
+out("0");
+out(0123); // octal number (equivalent to 83 decimal)
+out(0x1A); // hexadecimal number (equivalent to 26 decimal)
+
+
+
+
+//echo PHP_EOL;
+--EXPECT--
+Test 5555555555555555:
+ long:5555555555555555
+ string:5555555555555555
+ double:5.5555555555556E+15
+ bool:Yes
+
+Test '9223372036854775807':
+ long:9223372036854775807
+ string:9223372036854775807
+ double:9.2233720368548E+18
+ bool:Yes
+
+Test 9223372036854775807:
+ long:9223372036854775807
+ string:9223372036854775807
+ double:9.2233720368548E+18
+ bool:Yes
+
+Test 5:
+ long:5
+ string:5
+ double:5
+ bool:Yes
+
+Test -99999999:
+ long:-99999999
+ string:-99999999
+ double:-99999999
+ bool:Yes
+
+Test '18':
+ long:18
+ string:18
+ double:18
+ bool:Yes
+
+Test '3.14159265359':
+ long:3
+ string:3.14159265359
+ double:3.14159265359
+ bool:Yes
+
+Test 3.14159265359:
+ long:3
+ string:3.14159265359
+ double:3.14159265359
+ bool:Yes
+
+Test 3.5714285714286:
+ long:3
+ string:3.5714285714286
+ double:3.5714285714286
+ bool:Yes
+
+Test ' this is a string ':
+ long:0
+ string: this is a string
+ double:0
+ bool:Yes
+
+Test ' 2-nd string ':
+ long:2
+ string: 2-nd string
+ double:2
+ bool:Yes
+
+Test 'false':
+ long:0
+ string:false
+ double:0
+ bool:Yes
+
+Test false:
+ long:0
+ string:
+ double:0
+ bool:No
+
+Test 'true':
+ long:0
+ string:true
+ double:0
+ bool:Yes
+
+Test true:
+ long:1
+ string:1
+ double:1
+ bool:Yes
+
+Test 0:
+ long:0
+ string:0
+ double:0
+ bool:No
+
+Test '0':
+ long:0
+ string:0
+ double:0
+ bool:No
+
+Test 83:
+ long:83
+ string:83
+ double:83
+ bool:Yes
+
+Test 26:
+ long:26
+ string:26
+ double:26
+ bool:Yes
+
diff --git a/tests/php/phpt/variables/006-casting-obj2str.phpt b/tests/php/phpt/variables/006-casting-obj2str.phpt
new file mode 100644
index 0000000..53d9707
--- /dev/null
+++ b/tests/php/phpt/variables/006-casting-obj2str.phpt
@@ -0,0 +1,31 @@
+--TEST--
+Test Php::Value casting operators (object to string)
+--DESCRIPTION--
+
+Converting a php object to a string
+
+
+--SKIPIF--
+<?php if (!extension_loaded("extension_for_tests")) print "skip"; ?>
+--FILEEOF--
+<?php
+
+
+function native_value_casting($value) {
+ echo (string)$value, PHP_EOL;
+}
+class TestClass
+{
+ public function __toString() {return "I am TestClass";}
+}
+
+TestVariables\value_cast2str(new TestClass());
+//native_value_casting(new TestClass());
+
+TestVariables\value_cast2str("some string");
+
+
+
+--EXPECT--
+I am TestClass
+some string \ No newline at end of file
diff --git a/tests/php/phpt/variables/007-overloaded-operators.phpt b/tests/php/phpt/variables/007-overloaded-operators.phpt
new file mode 100644
index 0000000..a26b1a4
--- /dev/null
+++ b/tests/php/phpt/variables/007-overloaded-operators.phpt
@@ -0,0 +1,51 @@
+--TEST--
+Test Php::Value overloaded operators
+--DESCRIPTION--
+
+Many different operators are overloaded too so that you can use a Php::Value object directly in arithmetric operations,
+compare it with other variables, or send it to an output stream.
+
+
+--SKIPIF--
+<?php if (!extension_loaded("extension_for_tests")) print "skip"; ?>
+--FILEEOF--
+<?php
+
+
+TestVariables\overloaded_op(5);
+TestVariables\overloaded_op(3.14);
+TestVariables\overloaded_op(12);
+TestVariables\overloaded_op(120);
+TestVariables\overloaded_op(-1000);
+TestVariables\overloaded_op("some string");
+
+
+
+--EXPECT--
+15
+7
+1851.75
+0.121507
+13.14
+5
+1622.13
+0.10644
+value == 12
+22
+14
+2715.9
+0.17821
+value > 100
+130
+122
+16048.5
+1.05306
+-990
+-998
+-122216
+-8.01944
+value == 'some string'
+10
+2
+1234.5
+0.0810045 \ No newline at end of file
diff --git a/tests/php/phpt/variables/008-value-arrays.phpt- b/tests/php/phpt/variables/008-value-arrays.phpt-
new file mode 100644
index 0000000..6950780
--- /dev/null
+++ b/tests/php/phpt/variables/008-value-arrays.phpt-
@@ -0,0 +1,89 @@
+--TEST--
+Test Php::Value arrays
+--DESCRIPTION--
+--SKIPIF--
+<?php if (!extension_loaded("extension_for_tests")) print "skip"; ?>
+--FILEEOF--
+<?php
+
+
+$r = TestVariables\value_arrays();
+
+ // To check:
+/*
+ $array;
+ $array[0] = "apple";
+ $array[1] = "banana";
+ $array[2] = "tomato";
+
+ // an initializer list can be used to create a filled array
+ $filled = ["a", "b", "c", "d"];
+
+ // create an associative array
+ $assoc["apple"] = "green";
+ $assoc["banana"] = "yellow";
+ $assoc["tomato"] = "green";
+
+ // the variables in an array do not all have to be of the same type
+ $assoc2["x"] = "info@example.com";
+ $assoc2["y"] = NULL;
+ $assoc2["z"] = 123;
+
+ // nested arrays are possible too
+ $assoc3["x"] = "info@example.com";
+ $assoc3["y"] = NULL;
+ $assoc3["z"][0] = "a";
+ $assoc3["z"][1] = "b";
+ $assoc3["z"][2] = "c";
+
+ $r = [];
+ $r["array"] = $array;
+ $r["filled"] = $filled;
+ $r["assoc"] = $assoc;
+ $r["assoc2"] = $assoc2;
+ $r["assoc3"] = $assoc3;
+*/
+
+var_export($r);
+
+
+
+--EXPECT--
+array (
+ 'array' =>
+ array (
+ 0 => 'apple',
+ 1 => 'banana',
+ 2 => 'tomato',
+ ),
+ 'filled' =>
+ array (
+ 0 => 'a',
+ 1 => 'b',
+ 2 => 'c',
+ 3 => 'd',
+ ),
+ 'assoc' =>
+ array (
+ 'apple' => 'green',
+ 'banana' => 'yellow',
+ 'tomato' => 'green',
+ ),
+ 'assoc2' =>
+ array (
+ 'x' => 'info@example.com',
+ 'y' => NULL,
+ 'z' => 123,
+ ),
+ 'assoc3' =>
+ array (
+ 'x' => 'info@example.com',
+ 'y' => NULL,
+ 'z' =>
+ array (
+ 0 => 'a',
+ 1 => 'b',
+ 2 => 'c',
+ ),
+ ),
+) \ No newline at end of file
diff --git a/tests/php/phpt/variables/009-value-object.phpt- b/tests/php/phpt/variables/009-value-object.phpt-
new file mode 100644
index 0000000..c45cae8
--- /dev/null
+++ b/tests/php/phpt/variables/009-value-object.phpt-
@@ -0,0 +1,24 @@
+--TEST--
+Test Php::Value object #1
+--DESCRIPTION--
+ create empty object of type stdClass
+ object properties can be accessed with square brackets
+--SKIPIF--
+<?php if (!extension_loaded("extension_for_tests")) print "skip"; ?>
+--FILEEOF--
+<?php
+
+
+$object = TestVariables\value_object1();
+
+//$object = (object)array("property1" => "value1", "property2" => "value2");
+
+var_export($object);
+
+
+
+--EXPECT--
+stdClass::__set_state(array(
+ 'property1' => 'value1',
+ 'property2' => 'value2',
+)) \ No newline at end of file
diff --git a/tests/php/phpt/variables/010-value-object2.phpt b/tests/php/phpt/variables/010-value-object2.phpt
new file mode 100644
index 0000000..8697a69
--- /dev/null
+++ b/tests/php/phpt/variables/010-value-object2.phpt
@@ -0,0 +1,24 @@
+--TEST--
+Test Php::Value object #2
+--DESCRIPTION--
+ create empty object of type stdClass
+ object properties can be accessed with square brackets
+--SKIPIF--
+<?php if (!extension_loaded("extension_for_tests")) print "skip"; ?>
+--FILEEOF--
+<?php
+
+
+//date_default_timezone_set('Europe/Amsterdam');
+var_export(TestVariables\value_object2());
+
+
+--EXPECT--
+2014-03-27 00:37:15
+2016-03-31 15:48:00
+7200
+DateTime::__set_state(array(
+ 'date' => '2014-03-27 00:37:15',
+ 'timezone_type' => 3,
+ 'timezone' => 'Europe/Amsterdam',
+)) \ No newline at end of file
diff --git a/tests/php/phpt/variables/readme b/tests/php/phpt/variables/readme
new file mode 100644
index 0000000..8162526
--- /dev/null
+++ b/tests/php/phpt/variables/readme
@@ -0,0 +1 @@
+tests variables