summaryrefslogtreecommitdiff
path: root/tests/php
diff options
context:
space:
mode:
authorvalmat <ufabiz@gmail.com>2014-03-18 15:18:11 +0600
committervalmat <ufabiz@gmail.com>2014-03-18 15:18:11 +0600
commite8334afd7f2920b706a3d28250a3e2b6dbd49538 (patch)
treea92e2b1b67c22eaad7eb84a2138ede2dae12e873 /tests/php
parentbfaed88493de0a3ebd7f2619cb11291cd09252b1 (diff)
Unit tests. For description see https://github.com/CopernicaMarketingSoftware/PHP-CPP/pull/25#issuecomment-37882236
Diffstat (limited to 'tests/php')
-rw-r--r--tests/php/dbg.php58
-rw-r--r--tests/php/include/check.php11
-rw-r--r--tests/php/include/set_get.php52
-rw-r--r--tests/php/include/valueiterator/1.php76
-rwxr-xr-xtests/php/php_alias.sh16
-rw-r--r--tests/php/phpt/.gitignore6
-rw-r--r--tests/php/phpt/base/001.phpt14
-rw-r--r--tests/php/phpt/base/002.phpt14
-rw-r--r--tests/php/phpt/base/readme1
-rw-r--r--tests/php/phpt/valueiterator/001.phpt22
-rw-r--r--tests/php/phpt/valueiterator/002.phpt22
-rw-r--r--tests/php/phpt/valueiterator/003.phpt18
-rw-r--r--tests/php/phpt/valueiterator/004.phpt20
-rw-r--r--tests/php/phpt/valueiterator/005.phpt19
-rw-r--r--tests/php/phpt/valueiterator/006.phpt21
-rw-r--r--tests/php/phpt/valueiterator/readme1
-rw-r--r--tests/php/readme9
17 files changed, 380 insertions, 0 deletions
diff --git a/tests/php/dbg.php b/tests/php/dbg.php
new file mode 100644
index 0000000..6f1dabc
--- /dev/null
+++ b/tests/php/dbg.php
@@ -0,0 +1,58 @@
+<?php
+
+/**
+ * For debugging tests
+ *
+ */
+
+
+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/include/check.php b/tests/php/include/check.php
new file mode 100644
index 0000000..c38b70d
--- /dev/null
+++ b/tests/php/include/check.php
@@ -0,0 +1,11 @@
+<?php
+
+require '../../../php/class.screennav.php';
+require '../files/set_get.php';
+
+$scr = new ScreenNav(5, 8456, 'http://some/url');
+
+ScrNavTestSetGet::get($scr);
+
+
+//echo var_dump(ScreenNav::pageNo('part')) .PHP_EOL; \ No newline at end of file
diff --git a/tests/php/include/set_get.php b/tests/php/include/set_get.php
new file mode 100644
index 0000000..8f596ba
--- /dev/null
+++ b/tests/php/include/set_get.php
@@ -0,0 +1,52 @@
+<?php
+
+class ScrNavTestSetGet {
+
+ static function set(&$scr) {
+
+ $scr->setInterval(21); // Сколько объектов на странице
+ $scr->setPrefix('?qwe&part='); // URL prefix
+ $scr->setPostfix('&prm=132'); // URL prefix
+ //$scr->setSpace('<space>...</space>'); // Разделитель блоков табов
+ //$scr->setCssName('newClassName'); // Имя класса css блока управления постраничным выводом
+ $scr->setMidTab(15); // см. info.png
+ $scr->setMaxTab(5); // см. info.png
+ $scr->showCount(true); // Показывать ли общее количество элементов
+
+ }
+
+ static function set1(&$scr) {
+
+ $scr->setInterval(21); // Сколько объектов на странице
+ $scr->setPrefix('?qwe&part='); // URL prefix
+ $scr->setPostfix('&prm=132'); // URL prefix
+ $scr->setSpace('<space>...</space>'); // Разделитель блоков табов
+ $scr->setCssName('newClassName'); // Имя класса css блока управления постраничным выводом
+ $scr->setMidTab(15); // см. info.png
+ $scr->setMaxTab(5); // см. info.png
+ $scr->showCount(false); // Показывать ли общее количество элементов
+
+ }
+
+ static function get(&$scr) {
+
+ self::get1($scr);
+ echo $scr->show();
+
+ }
+
+ static function get1(&$scr) {
+
+ var_export(array(
+ 'StartPos' => $scr->getStartPos(),
+ 'LimitPos' => $scr->getLimitPos(),
+ 'PageCnt' => $scr->getPageCnt(),
+ 'PageNo' => $scr->getPageNo(),
+ 'start' => $start = $scr->getStartPos(),
+ 'lim' => $start+$scr->getLimitPos()
+ ));
+
+ }
+
+
+} \ No newline at end of file
diff --git a/tests/php/include/valueiterator/1.php b/tests/php/include/valueiterator/1.php
new file mode 100644
index 0000000..984a77f
--- /dev/null
+++ b/tests/php/include/valueiterator/1.php
@@ -0,0 +1,76 @@
+<?php
+
+class SimpleClass {
+ public $cl0_float = 3.14;
+ public $cl0_str1 = 'public str1';
+ private $cl0_str2 = 'private str2';
+ protected $cl0_str3 = 'protected str3';
+}
+
+class impIterator implements Iterator {
+ private $position = 0;
+ private $array = array(
+ "firstElement",
+ "secondElement",
+ "lastelEment",
+ );
+
+ public function __construct() {
+ $this->position = 0;
+ }
+
+ function rewind() {
+ $this->position = 0;
+ }
+
+ function current() {
+ return $this->array[$this->position];
+ }
+
+ function key() {
+ return 'key_' . $this->position;
+ }
+
+ function next() {
+ ++$this->position;
+ }
+
+ function valid() {
+ return isset($this->array[$this->position]);
+ }
+
+ function __destruct() {
+ echo "~impIterator\n";
+ }
+}
+
+class impIterAggr1 implements IteratorAggregate {
+ public function getIterator() {
+ return new ArrayIterator(new SimpleClass);
+ }
+ function __destruct() {
+ echo "~impIterAggr1\n";
+ }
+}
+
+class impIterAggr2 implements IteratorAggregate {
+ public function getIterator() {
+ return new impIterator();
+ }
+ function __destruct() {
+ echo "~impIterAggr2\n";
+ }
+}
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/tests/php/php_alias.sh b/tests/php/php_alias.sh
new file mode 100755
index 0000000..2c028ca
--- /dev/null
+++ b/tests/php/php_alias.sh
@@ -0,0 +1,16 @@
+#!/bin/bash
+#!/bin/bash
+#
+# this only alias to comand "/usr/bin/php -d enable_dl=On -d extension_dir=../ext_dir -d extension=extfortest.so"
+# Designed to simplify debugging of tests
+# You can get the same thing using normal aliases: `alias php_alias="php -d enable_dl=On -d extension_dir=../ext_dir -d extension=extfortest.so"`
+# Exemlple toese: $ ./php_alias.sh dbg.php
+#
+
+if [ ! $1 ]
+then
+ echo "Required the path to php file"
+ exit;
+fi
+
+/usr/bin/php -d enable_dl=On -d extension_dir=../ext_dir -d extension=extfortest.so $1
diff --git a/tests/php/phpt/.gitignore b/tests/php/phpt/.gitignore
new file mode 100644
index 0000000..08989fa
--- /dev/null
+++ b/tests/php/phpt/.gitignore
@@ -0,0 +1,6 @@
+*.diff
+*.exp
+*.log
+*.out
+*.php
+*.sh
diff --git a/tests/php/phpt/base/001.phpt b/tests/php/phpt/base/001.phpt
new file mode 100644
index 0000000..91175d7
--- /dev/null
+++ b/tests/php/phpt/base/001.phpt
@@ -0,0 +1,14 @@
+--TEST--
+Test constructor & destructor
+--SKIPIF--
+<?php if (!extension_loaded("extention_for_tests")) print "skip"; ?>
+--FILEEOF--
+<?php
+
+new TestBaseClass\MyClass();
+
+
+echo PHP_EOL;
+--EXPECT--
+MyCustomClass::MyCustomClass()
+MyCustomClass::~MyCustomClass \ No newline at end of file
diff --git a/tests/php/phpt/base/002.phpt b/tests/php/phpt/base/002.phpt
new file mode 100644
index 0000000..a6f611b
--- /dev/null
+++ b/tests/php/phpt/base/002.phpt
@@ -0,0 +1,14 @@
+--TEST--
+Test constructor & destructor
+--SKIPIF--
+<?php if (!extension_loaded("extention_for_tests")) print "skip"; ?>
+--FILEEOF--
+<?php
+
+echo count(new TestBaseClass\MyClass($x));
+
+echo PHP_EOL;
+--EXPECT--
+MyCustomClass::MyCustomClass()
+MyCustomClass::~MyCustomClass
+33 \ No newline at end of file
diff --git a/tests/php/phpt/base/readme b/tests/php/phpt/base/readme
new file mode 100644
index 0000000..6c89a94
--- /dev/null
+++ b/tests/php/phpt/base/readme
@@ -0,0 +1 @@
+tests iterator
diff --git a/tests/php/phpt/valueiterator/001.phpt b/tests/php/phpt/valueiterator/001.phpt
new file mode 100644
index 0000000..ae85e23
--- /dev/null
+++ b/tests/php/phpt/valueiterator/001.phpt
@@ -0,0 +1,22 @@
+--TEST--
+Iterate array
+--DESCRIPTION--
+Iterate regular php array
+--SKIPIF--
+<?php if (!extension_loaded("extention_for_tests")) print "skip"; ?>
+--FILEEOF--
+<?php
+require dirname(__FILE__) . '/../../include/valueiterator/1.php';
+
+$arr = array('qwe' => 'qweqweqweqw',5,'asd' => '«£¥§©®°±¶⅐⅒⅓⅘⅞Ⅻↆ❄❅❆⚑⚐⌛⌚〰»', 'zxccvx' => 'sdfsecvyh6bug6yfty',);
+
+TestValueIterator\loopValue($arr);
+
+echo PHP_EOL;
+--EXPECT--
+Array/Object contains 4 items
+[qwe]=qweqweqweqw
+[0]=5
+[asd]=«£¥§©®°±¶⅐⅒⅓⅘⅞Ⅻↆ❄❅❆⚑⚐⌛⌚〰»
+[zxccvx]=sdfsecvyh6bug6yfty
+
diff --git a/tests/php/phpt/valueiterator/002.phpt b/tests/php/phpt/valueiterator/002.phpt
new file mode 100644
index 0000000..59d5dad
--- /dev/null
+++ b/tests/php/phpt/valueiterator/002.phpt
@@ -0,0 +1,22 @@
+--TEST--
+Iterate object of stdClass
+--DESCRIPTION--
+Iterate object of stdClass
+--SKIPIF--
+<?php if (!extension_loaded("extention_for_tests")) print "skip"; ?>
+--FILEEOF--
+<?php
+require dirname(__FILE__) . '/../../include/valueiterator/1.php';
+
+$arr = array('qwe' => 'qweqweqweqw',5,'asd' => '«£¥§©®°±¶⅐⅒⅓⅘⅞Ⅻↆ❄❅❆⚑⚐⌛⌚〰»', 'zxccvx' => 'sdfsecvyh6bug6yfty',);
+$obj = (object)$arr;
+
+TestValueIterator\loopValue($obj);
+
+echo PHP_EOL;
+--EXPECT--
+Array/Object contains 0 items
+[qwe]=qweqweqweqw
+[0]=5
+[asd]=«£¥§©®°±¶⅐⅒⅓⅘⅞Ⅻↆ❄❅❆⚑⚐⌛⌚〰»
+[zxccvx]=sdfsecvyh6bug6yfty \ No newline at end of file
diff --git a/tests/php/phpt/valueiterator/003.phpt b/tests/php/phpt/valueiterator/003.phpt
new file mode 100644
index 0000000..4155a2d
--- /dev/null
+++ b/tests/php/phpt/valueiterator/003.phpt
@@ -0,0 +1,18 @@
+--TEST--
+Iterate object
+--DESCRIPTION--
+Iterate regular php object
+--SKIPIF--
+<?php if (!extension_loaded("extention_for_tests")) print "skip"; ?>
+--FILEEOF--
+<?php
+require dirname(__FILE__) . '/../../include/valueiterator/1.php';
+
+$smpl = new SimpleClass;
+
+TestValueIterator\loopValue($smpl);
+
+--EXPECT--
+Array/Object contains 0 items
+[cl0_float]=3.14
+[cl0_str1]=public str1 \ No newline at end of file
diff --git a/tests/php/phpt/valueiterator/004.phpt b/tests/php/phpt/valueiterator/004.phpt
new file mode 100644
index 0000000..3e6afb7
--- /dev/null
+++ b/tests/php/phpt/valueiterator/004.phpt
@@ -0,0 +1,20 @@
+--TEST--
+Iterate itarable oblect
+--DESCRIPTION--
+class impIterator implements Iterator
+--SKIPIF--
+<?php if (!extension_loaded("extention_for_tests")) print "skip"; ?>
+--FILEEOF--
+<?php
+require dirname(__FILE__) . '/../../include/valueiterator/1.php';
+
+$it = new impIterator;
+
+TestValueIterator\loopValue($it);
+
+--EXPECT--
+Array/Object contains 0 items
+[key_0]=firstElement
+[key_1]=secondElement
+[key_2]=lastelEment
+~impIterator \ No newline at end of file
diff --git a/tests/php/phpt/valueiterator/005.phpt b/tests/php/phpt/valueiterator/005.phpt
new file mode 100644
index 0000000..e5df91e
--- /dev/null
+++ b/tests/php/phpt/valueiterator/005.phpt
@@ -0,0 +1,19 @@
+--TEST--
+Iterate itarable oblect
+--DESCRIPTION--
+class impIterAggr1 implements IteratorAggregate
+--SKIPIF--
+<?php if (!extension_loaded("extention_for_tests")) print "skip"; ?>
+--FILEEOF--
+<?php
+require dirname(__FILE__) . '/../../include/valueiterator/1.php';
+
+$iag1 = new impIterAggr1;
+
+TestValueIterator\loopValue($iag1);
+
+--EXPECT--
+Array/Object contains 0 items
+[cl0_float]=3.14
+[cl0_str1]=public str1
+~impIterAggr1 \ No newline at end of file
diff --git a/tests/php/phpt/valueiterator/006.phpt b/tests/php/phpt/valueiterator/006.phpt
new file mode 100644
index 0000000..d31cdda
--- /dev/null
+++ b/tests/php/phpt/valueiterator/006.phpt
@@ -0,0 +1,21 @@
+--TEST--
+Iterate itarable oblect
+--DESCRIPTION--
+class impIterAggr1 implements IteratorAggregate
+--SKIPIF--
+<?php if (!extension_loaded("extention_for_tests")) print "skip"; ?>
+--FILEEOF--
+<?php
+require dirname(__FILE__) . '/../../include/valueiterator/1.php';
+
+$iag2 = new impIterAggr2;
+
+TestValueIterator\loopValue($iag2);
+
+--EXPECT--
+Array/Object contains 0 items
+[key_0]=firstElement
+[key_1]=secondElement
+[key_2]=lastelEment
+~impIterAggr2
+~impIterator \ No newline at end of file
diff --git a/tests/php/phpt/valueiterator/readme b/tests/php/phpt/valueiterator/readme
new file mode 100644
index 0000000..0156308
--- /dev/null
+++ b/tests/php/phpt/valueiterator/readme
@@ -0,0 +1 @@
+Tests of basic capabilities
diff --git a/tests/php/readme b/tests/php/readme
new file mode 100644
index 0000000..15f54ec
--- /dev/null
+++ b/tests/php/readme
@@ -0,0 +1,9 @@
+The phpt documentation:
+http://qa.php.net/phpt_details.php
+
+How to Write Tests
+http://qa.php.net/write-test.php
+
+Lessons Learned from PHPT Writing
+https://wiki.php.net/qa/phptlessonslearned
+