diff options
author | Emiel Bruijntjes <emiel.bruijntjes@copernica.com> | 2014-03-18 23:35:35 +0100 |
---|---|---|
committer | Emiel Bruijntjes <emiel.bruijntjes@copernica.com> | 2014-03-18 23:35:35 +0100 |
commit | 778561e1739a4a7ef20e85b713b4790e6be225d3 (patch) | |
tree | d1ff42f6b6f8d6aa68f88319506aba91394aded0 /tests/php | |
parent | bfaed88493de0a3ebd7f2619cb11291cd09252b1 (diff) | |
parent | da5521c2c168edc48e7d2b5dd12305c9dec85b7b (diff) |
Merge pull request #44 from valmat/unit-test
Unit tests
Diffstat (limited to 'tests/php')
-rw-r--r-- | tests/php/dbg.php | 58 | ||||
-rw-r--r-- | tests/php/include/valueiterator/1.php | 76 | ||||
-rwxr-xr-x | tests/php/php_alias.sh | 16 | ||||
-rw-r--r-- | tests/php/phpt/.gitignore | 6 | ||||
-rw-r--r-- | tests/php/phpt/base/001.phpt | 14 | ||||
-rw-r--r-- | tests/php/phpt/base/002.phpt | 14 | ||||
-rw-r--r-- | tests/php/phpt/base/readme | 1 | ||||
-rw-r--r-- | tests/php/phpt/valueiterator/001.phpt | 22 | ||||
-rw-r--r-- | tests/php/phpt/valueiterator/002.phpt | 22 | ||||
-rw-r--r-- | tests/php/phpt/valueiterator/003.phpt | 18 | ||||
-rw-r--r-- | tests/php/phpt/valueiterator/004.phpt | 20 | ||||
-rw-r--r-- | tests/php/phpt/valueiterator/005.phpt | 19 | ||||
-rw-r--r-- | tests/php/phpt/valueiterator/006.phpt | 21 | ||||
-rw-r--r-- | tests/php/phpt/valueiterator/readme | 1 | ||||
-rw-r--r-- | tests/php/readme | 9 |
15 files changed, 317 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/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 + |