diff options
author | valmat <ufabiz@gmail.com> | 2014-03-28 21:58:30 +0600 |
---|---|---|
committer | valmat <ufabiz@gmail.com> | 2014-03-28 21:58:30 +0600 |
commit | 4091487adfbfd07750524fd7910d7178af21f816 (patch) | |
tree | fb909ff7dedbe5eef51533364cdff09e9f4e575e /tests | |
parent | 168eeabc6e52165a71a3130c5e0f26a7fd9382c9 (diff) |
add test: 018-calling-php-functions
Diffstat (limited to 'tests')
-rw-r--r-- | tests/cpp/h/variables.h | 2 | ||||
-rw-r--r-- | tests/cpp/include/variables/013-018-calling-php-functions.h (renamed from tests/cpp/include/variables/013-017-calling-php-functions.h) | 42 | ||||
-rw-r--r-- | tests/cpp/main.cpp | 1 | ||||
-rw-r--r-- | tests/php/phpt/variables/018-calling-php-functions.phpt | 32 |
4 files changed, 75 insertions, 2 deletions
diff --git a/tests/cpp/h/variables.h b/tests/cpp/h/variables.h index df0d923..3ff77e9 100644 --- a/tests/cpp/h/variables.h +++ b/tests/cpp/h/variables.h @@ -17,7 +17,7 @@ #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-017-calling-php-functions.h" +#include "../include/variables/013-018-calling-php-functions.h" //#include "../include/variables/.h" //#include "../include/variables/.h" diff --git a/tests/cpp/include/variables/013-017-calling-php-functions.h b/tests/cpp/include/variables/013-018-calling-php-functions.h index 94367e0..c646f60 100644 --- a/tests/cpp/include/variables/013-017-calling-php-functions.h +++ b/tests/cpp/include/variables/013-018-calling-php-functions.h @@ -3,7 +3,7 @@ * Test call function * 013-calling-php-functions.phpt * ... - * 017-calling-php-functions.phpt + * 018-calling-php-functions.phpt * */ @@ -79,6 +79,46 @@ namespace TestVariables { } + /* + * 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; + + + + //::someMethod + //(new usrspClass("Mount Meru"))->someMethod("is in the Arctics"); + + + + + + } /** * End of namespace diff --git a/tests/cpp/main.cpp b/tests/cpp/main.cpp index 4db7b9c..5d0d0a6 100644 --- a/tests/cpp/main.cpp +++ b/tests/cpp/main.cpp @@ -103,6 +103,7 @@ extern "C" 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); 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 |