diff options
Diffstat (limited to 'tests')
22 files changed, 1001 insertions, 62 deletions
diff --git a/tests/cpp/Makefile b/tests/cpp/Makefile index e0c32ba..6239170 100644 --- a/tests/cpp/Makefile +++ b/tests/cpp/Makefile @@ -88,7 +88,7 @@ LINKER = g++ # LIB_DIR=$(shell cd ../.. && pwd) -COMPILER_FLAGS = -Wall -c -O2 -std=c++11 -fpic -I"${LIB_DIR}/include" -o +COMPILER_FLAGS = -Wall -c -O2 -std=c++11 -fpic -I"${LIB_DIR}/include" -I"./zts" -o LINKER_FLAGS = -shared -L"${LIB_DIR}" LINKER_DEPENDENCIES = -lphpcpp diff --git a/tests/cpp/include/testValueIterator.h b/tests/cpp/include/ValueIterator.h index a9329c9..a9329c9 100644 --- a/tests/cpp/include/testValueIterator.h +++ b/tests/cpp/include/ValueIterator.h diff --git a/tests/cpp/include/variables.h b/tests/cpp/include/variables.h new file mode 100644 index 0000000..f242653 --- /dev/null +++ b/tests/cpp/include/variables.h @@ -0,0 +1,293 @@ +/** + * + * 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 ¶ms) { + 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 ¶ms) + { + 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 ¶ms) + { + std::string value = params[0]; + Php::out << value << std::endl; + } + + /* + * Test Php::Value overloaded operators + */ + void overloaded_op(Php::Parameters ¶ms) + { + 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 ¶ms) + { + + + } + + + + + + + +/** + * End of namespace + */ +} + diff --git a/tests/cpp/main.cpp b/tests/cpp/main.cpp index 154b61b..2928f60 100644 --- a/tests/cpp/main.cpp +++ b/tests/cpp/main.cpp @@ -8,8 +8,10 @@ #include <phpcpp.h> // Test includes -#include "include/testValueIterator.h" +#include "include/ValueIterator.h" #include "include/MyCustomClass.h" +#include "include/variables.h" + @@ -43,10 +45,35 @@ extern "C" // add the class to the extension extension.add(customClass); - + /** + * tests for Iterators + * + */ // add function to extension //extension.add("TestValueIterator\\loopValue", TestValueIterator::loopValue/*, { extension.add("TestValueIterator\\loopValue", TestValueIterator::loopValue); + + + /** + * tests for variables + * + */ + 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_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); + + + + + + // return the extension module return extension; diff --git a/tests/cpp/zts/.gitignore b/tests/cpp/zts/.gitignore new file mode 100644 index 0000000..8d82a92 --- /dev/null +++ b/tests/cpp/zts/.gitignore @@ -0,0 +1 @@ +phpcpp/config.h 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/.gitignore b/tests/php/phpt/.gitignore index e89581c..b583a44 100644 --- a/tests/php/phpt/.gitignore +++ b/tests/php/phpt/.gitignore @@ -5,3 +5,10 @@ *.php *.sh *.mem +*.phpt-diff +*.phpt-exp +*.phpt-log +*.phpt-out +*.phpt-php +*.phpt-sh +*.phpt-mem 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 diff --git a/tests/prepare.sh b/tests/prepare.sh index 58fc646..6c0e331 100755 --- a/tests/prepare.sh +++ b/tests/prepare.sh @@ -1,27 +1,31 @@ #!/bin/bash # -# do not run this script. -# Create a local copy of the directory with the extension for run without installation +# do not run this script manualy. +# This script is intended to be run from a script test.sh +# Create a local copy of the directory with the extension for run tests without installation +# +# @author valmat <ufabiz@gmail.com> # - +# Local directory in which to copy the links to all installed extensions EXTDLOC=ext_dir +mkdir -p "./$EXTDLOC" + SO=extfortest.so +# to check whether specified the extension name as parameter if [ $1 ] then SO=$1 fi +# a directory of extensions already installed in the operating system EXTDIR=$(php-config --extension-dir) -#echo $EXTDIR - -mkdir -p "./$EXTDLOC" +# To copy references for all extensions to the local directory for LIBFILE in `find $EXTDIR -type f -or -type l -name "*.so"`; do BN=$(basename $LIBFILE) - PWD=$(pwd) NF="$PWD/$EXTDLOC/$BN" # if still no exist @@ -29,7 +33,6 @@ for LIBFILE in `find $EXTDIR -type f -or -type l -name "*.so"`; do then if [ -L $LIBFILE ]; then - #echo "cp $LIBFILE $NF" cp --no-dereference $LIBFILE $NF else ln -s $LIBFILE $NF @@ -40,10 +43,9 @@ for LIBFILE in `find $EXTDIR -type f -or -type l -name "*.so"`; do done # current extention -if [ ! -L "$PWD/$EXTDLOC/$SO" ]; +if [ ! -L "$PWD/$EXTDLOC/$SO" ] then ln -s "$PWD/cpp/$SO" "$PWD/$EXTDLOC/$SO" fi - diff --git a/tests/readme b/tests/readme index 1134f51..929f1b9 100644 --- a/tests/readme +++ b/tests/readme @@ -1,3 +1,7 @@ In this directory cpp extension is designed to conduct tests. When creating a test, do not use extension requiring the installation. -In the catalog php are the tests themselves. +In the directory php are the tests themselves. + +You can run test.sh with additional options. +The full list of available options see ./test.sh -h + diff --git a/tests/run-tests.php b/tests/run-tests.php index df9cf1e..798d218 100644 --- a/tests/run-tests.php +++ b/tests/run-tests.php @@ -765,7 +765,7 @@ HELP; } else if (is_dir($testfile)) { find_files($testfile); - } else if (preg_match("/\.phpt$/", $testfile)) { + } else if (preg_match("/\.phpt\-?$/", $testfile)) { $test_files[] = $testfile; } else { die("bogus test name " . $argv[$i] . "\n"); diff --git a/tests/test.sh b/tests/test.sh index 952bf17..8f5baa5 100755 --- a/tests/test.sh +++ b/tests/test.sh @@ -2,6 +2,8 @@ # # It is intended to run the command "make test" from the root directory of the library # +# @author valmat <ufabiz@gmail.com> +# THIS=`basename $0` @@ -19,6 +21,8 @@ function print_help() { echo " -g <opt> Comma separated list of groups to show during test run" echo " (possible values: PASS, FAIL, XFAIL, SKIP, BORK, WARN, LEAK, REDIRECT)." echo " -m Test for memory leaks with Valgrind." + echo " -r Removes all auxiliary files. (*.log, *.diff etc)." + echo " -t <files> Test file(s). Specify individual file(s) to test" echo " -s <file> Write output to <file>." echo " -x Sets 'SKIP_SLOW_TESTS' environmental variable." echo " -o Cancels sets 'SKIP_ONLINE_TESTS' (default set)." @@ -30,12 +34,16 @@ function print_help() { } PHP_BIN="/usr/bin/php" +# options list SCR_OPT="" COMPILE_EXT=1 +# SKIP_ONLINE_TESTS == true OFFLINE=1 EXT_NAME="extfortest.so" +# The file list of the tests that will be launched +TEST_FILES="" -while getopts ":p:e:nw:a:d:g:ms:xoqvh" opt ; +while getopts ":p:e:nw:a:d:g:mrt:s:xoqvh" opt ; do case $opt in p) @@ -65,10 +73,42 @@ do m) SCR_OPT="$SCR_OPT -m" ;; + r) + # Removes all auxiliary files. (*.log, *.diff etc). + + # if quiet, only delete + if [ $(echo $SCR_OPT | grep -o "\-q") ]; then + find ./php/phpt -type f \( \ + -name '*.diff' -or -name '*.exp' -or -name '*.log' -or -name '*.out' \ + -or -name '*.php' -or -name '*.sh' -or -name '*.mem' -or \ + -name '*.phpt-diff' -or -name '*.phpt-exp' -or -name '*.phpt-log' -or -name '*.phpt-out' \ + -or -name '*.phpt-php' -or -name '*.phpt-sh' -or -name '*.phpt-mem' \ + \) -delete + + # else delete and print + else + echo -e "\x1b[1;31;47mRemove auxiliary files...\x1b[0;0m" + for AUXF in `find ./php/phpt -type f \( \ + -name '*.diff' -or -name '*.exp' -or -name '*.log' -or -name '*.out' \ + -or -name '*.php' -or -name '*.sh' -or -name '*.mem' -or \ + -name '*.phpt-diff' -or -name '*.phpt-exp' -or -name '*.phpt-log' -or -name '*.phpt-out' \ + -or -name '*.phpt-php' -or -name '*.phpt-sh' -or -name '*.phpt-mem' \ + \)`; + do + echo -e "\x1b[1;31;47mdel \x1b[0;30;47m$(dirname $AUXF)/\x1b[1;31;47m$(basename $AUXF)\x1b[0;30;47m ...\x1b[0;0m" + rm $AUXF + done + fi + exit; + ;; + t) + TEST_FILES="$OPTARG" + ;; x) SCR_OPT="$SCR_OPT -x" ;; o) + # SKIP_ONLINE_TESTS == false OFFLINE=0 ;; q) @@ -88,12 +128,18 @@ do esac done +# The file list of the tests that will be launched +if [ ! "$TEST_FILES" ]; then + TEST_FILES=`find ./php/phpt -type f -name "*.phpt"` +fi + # default offline mode if [ 1 = $OFFLINE ]; then SCR_OPT="$SCR_OPT --offline" fi + +# A list of all additional options SCR_OPT="$SCR_OPT -d extension_dir=$PWD/ext_dir -d extension=$EXT_NAME" -TEST_FILES=`find ./php/phpt -type f -name "*.phpt"` # Create a local copy of the directory with the extension for run without installation |