summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorEmiel Bruijntjes <emiel.bruijntjes@copernica.com>2014-03-29 13:10:46 +0100
committerEmiel Bruijntjes <emiel.bruijntjes@copernica.com>2014-03-29 13:10:46 +0100
commit7b7efa4f80dc5c9d26b59087270a8d89fedcc808 (patch)
tree1dfb0ce4a6662a5bcb6562b40ab91f813a959afc /tests
parentc0e1f20eeab6445d6355ea11ef7d264cb37c52cf (diff)
parent8bd7f5162870e4b39c7629c1a67a3372402406c9 (diff)
Merge pull request #56 from valmat/tests
New tests
Diffstat (limited to 'tests')
-rw-r--r--tests/cpp/h/Classes_and_objects.h14
-rw-r--r--tests/cpp/h/ValueIterator.h8
-rw-r--r--tests/cpp/h/variables.h28
-rw-r--r--tests/cpp/include/bool2str.h12
-rw-r--r--tests/cpp/include/class_obj/001-002.h (renamed from tests/cpp/include/MyCustomClass.h)16
-rw-r--r--tests/cpp/include/class_obj/003-comparable.h74
-rw-r--r--tests/cpp/include/class_obj/004-static-funct.h90
-rw-r--r--tests/cpp/include/class_obj/tpl.h25
-rw-r--r--tests/cpp/include/doubl2str.h102
-rw-r--r--tests/cpp/include/valueiterator/001-006.h (renamed from tests/cpp/include/ValueIterator.h)2
-rw-r--r--tests/cpp/include/valueiterator/007.h44
-rw-r--r--tests/cpp/include/variables.h293
-rw-r--r--tests/cpp/include/variables/001-process_globals.h57
-rw-r--r--tests/cpp/include/variables/002-get_complex_array.h35
-rw-r--r--tests/cpp/include/variables/003-value-types.h37
-rw-r--r--tests/cpp/include/variables/004-store-scalar-variables.h48
-rw-r--r--tests/cpp/include/variables/005-cast-objects-to-scalars.h75
-rw-r--r--tests/cpp/include/variables/006-casting-obj2str.h30
-rw-r--r--tests/cpp/include/variables/007-overloaded-operators.h46
-rw-r--r--tests/cpp/include/variables/008-value-arrays.h57
-rw-r--r--tests/cpp/include/variables/009-010-value-object.h68
-rw-r--r--tests/cpp/include/variables/011-012-value-casting-operators.h52
-rw-r--r--tests/cpp/include/variables/013-018-calling-php-functions.h117
-rw-r--r--tests/cpp/include/variables/tpl.h30
-rw-r--r--tests/cpp/main.cpp58
-rw-r--r--tests/php/dbg.php1
-rwxr-xr-xtests/php/php_alias.sh2
-rw-r--r--tests/php/phpt/class_obj/001.phpt (renamed from tests/php/phpt/base/001.phpt)0
-rw-r--r--tests/php/phpt/class_obj/002.phpt (renamed from tests/php/phpt/base/002.phpt)0
-rw-r--r--tests/php/phpt/class_obj/003-comparable.phpt46
-rw-r--r--tests/php/phpt/class_obj/004-static-funct.phpt26
-rw-r--r--tests/php/phpt/class_obj/004-static-prop.phpt19
-rw-r--r--tests/php/phpt/class_obj/readme (renamed from tests/php/phpt/base/readme)0
-rw-r--r--tests/php/phpt/valueiterator/007-Iterate-internal-array.phpt15
-rw-r--r--tests/php/phpt/variables/003-value-types.phpt (renamed from tests/php/phpt/variables/003-value-types.phpt-)0
-rw-r--r--tests/php/phpt/variables/005-cast-objects-to-scalars.phpt22
-rw-r--r--tests/php/phpt/variables/011-value-casting-operators.phpt (renamed from tests/php/phpt/variables/005-value-casting-operators.phpt-)26
-rw-r--r--tests/php/phpt/variables/012-value-casting-operators-double.phpt80
-rw-r--r--tests/php/phpt/variables/013-calling-php-functions.phpt113
-rw-r--r--tests/php/phpt/variables/014-calling-php-functions.phpt113
-rw-r--r--tests/php/phpt/variables/015-calling-php-functions.phpt109
-rw-r--r--tests/php/phpt/variables/016-calling-php-functions.phpt113
-rw-r--r--tests/php/phpt/variables/017-calling-php-functions.phpt115
-rw-r--r--tests/php/phpt/variables/018-calling-php-functions.phpt32
-rw-r--r--tests/php/phpt/variables/readme4
45 files changed, 1920 insertions, 334 deletions
diff --git a/tests/cpp/h/Classes_and_objects.h b/tests/cpp/h/Classes_and_objects.h
new file mode 100644
index 0000000..8404c69
--- /dev/null
+++ b/tests/cpp/h/Classes_and_objects.h
@@ -0,0 +1,14 @@
+/**
+ *
+ *
+ * Classes_and_objects.h
+ *
+ */
+
+#include "../include/class_obj/001-002.h"
+#include "../include/class_obj/003-comparable.h"
+#include "../include/class_obj/004-static-funct.h"
+//#include "../include/class_obj/.h"
+//#include "../include/class_obj/.h"
+//#include "../include/class_obj/.h"
+
diff --git a/tests/cpp/h/ValueIterator.h b/tests/cpp/h/ValueIterator.h
new file mode 100644
index 0000000..b430008
--- /dev/null
+++ b/tests/cpp/h/ValueIterator.h
@@ -0,0 +1,8 @@
+/**
+ *
+ * TestValueIterator
+ *
+ */
+
+#include "../include/valueiterator/001-006.h"
+#include "../include/valueiterator/007.h"
diff --git a/tests/cpp/h/variables.h b/tests/cpp/h/variables.h
new file mode 100644
index 0000000..3ff77e9
--- /dev/null
+++ b/tests/cpp/h/variables.h
@@ -0,0 +1,28 @@
+/**
+ *
+ * Test variables
+ *
+ */
+
+#include "../include/doubl2str.h"
+#include "../include/bool2str.h"
+
+#include "../include/variables/001-process_globals.h"
+#include "../include/variables/002-get_complex_array.h"
+#include "../include/variables/003-value-types.h"
+#include "../include/variables/004-store-scalar-variables.h"
+#include "../include/variables/005-cast-objects-to-scalars.h"
+#include "../include/variables/006-casting-obj2str.h"
+#include "../include/variables/007-overloaded-operators.h"
+#include "../include/variables/008-value-arrays.h"
+#include "../include/variables/009-010-value-object.h"
+#include "../include/variables/011-012-value-casting-operators.h"
+#include "../include/variables/013-018-calling-php-functions.h"
+//#include "../include/variables/.h"
+//#include "../include/variables/.h"
+
+
+
+
+
+
diff --git a/tests/cpp/include/bool2str.h b/tests/cpp/include/bool2str.h
new file mode 100644
index 0000000..26aac80
--- /dev/null
+++ b/tests/cpp/include/bool2str.h
@@ -0,0 +1,12 @@
+/**
+ *
+ * bool -> string
+ *
+ */
+
+
+
+std::string bool2str(bool b)
+{
+ return b ? "Yes" : "No";
+}
diff --git a/tests/cpp/include/MyCustomClass.h b/tests/cpp/include/class_obj/001-002.h
index 02ff44b..2a3b4df 100644
--- a/tests/cpp/include/MyCustomClass.h
+++ b/tests/cpp/include/class_obj/001-002.h
@@ -1,21 +1,19 @@
/**
- *
*
- *
+ * Test Classes and objects
+ * 001.phpt
+ * 002.phpt
*
*/
+
+
/**
* Set up namespace
*/
namespace TestBaseClass {
-
-/**
- * Namespace to use
- */
- using namespace std;
class MyCustomClass : public Php::Base, public Php::Countable
{
@@ -53,7 +51,7 @@ namespace TestBaseClass {
// check number of parameters
//if (params.size() != 1) throw Php::Exception("Invalid number of parameters supplied");
- std::cout << "myMethod is called for object " << _x << std::endl;
+ Php::out << "myMethod is called for object " << _x << std::endl;
return 5;
@@ -61,10 +59,8 @@ namespace TestBaseClass {
};
-
/**
* End of namespace
*/
}
- \ No newline at end of file
diff --git a/tests/cpp/include/class_obj/003-comparable.h b/tests/cpp/include/class_obj/003-comparable.h
new file mode 100644
index 0000000..8a384dc
--- /dev/null
+++ b/tests/cpp/include/class_obj/003-comparable.h
@@ -0,0 +1,74 @@
+/**
+ *
+ * Test Classes and objects
+ * 003-comparable.phpt
+ *
+ */
+
+
+
+
+/**
+ * Set up namespace
+ */
+namespace TestBaseClass {
+
+
+ /**
+ * Test custom comparison operator
+ */
+ class Comparable : public Php::Base
+ {
+ private:
+ /**
+ * Internal value of the class
+ * @var int
+ */
+ static int count;
+ int _nom;
+ int _value;
+
+ public:
+ /**
+ * C++ constructor
+ */
+ Comparable()
+ {
+ // start with random value
+ //_value = rand();
+ _nom = ++count;
+ _value = _nom%2+1;
+ }
+
+ /**
+ * C++ destructor
+ */
+ virtual ~Comparable() {}
+
+ /**
+ * Cast the object to a string
+ * @return std::string
+ */
+ std::string __toString()
+ {
+ return "Obj#" + std::to_string(_nom) + "(" + std::to_string(_value) + ")";
+ }
+
+ /**
+ * Compare with a different object
+ * @param that
+ * @return int
+ */
+ int __compare(const Comparable &that) const
+ {
+ return _value - that._value;
+ }
+ };
+ int Comparable::count = 0;
+
+
+/**
+ * End of namespace
+ */
+}
+
diff --git a/tests/cpp/include/class_obj/004-static-funct.h b/tests/cpp/include/class_obj/004-static-funct.h
new file mode 100644
index 0000000..d6816ab
--- /dev/null
+++ b/tests/cpp/include/class_obj/004-static-funct.h
@@ -0,0 +1,90 @@
+/**
+ *
+ * Test Classes and objects
+ * 004-static-funct.phpt
+ * test static functions
+ *
+ */
+
+
+
+
+/**
+ * Set up namespace
+ */
+namespace TestBaseClass {
+
+
+ /**
+ * Regular function
+ *
+ * Because a regular function does not have a 'this' pointer,
+ * it has the same signature as static methods
+ *
+ * @param params Parameters passed to the function
+ */
+ void testStaticRegFunc(Php::Parameters &params)
+ {
+ Php::out << "testStatic regular function"<< std::endl;
+ }
+
+ /**
+ * A very simple class that will not be exported to PHP
+ */
+ class testStaticPrivClass
+ {
+ public:
+ /**
+ * C++ constructor and destructor
+ */
+ testStaticPrivClass() {}
+ virtual ~testStaticPrivClass() {}
+
+ /**
+ * Static method
+ *
+ * A static method also has no 'this' pointer and has
+ * therefore a signature identical to regular functions
+ *
+ * @param params Parameters passed to the method
+ */
+ static void staticMethod(Php::Parameters &params)
+ {
+ Php::out << "testStaticPrivClass::staticMethod()"<< std::endl;
+ }
+ };
+
+ /**
+ * A very simple class that will be exported to PHP
+ */
+ class testStaticPubClass : public Php::Base
+ {
+ public:
+ /**
+ * C++ constructor and destructor
+ */
+ testStaticPubClass() {}
+ virtual ~testStaticPubClass() {}
+
+ /**
+ * Another static method
+ *
+ * This static has exactly the same signature as the
+ * regular function and static method that were mentioned
+ * before
+ *
+ * @param params Parameters passed to the method
+ */
+ static void staticMethod(Php::Parameters &params)
+ {
+ Php::out << "testStaticPubClass::staticMethod()"<< std::endl;
+ }
+ };
+
+
+
+/**
+ * End of namespace
+ */
+}
+
diff --git a/tests/cpp/include/class_obj/tpl.h b/tests/cpp/include/class_obj/tpl.h
new file mode 100644
index 0000000..7dfdcfc
--- /dev/null
+++ b/tests/cpp/include/class_obj/tpl.h
@@ -0,0 +1,25 @@
+/**
+ *
+ * Test Classes and objects
+ * phptname.phpt
+ *
+ */
+
+
+
+
+/**
+ * Set up namespace
+ */
+namespace TestBaseClass {
+
+
+
+
+
+
+/**
+ * End of namespace
+ */
+}
+
diff --git a/tests/cpp/include/doubl2str.h b/tests/cpp/include/doubl2str.h
new file mode 100644
index 0000000..1a5e3fc
--- /dev/null
+++ b/tests/cpp/include/doubl2str.h
@@ -0,0 +1,102 @@
+/**
+ *
+ * double -> string
+ *
+ */
+
+
+
+char num2char(unsigned int num)
+{
+ switch(num)
+ {
+ case 0:
+ return '0';
+ case 1:
+ return '1';
+ case 2:
+ return '2';
+ case 3:
+ return '3';
+ case 4:
+ return '4';
+ case 5:
+ return '5';
+ case 6:
+ return '6';
+ case 7:
+ return '7';
+ case 8:
+ return '8';
+ case 9:
+ return '9';
+ }
+
+ //return '\0';
+ return '-';
+}
+
+std::string double2str(long double D)
+{
+ int sign = (D > 0) ? 1 : (D*=-1.0, -1);
+ unsigned long long int Ceil = D;
+
+ // if D is ceil
+ if(Ceil == D)
+ {
+ return std::to_string( (long long)(D*sign) );
+ }
+
+ // size of result buffer
+ const int bs = 32;
+
+ // size of temporary buffer
+ const int pw = 16;
+ // Temporary buffer
+ char buf[pw];
+ // Result buffer
+ char rez[bs];
+
+ int i, size = 0;
+ // set sign
+ if(sign < 0) rez[size++] = '-';
+
+ // set ceil
+ std::string sceil = std::to_string(Ceil);
+ const char * bceil = sceil.c_str();
+ int sceillen = sceil.size();
+ for(i = 0; i < sceillen; i++)
+ {
+ rez[size++] = bceil[i];
+ }
+
+ // set point
+ rez[size++] = '.';
+
+ unsigned long long int I = D * 10000000000000000; // D * 10**pw
+ // .14159265359 -> 14159265359000000
+ I -= Ceil * 10000000000000000;
+
+ // Remove the tail of zeros
+ // 14159265359000000 -> 14159265359
+ while(0 == I % 10) I /= 10;
+
+ int ind = 0;
+ while(I > 0)
+ {
+ buf[ind++] = num2char(I%10);
+ I = (I - I%10) / 10;
+ }
+
+ // set fraction part
+ for(i = 0; i < ind; i++)
+ {
+ rez[size] = buf[ind-i-1];
+ size++;
+ }
+
+ return std::string(rez, size);
+ //rez[size] = '\0';
+}
+
+
diff --git a/tests/cpp/include/ValueIterator.h b/tests/cpp/include/valueiterator/001-006.h
index a9329c9..0dc6778 100644
--- a/tests/cpp/include/ValueIterator.h
+++ b/tests/cpp/include/valueiterator/001-006.h
@@ -1,6 +1,7 @@
/**
*
* TestValueIterator
+ * test valueiterator/001.phpt-valueiterator/006.phpt
*
*/
@@ -19,7 +20,6 @@ namespace TestValueIterator {
}
return;
}
-
/**
* End of namespace
*/
diff --git a/tests/cpp/include/valueiterator/007.h b/tests/cpp/include/valueiterator/007.h
new file mode 100644
index 0000000..3cfcb59
--- /dev/null
+++ b/tests/cpp/include/valueiterator/007.h
@@ -0,0 +1,44 @@
+/**
+ *
+ * TestValueIterator
+ * test valueiterator/007.phpt
+ *
+ */
+
+/**
+ * Set up namespace
+ */
+namespace TestValueIterator {
+
+ void loopArray(void)
+ {
+
+ Php::Value value;
+ /*
+ If we fill the array in this form, we get the following:
+ *** Error in `/usr/bin/php': double free or corruption (fasttop): 0x0000000001956d60 ***
+ value[0] = "val0";
+ value[1] = "val1";
+ value["third"] = "val3";
+ value["fourth"] = "val3";
+ */
+ value.set(0 , "val0");
+ value.set(1 , "val1");
+ value.set("third" , "val3");
+ value.set("fourth", "val3");
+
+ std::cout << "Array/Object contains " << value.size() << " items" << std::endl;
+ // assum the value variable holds an array or object, it then
+ // is possible to iterator over the values or properties
+ for (auto &iter : value)
+ {
+ // output key and value
+ Php::out << "["<< iter.first << "]="<< iter.second << std::endl;
+ }
+ }
+
+/**
+ * End of namespace
+ */
+}
+
diff --git a/tests/cpp/include/variables.h b/tests/cpp/include/variables.h
deleted file mode 100644
index f242653..0000000
--- a/tests/cpp/include/variables.h
+++ /dev/null
@@ -1,293 +0,0 @@
-/**
- *
- * Test variables
- *
- */
-
-/**
- * Set up namespace
- */
-namespace TestVariables {
-
-
- /**
- * process_globals()
- *
- * This function reads and modifies global variables
- */
- Php::Value process_globals()
- {
- // all global variables can be accessed via the Php::GLOBALS variable,
- // which is more or less the same as the PHP $_GLOBALS variable
-
- // set a global variable
- Php::GLOBALS["a"] = 1;
-
- // increment a global variable
- Php::GLOBALS["b"] += 1;
-
- // set a global variable to be an array
- Php::GLOBALS["c"] = Php::Array();
-
- // add a member to an array
- Php::GLOBALS["c"]["member"] = 123;
-
- // and increment it
- Php::GLOBALS["c"]["member"] += 77;
-
- // change value e
- Php::GLOBALS["e"] = Php::GLOBALS["e"][0]("hello");
-
- // if a global variable holds a function, we can call it
- return Php::GLOBALS["d"](1,2,3);
- }
-
- /**
- * This function returns complex array
- */
- Php::Value get_complex_array()
- {
- Php::Value r;
- r["a"] = 123;
- r["b"] = 456;
- r["c"][0] = "nested value";
- r["c"][1] = "example";
- r["c"][2] = 7;
- return r;
- }
-
-
- std::string bool2str(bool b)
- {
- return b ? "Yes" : "No";
- }
-
- /*
- * Check type of value
- * @param array
- */
- void value_types(Php::Parameters &params) {
- if (params.size() == 0) {
- return;
- }
-
- Php::Value arr = params[0];
-
- Php::out << "Null: " << bool2str( arr.get("Null").type() == Php::Type::Null ) << std::endl;
- Php::out << "Numeric: " << bool2str( arr.get("Numeric").type() == Php::Type::Numeric ) << std::endl;
- Php::out << "Float: " << bool2str( arr.get("Float").type() == Php::Type::Float ) << std::endl;
- Php::out << "Bool: " << bool2str( arr.get("Bool").type() == Php::Type::Bool ) << std::endl;
- Php::out << "Array: " << bool2str( arr.get("Array").type() == Php::Type::Array ) << std::endl;
- Php::out << "Object: " << bool2str( arr.get("Object").type() == Php::Type::Object ) << std::endl;
- Php::out << "String: " << bool2str( arr.get("String").type() == Php::Type::String ) << std::endl;
- Php::out << "Resource: " << bool2str( arr.get("Resource").type() == Php::Type::Resource ) << std::endl;
- Php::out << "Constant: " << bool2str( arr.get("Constant").type() == Php::Type::Constant ) << std::endl;
- Php::out << "ConstantArray: " << bool2str( arr.get("ConstantArray").type() == Php::Type::ConstantArray ) << std::endl;
- Php::out << "Callable1: " << bool2str( arr.get("Callable1").type() == Php::Type::Callable ) << std::endl;
- Php::out << "Callable2: " << bool2str( arr.get("Callable2").type() == Php::Type::Callable ) << std::endl;
- Php::out << "Callable3: " << bool2str( arr.get("Callable3").type() == Php::Type::Callable ) << std::endl;
- Php::out << "Callable4: " << bool2str( arr.get("Callable4").type() == Php::Type::Callable ) << std::endl;
- }
-
- /*
- * Test variables defined 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;
- r[10] = Php::Value();
- r[11] = 123.45;
- r[12] = false;
-
- return r;
- }
-
- /*
- * Test Php::Value casting operators
- */
- void value_casting(Php::Parameters &params)
- {
- Php::Value value = params[0];
-
- long value1 = value;
- std::string value2 = value;
- //long double value3 = value; // <------------ error: conversion from ‘Php::Value’ to ‘long double’ is ambiguous
- double value3 = value;
- bool value4 = value;
-
- Php::out << " long:" << value1 << "\n string:" << value2 << "\n double:" << value3 << "\n bool:" << bool2str(value4) << std::endl;
- }
-
- /*
- * Test Php::Value casting operators
- */
- void value_cast2str(Php::Parameters &params)
- {
- std::string value = params[0];
- Php::out << value << std::endl;
- }
-
- /*
- * Test Php::Value overloaded operators
- */
- void overloaded_op(Php::Parameters &params)
- {
- Php::Value value = params[0];
- if (value == "some string")
- {
- Php::out << "value == 'some string'" << std::endl;
- }
-
- if (value == 12)
- {
- Php::out << "value == 12" << std::endl;
- }
- else if (value > 100)
- {
- Php::out << "value > 100" << std::endl;
- }
-
- value += 10;
- Php::out << value << std::endl;
-
- int r1 = value - 8;
- Php::out << r1 << std::endl;
-
- double r2 = value*123.45;
- Php::out << r2 << std::endl;
-
- double r3 = value/123.45;
- Php::out << r3 << std::endl;
-
-
-
- }
-
- /*
- * Test Php::Value arrays
- */
- Php::Value value_arrays(void)
- {
- // create a regular array
- Php::Value array;
- array[0] = "apple";
- array[1] = "banana";
- array[2] = "tomato";
-
- // an initializer list can be used to create a filled array
- Php::Value filled({ "a", "b", "c", "d"});
-
- // create an associative array
- Php::Value assoc;
- assoc["apple"] = "green";
- assoc["banana"] = "yellow";
- assoc["tomato"] = "green";
-
- // the variables in an array do not all have to be of the same type
- Php::Value assoc2;
- assoc2["x"] = "info@example.com";
- assoc2["y"] = nullptr;
- assoc2["z"] = 123;
-
- // nested arrays are possible too
- Php::Value assoc3;
- assoc3["x"] = "info@example.com";
- assoc3["y"] = nullptr;
- assoc3["z"][0] = "a";
- assoc3["z"][1] = "b";
- assoc3["z"][2] = "c";
-
- Php::Value r;
- r["array"] = array;
- r["filled"] = filled;
- r["assoc"] = assoc;
- r["assoc2"] = assoc2;
- r["assoc3"] = assoc3;
- return r;
- }
-
- /*
- * Test Php::Value object
- */
- Php::Value value_object1(void)
- {
-
- // create empty object of type stdClass
- Php::Object object;
-
- // object properties can be accessed with square brackets
- object["property1"] = "value1";
- object["property2"] = "value2";
-
- // Php::Value is the base class, so you can assign Php::Object objects
- //Php::Value value = object;
-
- return object;
- }
-
- /*
- * Test Php::Value object
- */
- Php::Value value_object2(void)
- {
-
- // create empty object of type stdClass
- Php::Object object;
-
- // to create an object of a different type, pass in the class name
- // to the constructor with optional constructor parameters
- //object = Php::Object("DateTime", "2014-03-27 00:37:15.638276");
-
- auto timeZone = Php::Object("DateTimeZone", "Europe/Amsterdam");
- object = Php::Object("DateTime", "2014-03-27 00:37:15", timeZone);
-
-
- // methods can be called with the call() method
- Php::out << object.call("format", "Y-m-d H:i:s") << std::endl;
-
- // all these methods can be called on a Php::Value object too
- Php::Value value = Php::Object("DateTime", "2016-03-31 15:48:00", timeZone);
- Php::out << value.call("format", "Y-m-d H:i:s") << std::endl;
- Php::out << value.call("getOffset") << std::endl;
-
- return object;
- }
-
- /*
- * Test Php::Value resize
- */
- void ghfghfhf2(Php::Parameters &params)
- {
-
-
- }
-
-
-
-
-
-
-
-/**
- * End of namespace
- */
-}
-
diff --git a/tests/cpp/include/variables/001-process_globals.h b/tests/cpp/include/variables/001-process_globals.h
new file mode 100644
index 0000000..ae930d2
--- /dev/null
+++ b/tests/cpp/include/variables/001-process_globals.h
@@ -0,0 +1,57 @@
+/**
+ *
+ * Test variables
+ * 001-process_globals.phpt
+ * Global variables in PHP-CPP
+ *
+ */
+
+
+
+
+/**
+ * Set up namespace
+ */
+namespace TestVariables {
+
+
+
+ /**
+ * process_globals()
+ *
+ * This function reads and modifies global variables
+ */
+ Php::Value process_globals()
+ {
+ // all global variables can be accessed via the Php::GLOBALS variable,
+ // which is more or less the same as the PHP $_GLOBALS variable
+
+ // set a global variable
+ Php::GLOBALS["a"] = 1;
+
+ // increment a global variable
+ Php::GLOBALS["b"] += 1;
+
+ // set a global variable to be an array
+ Php::GLOBALS["c"] = Php::Array();
+
+ // add a member to an array
+ Php::GLOBALS["c"]["member"] = 123;
+
+ // and increment it
+ Php::GLOBALS["c"]["member"] += 77;
+
+ // change value e
+ Php::GLOBALS["e"] = Php::GLOBALS["e"][0]("hello");
+
+ // if a global variable holds a function, we can call it
+ return Php::GLOBALS["d"](1,2,3);
+ }
+
+
+
+/**
+ * End of namespace
+ */
+}
+
diff --git a/tests/cpp/include/variables/002-get_complex_array.h b/tests/cpp/include/variables/002-get_complex_array.h
new file mode 100644
index 0000000..b12e5ee
--- /dev/null
+++ b/tests/cpp/include/variables/002-get_complex_array.h
@@ -0,0 +1,35 @@
+/**
+ *
+ * Test variables
+ * 002-get_complex_array.phpt
+ *
+ */
+
+
+
+
+/**
+ * Set up namespace
+ */
+namespace TestVariables {
+
+ /**
+ * This function returns complex array
+ */
+ Php::Value get_complex_array()
+ {
+ Php::Value r;
+ r["a"] = 123;
+ r["b"] = 456;
+ r["c"][0] = "nested value";
+ r["c"][1] = "example";
+ r["c"][2] = 7;
+ return r;
+ }
+
+
+/**
+ * End of namespace
+ */
+}
+
diff --git a/tests/cpp/include/variables/003-value-types.h b/tests/cpp/include/variables/003-value-types.h
new file mode 100644
index 0000000..d24549b
--- /dev/null
+++ b/tests/cpp/include/variables/003-value-types.h
@@ -0,0 +1,37 @@
+/**
+ *
+ * Test variables
+ * 003-value-types.phpt
+ *
+ */
+
+namespace TestVariables {
+
+ /*
+ * Check type of value
+ * @param array
+ */
+ void value_types(Php::Parameters &params)
+ {
+ if (params.size() == 0) return;
+ Php::Value arr = params[0];
+
+ Php::out << "Null: " << bool2str( arr.get("Null").isNull() ) << std::endl;
+ Php::out << "Numeric: " << bool2str( arr.get("Numeric").isNumeric()) << std::endl;
+ Php::out << "Float: " << bool2str( arr.get("Float").isFloat() ) << std::endl;
+ Php::out << "Bool: " << bool2str( arr.get("Bool").isBool() ) << std::endl;
+ Php::out << "Array: " << bool2str( arr.get("Array").isArray() ) << std::endl;
+ Php::out << "Object: " << bool2str( arr.get("Object").isObject() ) << std::endl;
+ Php::out << "String: " << bool2str( arr.get("String").isString() ) << std::endl;
+ Php::out << "Resource: " << bool2str( arr.get("Resource").type() == Php::Type::Resource ) << std::endl;
+ Php::out << "Constant: " << bool2str( arr.get("Constant").type() == Php::Type::Constant ) << std::endl;
+ Php::out << "ConstantArray: " << bool2str( arr.get("ConstantArray").type() == Php::Type::ConstantArray ) << std::endl;
+ Php::out << "Callable1: " << bool2str( arr.get("Callable1").isCallable() ) << std::endl;
+ Php::out << "Callable2: " << bool2str( arr.get("Callable2").isCallable() ) << std::endl;
+ Php::out << "Callable3: " << bool2str( arr.get("Callable3").isCallable() ) << std::endl;
+ Php::out << "Callable4: " << bool2str( arr.get("Callable4").isCallable() ) << std::endl;
+
+ }
+
+}
+
diff --git a/tests/cpp/include/variables/004-store-scalar-variables.h b/tests/cpp/include/variables/004-store-scalar-variables.h
new file mode 100644
index 0000000..9ce82e5
--- /dev/null
+++ b/tests/cpp/include/variables/004-store-scalar-variables.h
@@ -0,0 +1,48 @@
+/**
+ *
+ * Test variables
+ * 004-store-scalar-variables.phpt
+ *
+ */
+
+/**
+ * Set up namespace
+ */
+namespace TestVariables {
+
+ /*
+ * Test variables defined 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;
+ r[10] = Php::Value();
+ r[11] = 123.45;
+ r[12] = false;
+
+ return r;
+ }
+
+/**
+ * End of namespace
+ */
+}
+
diff --git a/tests/cpp/include/variables/005-cast-objects-to-scalars.h b/tests/cpp/include/variables/005-cast-objects-to-scalars.h
new file mode 100644
index 0000000..f053c4d
--- /dev/null
+++ b/tests/cpp/include/variables/005-cast-objects-to-scalars.h
@@ -0,0 +1,75 @@
+/**
+ *
+ * Test variables
+ * 005-cast-objects-to-scalars.phpt
+ *
+ */
+
+
+
+/**
+ * Set up namespace
+ */
+namespace TestVariables {
+
+ /**
+ * A sample class, with methods to cast objects to scalars
+ */
+ class Obj2Scalar : public Php::Base
+ {
+ public:
+ /**
+ * C++ constructor and C++ destructpr
+ */
+ Obj2Scalar() {}
+ virtual ~Obj2Scalar() {}
+
+ /**
+ * Cast to a string
+ *
+ * Note that now we use const char* as return value, and not Php::Value.
+ * The __toString function is detected at compile time, and it does
+ * not have a fixed signature. You can return any value that can be picked
+ * up by a Php::Value object.
+ *
+ * @return const char *
+ */
+ const char *__toString()
+ {
+ return "Mount Meru, also called Sumeru (Sanskrit)";
+ }
+
+ /**
+ * Cast to a integer
+ * @return long
+ */
+ long __toInteger()
+ {
+ return 27032014;
+ }
+
+ /**
+ * Cast to a floating point number
+ * @return double
+ */
+ double __toFloat()
+ {
+ return 3.14159265359;
+ }
+
+ /**
+ * Cast to a boolean
+ * @return bool
+ */
+ bool __toBool()
+ {
+ return true;
+ }
+ };
+
+
+/**
+ * End of namespace
+ */
+}
+
diff --git a/tests/cpp/include/variables/006-casting-obj2str.h b/tests/cpp/include/variables/006-casting-obj2str.h
new file mode 100644
index 0000000..879683d
--- /dev/null
+++ b/tests/cpp/include/variables/006-casting-obj2str.h
@@ -0,0 +1,30 @@
+/**
+ *
+ * Test variables
+ * 006-casting-obj2str.phpt
+ *
+ */
+
+
+
+/**
+ * Set up namespace
+ */
+namespace TestVariables {
+
+
+ /*
+ * Test Php::Value casting operators
+ */
+ void value_cast2str(Php::Parameters &params)
+ {
+ std::string value = params[0];
+ Php::out << value << std::endl;
+ }
+
+
+/**
+ * End of namespace
+ */
+}
+
diff --git a/tests/cpp/include/variables/007-overloaded-operators.h b/tests/cpp/include/variables/007-overloaded-operators.h
new file mode 100644
index 0000000..88b3117
--- /dev/null
+++ b/tests/cpp/include/variables/007-overloaded-operators.h
@@ -0,0 +1,46 @@
+/**
+ *
+ * Test variables
+ * 007-overloaded-operators.phpt
+ *
+ */
+
+
+
+namespace TestVariables {
+
+ /*
+ * Test Php::Value overloaded operators
+ */
+ void overloaded_op(Php::Parameters &params)
+ {
+ Php::Value value = params[0];
+ if (value == "some string")
+ {
+ Php::out << "value == 'some string'" << std::endl;
+ }
+
+ if (value == 12)
+ {
+ Php::out << "value == 12" << std::endl;
+ }
+ else if (value > 100)
+ {
+ Php::out << "value > 100" << std::endl;
+ }
+
+ value += 10;
+ Php::out << value << std::endl;
+
+ int r1 = value - 8;
+ Php::out << r1 << std::endl;
+
+ double r2 = value*123.45;
+ Php::out << r2 << std::endl;
+
+ double r3 = value/123.45;
+ Php::out << r3 << std::endl;
+ }
+
+}
+
diff --git a/tests/cpp/include/variables/008-value-arrays.h b/tests/cpp/include/variables/008-value-arrays.h
new file mode 100644
index 0000000..937f79a
--- /dev/null
+++ b/tests/cpp/include/variables/008-value-arrays.h
@@ -0,0 +1,57 @@
+/**
+ *
+ * Test variables
+ * 008-value-arrays.phpt
+ *
+ */
+
+
+namespace TestVariables {
+
+
+ /*
+ * Test Php::Value arrays
+ */
+ Php::Value value_arrays(void)
+ {
+ // create a regular array
+ Php::Value array;
+ array[0] = "apple";
+ array[1] = "banana";
+ array[2] = "tomato";
+
+ // an initializer list can be used to create a filled array
+ Php::Value filled({ "a", "b", "c", "d"});
+
+ // create an associative array
+ Php::Value assoc;
+ assoc["apple"] = "green";
+ assoc["banana"] = "yellow";
+ assoc["tomato"] = "green";
+
+ // the variables in an array do not all have to be of the same type
+ Php::Value assoc2;
+ assoc2["x"] = "info@example.com";
+ assoc2["y"] = nullptr;
+ assoc2["z"] = 123;
+
+ // nested arrays are possible too
+ Php::Value assoc3;
+ assoc3["x"] = "info@example.com";
+ assoc3["y"] = nullptr;
+ assoc3["z"][0] = "a";
+ assoc3["z"][1] = "b";
+ assoc3["z"][2] = "c";
+
+ Php::Value r;
+ r["array"] = array;
+ r["filled"] = filled;
+ r["assoc"] = assoc;
+ r["assoc2"] = assoc2;
+ r["assoc3"] = assoc3;
+ return r;
+ }
+
+
+}
+
diff --git a/tests/cpp/include/variables/009-010-value-object.h b/tests/cpp/include/variables/009-010-value-object.h
new file mode 100644
index 0000000..e3eba85
--- /dev/null
+++ b/tests/cpp/include/variables/009-010-value-object.h
@@ -0,0 +1,68 @@
+/**
+ *
+ * Test variables
+ * 009-value-object.phpt
+ * 010-value-object2.phpt
+ *
+ */
+
+
+/**
+ * Set up namespace
+ */
+namespace TestVariables {
+
+
+ /*
+ * Test Php::Value object
+ */
+ Php::Value value_object1(void)
+ {
+
+ // create empty object of type stdClass
+ Php::Object object;
+
+ // object properties can be accessed with square brackets
+ object["property1"] = "value1";
+ object["property2"] = "value2";
+
+ // Php::Value is the base class, so you can assign Php::Object objects
+ //Php::Value value = object;
+
+ return object;
+ }
+
+ /*
+ * Test Php::Value object
+ */
+ Php::Value value_object2(void)
+ {
+
+ // create empty object of type stdClass
+ Php::Object object;
+
+ // to create an object of a different type, pass in the class name
+ // to the constructor with optional constructor parameters
+ //object = Php::Object("DateTime", "2014-03-27 00:37:15.638276");
+
+ auto timeZone = Php::Object("DateTimeZone", "Europe/Amsterdam");
+ object = Php::Object("DateTime", "2014-03-27 00:37:15", timeZone);
+
+
+ // methods can be called with the call() method
+ Php::out << object.call("format", "Y-m-d H:i:s") << std::endl;
+
+ // all these methods can be called on a Php::Value object too
+ Php::Value value = Php::Object("DateTime", "2016-03-31 15:48:00", timeZone);
+ Php::out << value.call("format", "Y-m-d H:i:s") << std::endl;
+ Php::out << value.call("getOffset") << std::endl;
+
+ return object;
+ }
+
+
+/**
+ * End of namespace
+ */
+}
+
diff --git a/tests/cpp/include/variables/011-012-value-casting-operators.h b/tests/cpp/include/variables/011-012-value-casting-operators.h
new file mode 100644
index 0000000..182054b
--- /dev/null
+++ b/tests/cpp/include/variables/011-012-value-casting-operators.h
@@ -0,0 +1,52 @@
+/**
+ *
+ * Test variables
+ * 011-value-casting-operators.phpt
+ * 012-value-casting-operators-double.phpt
+ *
+ */
+
+
+
+/**
+ * Set up namespace
+ */
+namespace TestVariables {
+
+ /*
+ * Test Php::Value casting operators
+ */
+ void value_casting(Php::Parameters &params)
+ {
+ Php::Value value = params[0];
+
+ long value1 = value;
+ std::string value2 = value;
+ bool value4 = value;
+
+ Php::out << " long:" << value1 << "\n string:" << value2 << "\n bool:" << bool2str(value4) << std::endl;
+ }
+
+
+ /*
+ * Test Php::Value casting operators
+ */
+ void value_cast2double(Php::Parameters &params)
+ {
+ Php::Value value = params[0];
+ double value3 = value;
+
+ /*
+ * The remark (from valmat).
+ * Somehow std::to_string truncates the tail of numbers of type `double` when converting it to a string.
+ * So I wrote my own function `double2str()`, which does not have this drawback.
+ */
+ Php::out << double2str(value3) << std::endl;
+ }
+
+
+/**
+ * End of namespace
+ */
+}
+
diff --git a/tests/cpp/include/variables/013-018-calling-php-functions.h b/tests/cpp/include/variables/013-018-calling-php-functions.h
new file mode 100644
index 0000000..9a77408
--- /dev/null
+++ b/tests/cpp/include/variables/013-018-calling-php-functions.h
@@ -0,0 +1,117 @@
+/**
+ *
+ * Test call function
+ * 013-calling-php-functions.phpt
+ * ...
+ * 018-calling-php-functions.phpt
+ *
+ */
+
+
+/**
+ * Set up namespace
+ */
+namespace TestVariables {
+
+
+ /*
+ * Test call function from user space
+ */
+ void fnFromUserSpace(void)
+ {
+
+
+ Php::out << "fnFromUserSpace" << std::endl;
+
+ Php::Value param5;
+ param5.set(0, "param5");
+ param5.set(1, 3.14159265359);
+ param5.set(2, 28032014);
+ param5.set("key", "value");
+
+ auto timeZone = Php::Object("DateTimeZone", "Asia/Yekaterinburg");
+ Php::Value param6 = Php::Object("DateTime", "2014-03-28 19:42:15", timeZone);
+
+ // call a function from user space
+ Php::call("some_function", "param1");
+ Php::call("some_function", "param1", "param2");
+ Php::call("some_function", "param1", "param2", "param3");
+ Php::call("some_function", "param1", "param2", "param3", "param4");
+ Php::call("some_function", "param1", "param2", "param3", "param4", param5);
+ Php::call("some_function", "param1", "param2", "param3", "param4", param5, param6);
+ Php::call("some_function", "param1", "param2", "param3", "param4", "param5", "param6", "param7");
+ Php::call("some_function", "param1", "param2", "param3", "param4", "param5", "param6", "param7", "param8");
+ Php::call("some_function", "param1", "param2", "param3", "param4", "param5", "param6", "param7", "param8", "param9");
+ Php::call("some_function", "param1", "param2", "param3", "param4", "param5", "param6", "param7", "param8", "param9", "param10");
+
+ }
+
+ /*
+ * Test call callback
+ */
+ void fnCallback(Php::Parameters &params)
+ {
+ Php::out << "call callback" << std::endl;
+
+ Php::Value callback = params[0];
+
+
+ Php::Value param5;
+ param5.set(0, "param5");
+ param5.set(1, 3.14159265359);
+ param5.set(2, 28032014);
+ param5.set("key", "value");
+
+ auto timeZone = Php::Object("DateTimeZone", "Asia/Yekaterinburg");
+ Php::Value param6 = Php::Object("DateTime", "2014-03-28 19:42:15", timeZone);
+
+ // call a function from user space
+ callback("param1");
+ callback("param1", "param2");
+ callback("param1", "param2", "param3");
+ callback("param1", "param2", "param3", "param4");
+ callback("param1", "param2", "param3", "param4", param5);
+ callback("param1", "param2", "param3", "param4", param5, param6);
+ callback("param1", "param2", "param3", "param4", "param5", "param6", "param7");
+ callback("param1", "param2", "param3", "param4", "param5", "param6", "param7", "param8");
+ callback("param1", "param2", "param3", "param4", "param5", "param6", "param7", "param8", "param9");
+ callback("param1", "param2", "param3", "param4", "param5", "param6", "param7", "param8", "param9", "param10");
+
+ }
+
+ /*
+ * Test
+ */
+ void fnFromUserSpace2(void)
+ {
+
+ // create an object (this will also call __construct())
+ Php::Object time("DateTime", "2014-03-28 21:22:15", Php::Object("DateTimeZone", "Asia/Irkutsk"));
+
+ // call a method on the datetime object
+ Php::out << time.call("format", "Y-m-d H:i:s") << std::endl;
+
+ // in PHP it is possible to create an array with two parameters, the first
+ // parameter being an object, and the second parameter should be the name
+ // of the method, we can do that in PHP-CPP too
+ Php::Array time_format({time, "format"});
+
+ // call the method that is stored in the array
+ Php::out << time_format("Y-m-d H:i:s") << std::endl;
+
+ // call method of class from user space
+ Php::Object usrspcl("usrspClass", "Mount Meru");
+ Php::Array usrspcl_meth({usrspcl, "someMethod"});
+ // call the method that is stored in the array
+ Php::out << usrspcl_meth("is in the Arctics") << std::endl;
+
+ // call callable object of class from user space
+ Php::Object clbl("CallableClass", "Arctics around mount Meru");
+ Php::out << clbl("is the birthplace of the Hyperboreans") << std::endl;
+ }
+
+/**
+ * End of namespace
+ */
+}
+
diff --git a/tests/cpp/include/variables/tpl.h b/tests/cpp/include/variables/tpl.h
new file mode 100644
index 0000000..3c4ed7c
--- /dev/null
+++ b/tests/cpp/include/variables/tpl.h
@@ -0,0 +1,30 @@
+/**
+ *
+ * Test variables
+ * phptname.phpt
+ *
+ */
+
+
+
+
+/**
+ * Set up namespace
+ */
+namespace TestVariables {
+
+
+ /*
+ * Test
+ */
+ void fnname(Php::Parameters &params)
+ {
+
+
+ }
+
+/**
+ * End of namespace
+ */
+}
+
diff --git a/tests/cpp/main.cpp b/tests/cpp/main.cpp
index 2928f60..db2416d 100644
--- a/tests/cpp/main.cpp
+++ b/tests/cpp/main.cpp
@@ -8,9 +8,9 @@
#include <phpcpp.h>
// Test includes
-#include "include/ValueIterator.h"
-#include "include/MyCustomClass.h"
-#include "include/variables.h"
+#include "h/ValueIterator.h"
+#include "h/Classes_and_objects.h"
+#include "h/variables.h"
@@ -33,7 +33,14 @@ extern "C"
// add the interface to the extension
//extension.add(interface);
+
+
+
+ /**
+ * Classes and objects
+ *
+ */
// we are going to define a class
Php::Class<TestBaseClass::MyCustomClass> customClass("TestBaseClass\\MyClass");
@@ -42,9 +49,38 @@ extern "C"
customClass.property("property1", "prop1");
customClass.property("property2", "prop2", Php::Protected);
+ customClass.property("CONSTANT1", "some string", Php::Const);
+ customClass.property("EXP", 2.718281828459, Php::Const);
+ customClass.property("CONSTANT2", -2582341, Php::Const);
+ customClass.property("CONSTANT1", true, Php::Const);
+
// add the class to the extension
extension.add(customClass);
+ // Comparable
+ extension.add( Php::Class<TestBaseClass::Comparable>("TestBaseClass\\Comparable") );
+
+
+ // test static functions
+ //
+ // description of the class so that PHP knows which methods are accessible
+ Php::Class<TestBaseClass::testStaticPubClass> ClassWithStatic("TestBaseClass\\ClassWithStatic");
+ // register the testStaticPubClass::staticMethod to be a static method callable from PHP
+ ClassWithStatic.method("static1", &TestBaseClass::testStaticPubClass::staticMethod);
+ // regular functions have the same signatures as static methods. So nothing forbids you to register a normal function as static method too
+ ClassWithStatic.method("static2", TestBaseClass::testStaticRegFunc);
+ // and even static methods from completely different classes have the same function signature and can thus be registered
+ ClassWithStatic.method("static3", &TestBaseClass::testStaticPrivClass::staticMethod);
+ // add the class to the extension
+ extension.add(std::move(ClassWithStatic));
+ // In fact, because a static method has the same signature
+ // as a regular function, you can also register static
+ // C++ methods as regular global PHP functions
+ extension.add("TestBaseClass\\staticFun1", &TestBaseClass::testStaticPrivClass::staticMethod);
+
+
+
+
/**
* tests for Iterators
*
@@ -52,22 +88,34 @@ extern "C"
// add function to extension
//extension.add("TestValueIterator\\loopValue", TestValueIterator::loopValue/*, {
extension.add("TestValueIterator\\loopValue", TestValueIterator::loopValue);
+ extension.add("TestValueIterator\\loopArray", TestValueIterator::loopArray);
/**
* tests for variables
*
*/
+ // create a nested namespace
extension.add("TestVariables\\process_globals", TestVariables::process_globals);
extension.add("TestVariables\\get_complex_array", TestVariables::get_complex_array);
extension.add("TestVariables\\value_types", TestVariables::value_types);
extension.add("TestVariables\\scalar_store", TestVariables::scalar_store);
extension.add("TestVariables\\value_casting", TestVariables::value_casting);
+ extension.add("TestVariables\\value_cast2double", TestVariables::value_cast2double);
extension.add("TestVariables\\value_cast2str", TestVariables::value_cast2str);
extension.add("TestVariables\\overloaded_op", TestVariables::overloaded_op);
extension.add("TestVariables\\value_arrays", TestVariables::value_arrays);
- extension.add("TestVariables\\value_object1", TestVariables::value_object1);
- extension.add("TestVariables\\value_object2", TestVariables::value_object2);
+ extension.add("TestVariables\\value_object1", TestVariables::value_object1);
+ extension.add("TestVariables\\value_object2", TestVariables::value_object2);
+ extension.add("TestVariables\\fnFromUserSpace", TestVariables::fnFromUserSpace);
+ extension.add("TestVariables\\fnFromUserSpace2", TestVariables::fnFromUserSpace2);
+ extension.add("TestVariables\\fnCallback", TestVariables::fnCallback);
+
+
+
+ // A sample class, with methods to cast objects to scalars
+ Php::Class<TestVariables::Obj2Scalar> cObj2Scalar("TestVariables\\Obj2Scalar");
+ extension.add(std::move(cObj2Scalar));
diff --git a/tests/php/dbg.php b/tests/php/dbg.php
index 9a28fc6..2040f01 100644
--- a/tests/php/dbg.php
+++ b/tests/php/dbg.php
@@ -11,3 +11,4 @@
+
diff --git a/tests/php/php_alias.sh b/tests/php/php_alias.sh
index 34c2918..f4c7f8f 100755
--- a/tests/php/php_alias.sh
+++ b/tests/php/php_alias.sh
@@ -16,4 +16,4 @@ fi
LD_LIBRARY_PATH="$(cd $PWD/../.. && echo $PWD):${LD_LIBRARY_PATH}"
export LD_LIBRARY_PATH
-/usr/bin/php -d enable_dl=On -d extension_dir=../ext_dir -d extension=extfortest.so $1
+/usr/bin/php -d extension_dir=../ext_dir -d extension=extfortest.so $1
diff --git a/tests/php/phpt/base/001.phpt b/tests/php/phpt/class_obj/001.phpt
index b22a44c..b22a44c 100644
--- a/tests/php/phpt/base/001.phpt
+++ b/tests/php/phpt/class_obj/001.phpt
diff --git a/tests/php/phpt/base/002.phpt b/tests/php/phpt/class_obj/002.phpt
index 847e602..847e602 100644
--- a/tests/php/phpt/base/002.phpt
+++ b/tests/php/phpt/class_obj/002.phpt
diff --git a/tests/php/phpt/class_obj/003-comparable.phpt b/tests/php/phpt/class_obj/003-comparable.phpt
new file mode 100644
index 0000000..3e0b1f6
--- /dev/null
+++ b/tests/php/phpt/class_obj/003-comparable.phpt
@@ -0,0 +1,46 @@
+--TEST--
+Test comparable objects
+--SKIPIF--
+<?php if (!extension_loaded("extension_for_tests")) print "skip"; ?>
+--FILEEOF--
+<?php
+
+// initialize a couple of objects
+$object1 = new TestBaseClass\Comparable();
+$object2 = new TestBaseClass\Comparable();
+$object3 = new TestBaseClass\Comparable();
+
+// compare the objects
+if ($object1 < $object2)
+{
+ echo("$object1 is smaller than $object2\n");
+}
+else
+{
+ echo("$object1 is bigger than $object2\n");
+}
+
+if ($object1 == $object3)
+{
+ echo("$object1 is equal to $object3\n");
+}
+else
+{
+ echo("$object1 is not equal to $object3\n");
+}
+
+if ($object1 != $object2)
+{
+ echo("$object1 is not equal to $object2\n");
+}
+else
+{
+ echo("$object1 is equal to $object2\n");
+}
+
+
+//echo PHP_EOL;
+--EXPECT--
+Obj#1(2) is bigger than Obj#2(1)
+Obj#1(2) is equal to Obj#3(2)
+Obj#1(2) is not equal to Obj#2(1) \ No newline at end of file
diff --git a/tests/php/phpt/class_obj/004-static-funct.phpt b/tests/php/phpt/class_obj/004-static-funct.phpt
new file mode 100644
index 0000000..8c78210
--- /dev/null
+++ b/tests/php/phpt/class_obj/004-static-funct.phpt
@@ -0,0 +1,26 @@
+--TEST--
+Test class with static function
+--SKIPIF--
+<?php if (!extension_loaded("extension_for_tests")) print "skip"; ?>
+--FILEEOF--
+<?php
+
+// this will call PublicClass::staticMethod()
+TestBaseClass\ClassWithStatic::static1();
+
+// this will call PrivateClass::staticMethod()
+TestBaseClass\ClassWithStatic::static2();
+
+// this will call regularFunction()
+TestBaseClass\ClassWithStatic::static3();
+
+// this will also call PrivateClass::staticMethod()
+TestBaseClass\staticFun1();
+
+
+//echo PHP_EOL;
+--EXPECT--
+testStaticPubClass::staticMethod()
+testStatic regular function
+testStaticPrivClass::staticMethod()
+testStaticPrivClass::staticMethod() \ No newline at end of file
diff --git a/tests/php/phpt/class_obj/004-static-prop.phpt b/tests/php/phpt/class_obj/004-static-prop.phpt
new file mode 100644
index 0000000..4073247
--- /dev/null
+++ b/tests/php/phpt/class_obj/004-static-prop.phpt
@@ -0,0 +1,19 @@
+--TEST--
+Test class with static property and class constant
+--SKIPIF--
+<?php if (!extension_loaded("extension_for_tests")) print "skip"; ?>
+--FILEEOF--
+<?php
+
+var_dump( TestBaseClass\MyClass::CONSTANT1 );
+var_dump( TestBaseClass\MyClass::EXP );
+var_dump( TestBaseClass\MyClass::CONSTANT2 );
+var_dump( TestBaseClass\MyClass::CONSTANT1 );
+
+
+//echo PHP_EOL;
+--EXPECT--
+bool(true)
+float(2.718281828459)
+int(-2582341)
+bool(true) \ No newline at end of file
diff --git a/tests/php/phpt/base/readme b/tests/php/phpt/class_obj/readme
index 6c89a94..6c89a94 100644
--- a/tests/php/phpt/base/readme
+++ b/tests/php/phpt/class_obj/readme
diff --git a/tests/php/phpt/valueiterator/007-Iterate-internal-array.phpt b/tests/php/phpt/valueiterator/007-Iterate-internal-array.phpt
new file mode 100644
index 0000000..1f18203
--- /dev/null
+++ b/tests/php/phpt/valueiterator/007-Iterate-internal-array.phpt
@@ -0,0 +1,15 @@
+--TEST--
+Iterate internal array
+--SKIPIF--
+<?php if (!extension_loaded("extension_for_tests")) print "skip"; ?>
+--FILEEOF--
+<?php
+
+TestValueIterator\loopArray();
+
+--EXPECT--
+Array/Object contains 4 items
+[0]=val0
+[1]=val1
+[third]=val3
+[fourth]=val3
diff --git a/tests/php/phpt/variables/003-value-types.phpt- b/tests/php/phpt/variables/003-value-types.phpt
index 477fbe2..477fbe2 100644
--- a/tests/php/phpt/variables/003-value-types.phpt-
+++ b/tests/php/phpt/variables/003-value-types.phpt
diff --git a/tests/php/phpt/variables/005-cast-objects-to-scalars.phpt b/tests/php/phpt/variables/005-cast-objects-to-scalars.phpt
new file mode 100644
index 0000000..9de9ba5
--- /dev/null
+++ b/tests/php/phpt/variables/005-cast-objects-to-scalars.phpt
@@ -0,0 +1,22 @@
+--TEST--
+cast objects to scalars
+--DESCRIPTION--
+http://www.phpcpp.com/documentation/special-features#casting-functions
+--SKIPIF--
+<?php if (!extension_loaded("extension_for_tests")) print "skip"; ?>
+--FILEEOF--
+<?php
+
+
+function bool2str($b) {
+ return $b ? "Yes" : "No";
+}
+$obj = new TestVariables\Obj2Scalar();
+echo " long: ", (int)$obj, "\n string: ", (string)$obj, "\n double: ", (double)$obj, "\n bool: ", bool2str((bool)$obj);
+
+
+--EXPECT--
+ long: 27032014
+ string: Mount Meru, also called Sumeru (Sanskrit)
+ double: 3.14159265359
+ bool: Yes
diff --git a/tests/php/phpt/variables/005-value-casting-operators.phpt- b/tests/php/phpt/variables/011-value-casting-operators.phpt
index 5e0fb8e..3fe6817 100644
--- a/tests/php/phpt/variables/005-value-casting-operators.phpt-
+++ b/tests/php/phpt/variables/011-value-casting-operators.phpt
@@ -3,13 +3,9 @@ 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--
@@ -20,7 +16,8 @@ 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;
+ //echo " long:", (int)$value, "\n string:", (string)$value, "\n double:", (double)$value, "\n bool:", bool2str((bool)$value), PHP_EOL;
+ echo " long:", (int)$value, "\n string:", (string)$value, "\n bool:", bool2str((bool)$value), PHP_EOL;
}
@@ -61,114 +58,95 @@ out(0x1A); // hexadecimal number (equivalent to 26 decimal)
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/012-value-casting-operators-double.phpt b/tests/php/phpt/variables/012-value-casting-operators-double.phpt
new file mode 100644
index 0000000..32086ef
--- /dev/null
+++ b/tests/php/phpt/variables/012-value-casting-operators-double.phpt
@@ -0,0 +1,80 @@
+--TEST--
+Test Php::Value casting operators (double)
+--DESCRIPTION--
+The Php::Value class has casting operators to cast the object to almost every thinkable native type.
+
+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 out($v) {
+ echo 'Test ';
+ var_export($v);
+ echo ':', PHP_EOL;
+ TestVariables\value_cast2double($v);
+ //echo (double)$v, PHP_EOL;;
+ //echo PHP_EOL;
+}
+
+out(5555555555555555);
+out("999999999999999");
+out(999999999999999);
+out(5);
+out(-99999999);
+out("18");
+out("3.14159265359");
+out(3.14159265359);
+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)
+
+
+--EXPECT--
+Test 5555555555555555:
+5555555555555555
+Test '999999999999999':
+999999999999999
+Test 999999999999999:
+999999999999999
+Test 5:
+5
+Test -99999999:
+-99999999
+Test '18':
+18
+Test '3.14159265359':
+3.14159265359
+Test 3.14159265359:
+3.14159265359
+Test ' this is a string ':
+0
+Test ' 2-nd string ':
+2
+Test 'false':
+0
+Test false:
+0
+Test 'true':
+0
+Test true:
+1
+Test 0:
+0
+Test '0':
+0
+Test 83:
+83
+Test 26:
+26 \ No newline at end of file
diff --git a/tests/php/phpt/variables/013-calling-php-functions.phpt b/tests/php/phpt/variables/013-calling-php-functions.phpt
new file mode 100644
index 0000000..5ec6644
--- /dev/null
+++ b/tests/php/phpt/variables/013-calling-php-functions.phpt
@@ -0,0 +1,113 @@
+--TEST--
+calling-php-functions from userspace
+--SKIPIF--
+<?php if (!extension_loaded("extension_for_tests")) print "skip"; ?>
+--FILEEOF--
+<?php
+
+
+
+function some_function($param) {
+ echo("userspace function called with parameters:\n");
+ var_export(func_get_args ());
+}
+
+TestVariables\fnFromUserSpace();
+
+
+
+--EXPECT--
+fnFromUserSpace
+userspace function called with parameters:
+array (
+ 0 => 'param1',
+)userspace function called with parameters:
+array (
+ 0 => 'param1',
+ 1 => 'param2',
+)userspace function called with parameters:
+array (
+ 0 => 'param1',
+ 1 => 'param2',
+ 2 => 'param3',
+)userspace function called with parameters:
+array (
+ 0 => 'param1',
+ 1 => 'param2',
+ 2 => 'param3',
+ 3 => 'param4',
+)userspace function called with parameters:
+array (
+ 0 => 'param1',
+ 1 => 'param2',
+ 2 => 'param3',
+ 3 => 'param4',
+ 4 =>
+ array (
+ 0 => 'param5',
+ 1 => 3.14159265359,
+ 2 => 28032014,
+ 'key' => 'value',
+ ),
+)userspace function called with parameters:
+array (
+ 0 => 'param1',
+ 1 => 'param2',
+ 2 => 'param3',
+ 3 => 'param4',
+ 4 =>
+ array (
+ 0 => 'param5',
+ 1 => 3.14159265359,
+ 2 => 28032014,
+ 'key' => 'value',
+ ),
+ 5 =>
+ DateTime::__set_state(array(
+ 'date' => '2014-03-28 19:42:15',
+ 'timezone_type' => 3,
+ 'timezone' => 'Asia/Yekaterinburg',
+ )),
+)userspace function called with parameters:
+array (
+ 0 => 'param1',
+ 1 => 'param2',
+ 2 => 'param3',
+ 3 => 'param4',
+ 4 => 'param5',
+ 5 => 'param6',
+ 6 => 'param7',
+)userspace function called with parameters:
+array (
+ 0 => 'param1',
+ 1 => 'param2',
+ 2 => 'param3',
+ 3 => 'param4',
+ 4 => 'param5',
+ 5 => 'param6',
+ 6 => 'param7',
+ 7 => 'param8',
+)userspace function called with parameters:
+array (
+ 0 => 'param1',
+ 1 => 'param2',
+ 2 => 'param3',
+ 3 => 'param4',
+ 4 => 'param5',
+ 5 => 'param6',
+ 6 => 'param7',
+ 7 => 'param8',
+ 8 => 'param9',
+)userspace function called with parameters:
+array (
+ 0 => 'param1',
+ 1 => 'param2',
+ 2 => 'param3',
+ 3 => 'param4',
+ 4 => 'param5',
+ 5 => 'param6',
+ 6 => 'param7',
+ 7 => 'param8',
+ 8 => 'param9',
+ 9 => 'param10',
+) \ No newline at end of file
diff --git a/tests/php/phpt/variables/014-calling-php-functions.phpt b/tests/php/phpt/variables/014-calling-php-functions.phpt
new file mode 100644
index 0000000..4a05e2a
--- /dev/null
+++ b/tests/php/phpt/variables/014-calling-php-functions.phpt
@@ -0,0 +1,113 @@
+--TEST--
+calling-php-Callback-functions
+--SKIPIF--
+<?php if (!extension_loaded("extension_for_tests")) print "skip"; ?>
+--FILEEOF--
+<?php
+
+
+
+function some_function($param) {
+ echo("Callback called with parameters:\n");
+ var_export(func_get_args ());
+}
+
+TestVariables\fnCallback("some_function");
+
+
+
+--EXPECT--
+call callback
+Callback called with parameters:
+array (
+ 0 => 'param1',
+)Callback called with parameters:
+array (
+ 0 => 'param1',
+ 1 => 'param2',
+)Callback called with parameters:
+array (
+ 0 => 'param1',
+ 1 => 'param2',
+ 2 => 'param3',
+)Callback called with parameters:
+array (
+ 0 => 'param1',
+ 1 => 'param2',
+ 2 => 'param3',
+ 3 => 'param4',
+)Callback called with parameters:
+array (
+ 0 => 'param1',
+ 1 => 'param2',
+ 2 => 'param3',
+ 3 => 'param4',
+ 4 =>
+ array (
+ 0 => 'param5',
+ 1 => 3.14159265359,
+ 2 => 28032014,
+ 'key' => 'value',
+ ),
+)Callback called with parameters:
+array (
+ 0 => 'param1',
+ 1 => 'param2',
+ 2 => 'param3',
+ 3 => 'param4',
+ 4 =>
+ array (
+ 0 => 'param5',
+ 1 => 3.14159265359,
+ 2 => 28032014,
+ 'key' => 'value',
+ ),
+ 5 =>
+ DateTime::__set_state(array(
+ 'date' => '2014-03-28 19:42:15',
+ 'timezone_type' => 3,
+ 'timezone' => 'Asia/Yekaterinburg',
+ )),
+)Callback called with parameters:
+array (
+ 0 => 'param1',
+ 1 => 'param2',
+ 2 => 'param3',
+ 3 => 'param4',
+ 4 => 'param5',
+ 5 => 'param6',
+ 6 => 'param7',
+)Callback called with parameters:
+array (
+ 0 => 'param1',
+ 1 => 'param2',
+ 2 => 'param3',
+ 3 => 'param4',
+ 4 => 'param5',
+ 5 => 'param6',
+ 6 => 'param7',
+ 7 => 'param8',
+)Callback called with parameters:
+array (
+ 0 => 'param1',
+ 1 => 'param2',
+ 2 => 'param3',
+ 3 => 'param4',
+ 4 => 'param5',
+ 5 => 'param6',
+ 6 => 'param7',
+ 7 => 'param8',
+ 8 => 'param9',
+)Callback called with parameters:
+array (
+ 0 => 'param1',
+ 1 => 'param2',
+ 2 => 'param3',
+ 3 => 'param4',
+ 4 => 'param5',
+ 5 => 'param6',
+ 6 => 'param7',
+ 7 => 'param8',
+ 8 => 'param9',
+ 9 => 'param10',
+) \ No newline at end of file
diff --git a/tests/php/phpt/variables/015-calling-php-functions.phpt b/tests/php/phpt/variables/015-calling-php-functions.phpt
new file mode 100644
index 0000000..e9382b2
--- /dev/null
+++ b/tests/php/phpt/variables/015-calling-php-functions.phpt
@@ -0,0 +1,109 @@
+--TEST--
+calling-php-Callback-functions (lambda)
+--SKIPIF--
+<?php if (!extension_loaded("extension_for_tests")) print "skip"; ?>
+--FILEEOF--
+<?php
+
+
+TestVariables\fnCallback( function($param) {
+ echo("Callback called with parameters:\n");
+ var_export(func_get_args ());
+});
+
+
+--EXPECT--
+call callback
+Callback called with parameters:
+array (
+ 0 => 'param1',
+)Callback called with parameters:
+array (
+ 0 => 'param1',
+ 1 => 'param2',
+)Callback called with parameters:
+array (
+ 0 => 'param1',
+ 1 => 'param2',
+ 2 => 'param3',
+)Callback called with parameters:
+array (
+ 0 => 'param1',
+ 1 => 'param2',
+ 2 => 'param3',
+ 3 => 'param4',
+)Callback called with parameters:
+array (
+ 0 => 'param1',
+ 1 => 'param2',
+ 2 => 'param3',
+ 3 => 'param4',
+ 4 =>
+ array (
+ 0 => 'param5',
+ 1 => 3.14159265359,
+ 2 => 28032014,
+ 'key' => 'value',
+ ),
+)Callback called with parameters:
+array (
+ 0 => 'param1',
+ 1 => 'param2',
+ 2 => 'param3',
+ 3 => 'param4',
+ 4 =>
+ array (
+ 0 => 'param5',
+ 1 => 3.14159265359,
+ 2 => 28032014,
+ 'key' => 'value',
+ ),
+ 5 =>
+ DateTime::__set_state(array(
+ 'date' => '2014-03-28 19:42:15',
+ 'timezone_type' => 3,
+ 'timezone' => 'Asia/Yekaterinburg',
+ )),
+)Callback called with parameters:
+array (
+ 0 => 'param1',
+ 1 => 'param2',
+ 2 => 'param3',
+ 3 => 'param4',
+ 4 => 'param5',
+ 5 => 'param6',
+ 6 => 'param7',
+)Callback called with parameters:
+array (
+ 0 => 'param1',
+ 1 => 'param2',
+ 2 => 'param3',
+ 3 => 'param4',
+ 4 => 'param5',
+ 5 => 'param6',
+ 6 => 'param7',
+ 7 => 'param8',
+)Callback called with parameters:
+array (
+ 0 => 'param1',
+ 1 => 'param2',
+ 2 => 'param3',
+ 3 => 'param4',
+ 4 => 'param5',
+ 5 => 'param6',
+ 6 => 'param7',
+ 7 => 'param8',
+ 8 => 'param9',
+)Callback called with parameters:
+array (
+ 0 => 'param1',
+ 1 => 'param2',
+ 2 => 'param3',
+ 3 => 'param4',
+ 4 => 'param5',
+ 5 => 'param6',
+ 6 => 'param7',
+ 7 => 'param8',
+ 8 => 'param9',
+ 9 => 'param10',
+) \ No newline at end of file
diff --git a/tests/php/phpt/variables/016-calling-php-functions.phpt b/tests/php/phpt/variables/016-calling-php-functions.phpt
new file mode 100644
index 0000000..46fda6e
--- /dev/null
+++ b/tests/php/phpt/variables/016-calling-php-functions.phpt
@@ -0,0 +1,113 @@
+--TEST--
+calling-php-Callback-functions (__invoke)
+--SKIPIF--
+<?php if (!extension_loaded("extension_for_tests")) print "skip"; ?>
+--FILEEOF--
+<?php
+
+
+class CallableClass {
+ public function __invoke() {
+ echo("Callback called with parameters:\n");
+ var_export(func_get_args ());
+ }
+}
+
+TestVariables\fnCallback(new CallableClass());
+
+
+--EXPECT--
+call callback
+Callback called with parameters:
+array (
+ 0 => 'param1',
+)Callback called with parameters:
+array (
+ 0 => 'param1',
+ 1 => 'param2',
+)Callback called with parameters:
+array (
+ 0 => 'param1',
+ 1 => 'param2',
+ 2 => 'param3',
+)Callback called with parameters:
+array (
+ 0 => 'param1',
+ 1 => 'param2',
+ 2 => 'param3',
+ 3 => 'param4',
+)Callback called with parameters:
+array (
+ 0 => 'param1',
+ 1 => 'param2',
+ 2 => 'param3',
+ 3 => 'param4',
+ 4 =>
+ array (
+ 0 => 'param5',
+ 1 => 3.14159265359,
+ 2 => 28032014,
+ 'key' => 'value',
+ ),
+)Callback called with parameters:
+array (
+ 0 => 'param1',
+ 1 => 'param2',
+ 2 => 'param3',
+ 3 => 'param4',
+ 4 =>
+ array (
+ 0 => 'param5',
+ 1 => 3.14159265359,
+ 2 => 28032014,
+ 'key' => 'value',
+ ),
+ 5 =>
+ DateTime::__set_state(array(
+ 'date' => '2014-03-28 19:42:15',
+ 'timezone_type' => 3,
+ 'timezone' => 'Asia/Yekaterinburg',
+ )),
+)Callback called with parameters:
+array (
+ 0 => 'param1',
+ 1 => 'param2',
+ 2 => 'param3',
+ 3 => 'param4',
+ 4 => 'param5',
+ 5 => 'param6',
+ 6 => 'param7',
+)Callback called with parameters:
+array (
+ 0 => 'param1',
+ 1 => 'param2',
+ 2 => 'param3',
+ 3 => 'param4',
+ 4 => 'param5',
+ 5 => 'param6',
+ 6 => 'param7',
+ 7 => 'param8',
+)Callback called with parameters:
+array (
+ 0 => 'param1',
+ 1 => 'param2',
+ 2 => 'param3',
+ 3 => 'param4',
+ 4 => 'param5',
+ 5 => 'param6',
+ 6 => 'param7',
+ 7 => 'param8',
+ 8 => 'param9',
+)Callback called with parameters:
+array (
+ 0 => 'param1',
+ 1 => 'param2',
+ 2 => 'param3',
+ 3 => 'param4',
+ 4 => 'param5',
+ 5 => 'param6',
+ 6 => 'param7',
+ 7 => 'param8',
+ 8 => 'param9',
+ 9 => 'param10',
+) \ No newline at end of file
diff --git a/tests/php/phpt/variables/017-calling-php-functions.phpt b/tests/php/phpt/variables/017-calling-php-functions.phpt
new file mode 100644
index 0000000..630399a
--- /dev/null
+++ b/tests/php/phpt/variables/017-calling-php-functions.phpt
@@ -0,0 +1,115 @@
+--TEST--
+calling-php-Callback-functions (method of class)
+--SKIPIF--
+<?php if (!extension_loaded("extension_for_tests")) print "skip"; ?>
+--FILEEOF--
+<?php
+
+
+class someClass {
+ function someMethod() {
+ echo("Callback called with parameters:\n");
+ var_export(func_get_args ());
+ }
+}
+
+$anObject = new someClass();
+$methodVariable = array($anObject, 'someMethod');
+TestVariables\fnCallback($methodVariable);
+
+
+--EXPECT--
+call callback
+Callback called with parameters:
+array (
+ 0 => 'param1',
+)Callback called with parameters:
+array (
+ 0 => 'param1',
+ 1 => 'param2',
+)Callback called with parameters:
+array (
+ 0 => 'param1',
+ 1 => 'param2',
+ 2 => 'param3',
+)Callback called with parameters:
+array (
+ 0 => 'param1',
+ 1 => 'param2',
+ 2 => 'param3',
+ 3 => 'param4',
+)Callback called with parameters:
+array (
+ 0 => 'param1',
+ 1 => 'param2',
+ 2 => 'param3',
+ 3 => 'param4',
+ 4 =>
+ array (
+ 0 => 'param5',
+ 1 => 3.14159265359,
+ 2 => 28032014,
+ 'key' => 'value',
+ ),
+)Callback called with parameters:
+array (
+ 0 => 'param1',
+ 1 => 'param2',
+ 2 => 'param3',
+ 3 => 'param4',
+ 4 =>
+ array (
+ 0 => 'param5',
+ 1 => 3.14159265359,
+ 2 => 28032014,
+ 'key' => 'value',
+ ),
+ 5 =>
+ DateTime::__set_state(array(
+ 'date' => '2014-03-28 19:42:15',
+ 'timezone_type' => 3,
+ 'timezone' => 'Asia/Yekaterinburg',
+ )),
+)Callback called with parameters:
+array (
+ 0 => 'param1',
+ 1 => 'param2',
+ 2 => 'param3',
+ 3 => 'param4',
+ 4 => 'param5',
+ 5 => 'param6',
+ 6 => 'param7',
+)Callback called with parameters:
+array (
+ 0 => 'param1',
+ 1 => 'param2',
+ 2 => 'param3',
+ 3 => 'param4',
+ 4 => 'param5',
+ 5 => 'param6',
+ 6 => 'param7',
+ 7 => 'param8',
+)Callback called with parameters:
+array (
+ 0 => 'param1',
+ 1 => 'param2',
+ 2 => 'param3',
+ 3 => 'param4',
+ 4 => 'param5',
+ 5 => 'param6',
+ 6 => 'param7',
+ 7 => 'param8',
+ 8 => 'param9',
+)Callback called with parameters:
+array (
+ 0 => 'param1',
+ 1 => 'param2',
+ 2 => 'param3',
+ 3 => 'param4',
+ 4 => 'param5',
+ 5 => 'param6',
+ 6 => 'param7',
+ 7 => 'param8',
+ 8 => 'param9',
+ 9 => 'param10',
+) \ No newline at end of file
diff --git a/tests/php/phpt/variables/018-calling-php-functions.phpt b/tests/php/phpt/variables/018-calling-php-functions.phpt
new file mode 100644
index 0000000..1b8bfeb
--- /dev/null
+++ b/tests/php/phpt/variables/018-calling-php-functions.phpt
@@ -0,0 +1,32 @@
+--TEST--
+calling-php-callable
+--DESCRIPTION--
+call callable object of class from user space
+call method of class from user space
+--SKIPIF--
+<?php if (!extension_loaded("extension_for_tests")) print "skip"; ?>
+--FILEEOF--
+<?php
+
+
+class CallableClass {
+ public function __construct($a){ $this->a = $a;}
+ public function __invoke($b){ echo "CallableClass({$this->a})::__invoke($b)";}
+ private $a = "";
+}
+
+class usrspClass {
+ function __construct($a){ $this->a = $a;}
+ function someMethod($b) {echo "usrspClass({$this->a})::someMethod($b)";}
+ private $a = "";
+}
+
+
+TestVariables\fnFromUserSpace2();
+
+
+--EXPECT--
+2014-03-28 21:22:15
+2014-03-28 21:22:15
+usrspClass(Mount Meru)::someMethod(is in the Arctics)
+CallableClass(Arctics around mount Meru)::__invoke(is the birthplace of the Hyperboreans) \ No newline at end of file
diff --git a/tests/php/phpt/variables/readme b/tests/php/phpt/variables/readme
index 8162526..a47cb89 100644
--- a/tests/php/phpt/variables/readme
+++ b/tests/php/phpt/variables/readme
@@ -1 +1,5 @@
tests variables
+
+TODO: more tests for globals variables
+including separate test for $_GET, $_POST, $_COOKIE, $_FILES, $_SERVER, $_REQUEST and $_ENV (Php::GET, Php::POST, Php::COOKIE, Php::FILES, Php::SERVER, Php::REQUEST and Php::ENV) variables.
+