diff options
Diffstat (limited to 'ext/spl/tests')
-rw-r--r-- | ext/spl/tests/SplFileInfo_getInode_basic.phpt | 8 | ||||
-rw-r--r-- | ext/spl/tests/SplFileInfo_getPerms_basic.phpt | 8 | ||||
-rw-r--r-- | ext/spl/tests/SplFileObject_fgetcsv_delimiter_basic.phpt | 2 | ||||
-rw-r--r-- | ext/spl/tests/SplFileObject_fgetcsv_delimiter_error.phpt | 2 | ||||
-rw-r--r-- | ext/spl/tests/SplFileObject_fgetcsv_enclosure_basic.phpt | 2 | ||||
-rw-r--r-- | ext/spl/tests/SplFileObject_fgetcsv_enclosure_error.phpt | 2 | ||||
-rw-r--r-- | ext/spl/tests/SplFileObject_fgetcsv_escape_basic.phpt | 2 | ||||
-rw-r--r-- | ext/spl/tests/SplFileObject_fgetcsv_escape_error.phpt | 2 | ||||
-rw-r--r-- | ext/spl/tests/SplFixedArray_serialize.phpt | 52 | ||||
-rw-r--r-- | ext/spl/tests/bug61828.phpt | 11 | ||||
-rw-r--r-- | ext/spl/tests/bug62672.phpt | 31 | ||||
-rw-r--r-- | ext/spl/tests/bug63680.phpt | 2 | ||||
-rw-r--r-- | ext/spl/tests/bug65328.phpt | 348 | ||||
-rw-r--r-- | ext/spl/tests/iterator_031.phpt | 2 | ||||
-rw-r--r-- | ext/spl/tests/spl_004.phpt | 6 | ||||
-rw-r--r-- | ext/spl/tests/spl_priorityqeue_insert_two_params_error.phpt | 2 |
16 files changed, 463 insertions, 19 deletions
diff --git a/ext/spl/tests/SplFileInfo_getInode_basic.phpt b/ext/spl/tests/SplFileInfo_getInode_basic.phpt index 902cbb31c..380b865cd 100644 --- a/ext/spl/tests/SplFileInfo_getInode_basic.phpt +++ b/ext/spl/tests/SplFileInfo_getInode_basic.phpt @@ -16,15 +16,15 @@ if (substr(PHP_OS, 0, 3) == 'WIN') die("skip this test not for Windows platforms <?php
//file -touch ('test_file_ptfi'); -$fileInfo = new SplFileInfo('test_file_ptfi'); -$result = shell_exec('ls -i test_file_ptfi'); +touch ('SplFileInfo_getInode_basic.txt'); +$fileInfo = new SplFileInfo('SplFileInfo_getInode_basic.txt'); +$result = shell_exec('ls -i SplFileInfo_getInode_basic.txt'); var_dump($fileInfo->getInode() == $result); ?> --CLEAN-- <?php -unlink('test_file_ptfi'); +unlink('SplFileInfo_getInode_basic.txt'); ?>
--EXPECTF--
bool(true) diff --git a/ext/spl/tests/SplFileInfo_getPerms_basic.phpt b/ext/spl/tests/SplFileInfo_getPerms_basic.phpt index e9b7beaa9..53591f341 100644 --- a/ext/spl/tests/SplFileInfo_getPerms_basic.phpt +++ b/ext/spl/tests/SplFileInfo_getPerms_basic.phpt @@ -16,15 +16,15 @@ if (substr(PHP_OS, 0, 3) == 'WIN') die("skip this test not for Windows platforms <?php
//file -touch ('test_file_ptfi'); -chmod('test_file_ptfi', 0557); -$fileInfo = new SplFileInfo('test_file_ptfi'); +touch ('SplFileInfo_getPerms_basic.txt'); +chmod('SplFileInfo_getPerms_basic.txt', 0557); +$fileInfo = new SplFileInfo('SplFileInfo_getPerms_basic.txt'); var_dump($fileInfo->getPerms() == 0100557); ?> --CLEAN-- <?php -unlink('test_file_ptfi'); +unlink('SplFileInfo_getPerms_basic.txt'); ?>
--EXPECTF--
bool(true) diff --git a/ext/spl/tests/SplFileObject_fgetcsv_delimiter_basic.phpt b/ext/spl/tests/SplFileObject_fgetcsv_delimiter_basic.phpt index 32705f091..4402d6ca4 100644 --- a/ext/spl/tests/SplFileObject_fgetcsv_delimiter_basic.phpt +++ b/ext/spl/tests/SplFileObject_fgetcsv_delimiter_basic.phpt @@ -1,5 +1,5 @@ --TEST-- -SplFileObject::fgetcsv with alternative delimeter +SplFileObject::fgetcsv with alternative delimiter --FILE-- <?php $fp = fopen('SplFileObject__fgetcsv.csv', 'w+'); diff --git a/ext/spl/tests/SplFileObject_fgetcsv_delimiter_error.phpt b/ext/spl/tests/SplFileObject_fgetcsv_delimiter_error.phpt index 942c7619d..64d6514a2 100644 --- a/ext/spl/tests/SplFileObject_fgetcsv_delimiter_error.phpt +++ b/ext/spl/tests/SplFileObject_fgetcsv_delimiter_error.phpt @@ -1,5 +1,5 @@ --TEST-- -SplFileObject::fgetcsv with alternative delimeter +SplFileObject::fgetcsv with alternative delimiter --FILE-- <?php $fp = fopen('SplFileObject__fgetcsv.csv', 'w+'); diff --git a/ext/spl/tests/SplFileObject_fgetcsv_enclosure_basic.phpt b/ext/spl/tests/SplFileObject_fgetcsv_enclosure_basic.phpt index ee2497252..efbb5fb68 100644 --- a/ext/spl/tests/SplFileObject_fgetcsv_enclosure_basic.phpt +++ b/ext/spl/tests/SplFileObject_fgetcsv_enclosure_basic.phpt @@ -1,5 +1,5 @@ --TEST-- -SplFileObject::fgetcsv with alternative delimeter +SplFileObject::fgetcsv with alternative delimiter --FILE-- <?php $fp = fopen('SplFileObject__fgetcsv.csv', 'w+'); diff --git a/ext/spl/tests/SplFileObject_fgetcsv_enclosure_error.phpt b/ext/spl/tests/SplFileObject_fgetcsv_enclosure_error.phpt index 5430e5375..7487b8353 100644 --- a/ext/spl/tests/SplFileObject_fgetcsv_enclosure_error.phpt +++ b/ext/spl/tests/SplFileObject_fgetcsv_enclosure_error.phpt @@ -1,5 +1,5 @@ --TEST-- -SplFileObject::fgetcsv with alternative delimeter +SplFileObject::fgetcsv with alternative delimiter --FILE-- <?php $fp = fopen('SplFileObject__fgetcsv.csv', 'w+'); diff --git a/ext/spl/tests/SplFileObject_fgetcsv_escape_basic.phpt b/ext/spl/tests/SplFileObject_fgetcsv_escape_basic.phpt index 96c029095..1a94532b2 100644 --- a/ext/spl/tests/SplFileObject_fgetcsv_escape_basic.phpt +++ b/ext/spl/tests/SplFileObject_fgetcsv_escape_basic.phpt @@ -1,5 +1,5 @@ --TEST-- -SplFileObject::fgetcsv with alternative delimeter +SplFileObject::fgetcsv with alternative delimiter --FILE-- <?php $fp = fopen('SplFileObject__fgetcsv.csv', 'w+'); diff --git a/ext/spl/tests/SplFileObject_fgetcsv_escape_error.phpt b/ext/spl/tests/SplFileObject_fgetcsv_escape_error.phpt index a57031899..fd90103bf 100644 --- a/ext/spl/tests/SplFileObject_fgetcsv_escape_error.phpt +++ b/ext/spl/tests/SplFileObject_fgetcsv_escape_error.phpt @@ -1,5 +1,5 @@ --TEST-- -SplFileObject::fgetcsv with alternative delimeter +SplFileObject::fgetcsv with alternative delimiter --FILE-- <?php $fp = fopen('SplFileObject__fgetcsv.csv', 'w+'); diff --git a/ext/spl/tests/SplFixedArray_serialize.phpt b/ext/spl/tests/SplFixedArray_serialize.phpt new file mode 100644 index 000000000..f99812ecc --- /dev/null +++ b/ext/spl/tests/SplFixedArray_serialize.phpt @@ -0,0 +1,52 @@ +--TEST-- +SplFixedArray serialisation +--FILE-- +<?php + +$array = new SplFixedArray(5); + +$obj = new stdClass; +$obj->prop = 'value'; + +$array[0] = 'foo'; +$array[2] = 42; +$array[3] = $obj; +$array[4] = range(1, 5); + +$ser = serialize($array); +echo "$ser\n"; +$unser = unserialize($ser); + +printf("count: %d\n", count($unser)); +printf("getSize(): %d\n", $unser->getSize()); + +var_dump($unser[0], $unser[1], $unser[2], $unser[3], $unser[4]); + +$unser[4] = 'quux'; +var_dump($unser[4]); + +?> +--EXPECT-- +O:13:"SplFixedArray":5:{i:0;s:3:"foo";i:1;N;i:2;i:42;i:3;O:8:"stdClass":1:{s:4:"prop";s:5:"value";}i:4;a:5:{i:0;i:1;i:1;i:2;i:2;i:3;i:3;i:4;i:4;i:5;}} +count: 5 +getSize(): 5 +string(3) "foo" +NULL +int(42) +object(stdClass)#4 (1) { + ["prop"]=> + string(5) "value" +} +array(5) { + [0]=> + int(1) + [1]=> + int(2) + [2]=> + int(3) + [3]=> + int(4) + [4]=> + int(5) +} +string(4) "quux" diff --git a/ext/spl/tests/bug61828.phpt b/ext/spl/tests/bug61828.phpt new file mode 100644 index 000000000..04d435e6d --- /dev/null +++ b/ext/spl/tests/bug61828.phpt @@ -0,0 +1,11 @@ +--TEST-- +Bug #61828 (Memleak when calling Directory(Recursive)Iterator/Spl(Temp)FileObject ctor twice) +--FILE-- +<?php +$x = new DirectoryIterator('.'); +$x->__construct('/tmp'); +echo "Okey"; +?> +--EXPECTF-- +Warning: DirectoryIterator::__construct(): Directory object is already initialized in %sbug61828.php on line 3 +Okey diff --git a/ext/spl/tests/bug62672.phpt b/ext/spl/tests/bug62672.phpt new file mode 100644 index 000000000..d0d6a6245 --- /dev/null +++ b/ext/spl/tests/bug62672.phpt @@ -0,0 +1,31 @@ +--TEST-- +Bug #62672 (Error on serialize of ArrayObject) +--FILE-- +<?php + +class ObjA +{ + private $_varA; + + public function __construct(Iterator $source) + { + $this->_varA = $source; + } +} + +class ObjB extends ObjA +{ + private $_varB; + + public function __construct(ArrayObject $keys) + { + $this->_varB = $keys; + parent::__construct($keys->getIterator()); + } +} + +$obj = new ObjB(new ArrayObject()); + +var_dump($obj == unserialize(serialize($obj))); +--EXPECTF-- +bool(true) diff --git a/ext/spl/tests/bug63680.phpt b/ext/spl/tests/bug63680.phpt index 3a20c4bb1..0b5c35dc7 100644 --- a/ext/spl/tests/bug63680.phpt +++ b/ext/spl/tests/bug63680.phpt @@ -1,5 +1,7 @@ --TEST-- Bug #63680 (Memleak in splfixedarray with cycle reference) +--INI-- +zend.enable_gc=1 --FILE-- <?php function dummy() { diff --git a/ext/spl/tests/bug65328.phpt b/ext/spl/tests/bug65328.phpt new file mode 100644 index 000000000..32e6c24fa --- /dev/null +++ b/ext/spl/tests/bug65328.phpt @@ -0,0 +1,348 @@ +--TEST-- +Bug #65328 (Segfault when getting SplStack object Value) +--FILE-- +<?php +/** + * @author AlexanderC + */ + +class Tree +{ + /** + * @var Node + */ + protected $head; + + /** + * @param Node $head + */ + public function __construct(Node $head = null) + { + $this->head = $head ? : new Node('HEAD'); + } + + /** + * @return Node + */ + public function getHead() + { + return $this->head; + } + + /** + * @param mixed $uid + * @return Node|bool + */ + public function find($uid) + { + $iterator = $this->getIterator(); + + /** @var Node $node */ + foreach($iterator as $node) { + if($node->getUid() === $uid) { + return $node; + } + } + + return false; + } + + /** + * @param mixed $uid + * @return \SplStack + */ + public function & findAll($uid) + { + $result = new \SplStack(); + + /** @var Node $node */ + foreach($this->getIterator() as $node) { + if($node->getUid() == $uid) { + $result->push($node); + } + } + + return $result; + } + + /** + * @return \RecursiveIteratorIterator + */ + public function getIterator() + { + return new \RecursiveIteratorIterator( + $this->head->getChildren(), + \RecursiveIteratorIterator::SELF_FIRST + ); + } +} + +class Node extends \RecursiveArrayIterator implements \Countable +{ + /** + * @var array + */ + protected $children = []; + + /** + * @var Node + */ + protected $parent; + + /** + * @var mixed + */ + protected $data; + + /** + * @var mixed + */ + protected $uid; + + /** + * @var int + */ + protected $index = 0; + + /** + * @var bool + */ + protected $assureUnique; + + /** + * @param mixed $data + * @param mixed $uid + * @param Node $parent + * @param bool $assureUnique + */ + public function __construct($data, $uid = null, Node $parent = null, $assureUnique = false) + { + if(null !== $parent) { + $this->parent = $parent; + } + + $this->data = $data; + $this->uid = $uid ? : uniqid(sha1(serialize($data)), true); + $this->assureUnique = $assureUnique; + } + + /** + * @param mixed $uid + */ + public function setUid($uid) + { + $this->uid = $uid; + } + + /** + * @return mixed + */ + public function getUid() + { + return $this->uid; + } + + /** + * @param Node $child + */ + public function addChild(Node $child) + { + $child->setParent($this); + $this->children[] = $child; + } + + /** + * @param array $children + */ + public function setChildren(array $children) + { + $this->children = $children; + } + + /** + * @return array + */ + public function getChildrenArray() + { + return $this->children; + } + + /** + * @param mixed $data + */ + public function setData($data) + { + $this->data = $data; + } + + /** + * @return mixed + */ + public function getData() + { + return $this->data; + } + + /** + * @param Node $parent + * @throws \RuntimeException + */ + public function setParent(Node $parent) + { + if(true === $this->assureUnique && !self::checkUnique($parent, $this->uid)) { + throw new \RuntimeException("Node uid is not unique in assigned node tree"); + } + + $this->parent = $parent; + } + + /** + * @param Node $node + * @param mixed $uid + * @return bool + */ + protected static function checkUnique(Node $node, $uid) + { + $headNode = $node; + do { + $headNode = $node; + } while($node = $node->getParent()); + + $tree = new Tree($headNode); + + return !$tree->find($uid); + } + + /** + * @return \IJsonRPC\Helpers\Tree\Node + */ + public function getParent() + { + return $this->parent; + } + + /** + * @return Node + */ + public function current() + { + return $this->children[$this->index]; + } + + /** + * @return scalar + */ + public function key() + { + return $this->index; + } + + /** + * @return void + */ + public function next() + { + ++$this->index; + } + + /** + * @return void + */ + public function rewind() + { + $this->index = 0; + } + + /** + * @return bool + */ + public function valid() + { + return array_key_exists($this->index, $this->children); + } + + /** + * @return int + */ + public function count() + { + return count($this->children); + } + + /** + * @return bool + */ + public function hasChildren() + { + return !empty($this->children); + } + + /** + * @return \RecursiveArrayIterator + */ + public function getChildren() + { + return new \RecursiveArrayIterator($this->children); + } +} + +$tree = new Tree(); +$node1 = new Node('value1', 1); +$tree->getHead()->addChild($node1); +$node2 = new Node('value2', 2); +$node1->addChild($node2); + +print_r($tree->findAll(2)->offsetGet(0)); +--EXPECTF-- +Node Object +( + [children:protected] => Array + ( + ) + + [parent:protected] => Node Object + ( + [children:protected] => Array + ( + [0] => Node Object + *RECURSION* + ) + + [parent:protected] => Node Object + ( + [children:protected] => Array + ( + [0] => Node Object + *RECURSION* + ) + + [parent:protected] => + [data:protected] => HEAD + [uid:protected] => %s + [index:protected] => 0 + [assureUnique:protected] => + [storage:ArrayIterator:private] => Array + ( + ) + + ) + + [data:protected] => value1 + [uid:protected] => 1 + [index:protected] => 1 + [assureUnique:protected] => + [storage:ArrayIterator:private] => Array + ( + ) + + ) + + [data:protected] => value2 + [uid:protected] => 2 + [index:protected] => 0 + [assureUnique:protected] => + [storage:ArrayIterator:private] => Array + ( + ) + +) diff --git a/ext/spl/tests/iterator_031.phpt b/ext/spl/tests/iterator_031.phpt index 40342f4bb..8bd3ca7c5 100644 --- a/ext/spl/tests/iterator_031.phpt +++ b/ext/spl/tests/iterator_031.phpt @@ -1,5 +1,5 @@ --TEST-- -SPL: AppendIterator::append() rewinds when neccessary +SPL: AppendIterator::append() rewinds when necessary --FILE-- <?php diff --git a/ext/spl/tests/spl_004.phpt b/ext/spl/tests/spl_004.phpt index 97896f815..d56f48f89 100644 --- a/ext/spl/tests/spl_004.phpt +++ b/ext/spl/tests/spl_004.phpt @@ -43,8 +43,8 @@ var_dump(iterator_apply($it, 'test')); echo "===ERRORS===\n"; var_dump(iterator_apply($it, 'test', 1)); -var_dump(iterator_apply($it, 'non_existing_functon')); -var_dump(iterator_apply($it, 'non_existing_functon', NULL, 2)); +var_dump(iterator_apply($it, 'non_existing_function')); +var_dump(iterator_apply($it, 'non_existing_function', NULL, 2)); ?> ===DONE=== @@ -77,7 +77,7 @@ int(4) Error: Argument 3 passed to iterator_apply() must be of the type array, integer given Error: iterator_apply() expects parameter 3 to be array, integer given NULL -Error: iterator_apply() expects parameter 2 to be a valid callback, function 'non_existing_functon' not found or invalid function name +Error: iterator_apply() expects parameter 2 to be a valid callback, function 'non_existing_function' not found or invalid function name NULL Error: iterator_apply() expects at most 3 parameters, 4 given NULL diff --git a/ext/spl/tests/spl_priorityqeue_insert_two_params_error.phpt b/ext/spl/tests/spl_priorityqeue_insert_two_params_error.phpt index 659ffb4bc..076c68771 100644 --- a/ext/spl/tests/spl_priorityqeue_insert_two_params_error.phpt +++ b/ext/spl/tests/spl_priorityqeue_insert_two_params_error.phpt @@ -1,5 +1,5 @@ --TEST-- -SPL: priorityQueue paramter test on insert method +SPL: priorityQueue parameter test on insert method --CREDITS-- Sean Burlington www.practicalweb.co.uk TestFest London May 2009 |