xref: /PHP-5.4/ext/spl/tests/fileobject_003.phpt (revision 610c7fbe)
1--TEST--
2SPL: SplFileInfo cloning
3--FILE--
4<?php
5
6function test($name, $lc, $lp)
7{
8	static $i = 0;
9	echo "===$i===\n";
10	$i++;
11
12	$o = new SplFileInfo($name);
13
14	var_dump($o);
15	$c = clone $o;
16	var_dump($c);
17	var_dump($o === $c);
18	var_dump($o == $c);
19	var_dump($o->getPathname() == $c->getPathname());
20
21	try {
22		$f = new SplFileObject($name);
23		var_dump($name);
24		var_dump($f->getPathName());
25		$l = substr($f->getPathName(), -1);
26		var_dump($l != '/' && $l != '\\' && $l == $lc);
27		var_dump($f->getFileName());
28		$l = substr($f->getFileName(), -1);
29		var_dump($l != '/' && $l != '\\' && $l == $lc);
30		var_dump($f->getPath());
31		$l = substr($f->getPath(), -1);
32		var_dump($l != '/' && $l != '\\' && $l == $lp);
33	} catch (LogicException $e) {
34		echo "LogicException: ".$e->getMessage()."\n";
35	}
36	try {
37		$fo = $o->openFile();
38		var_dump($fo->getPathName(), $fo->getFileName(), $fo->getPath());
39	} catch (LogicException $e) {
40		echo "LogicException: ".$e->getMessage()."\n";
41	}
42}
43
44test(dirname(__FILE__) . '/' . 'fileobject_001a.txt', 't', substr(dirname(__FILE__),-1));
45test(dirname(__FILE__) . '/', substr(dirname(__FILE__),-1), 'l');
46test(dirname(__FILE__),       substr(dirname(__FILE__),-1), 'l');
47
48?>
49===DONE===
50<?php exit(0); ?>
51--EXPECTF--
52===0===
53object(SplFileInfo)#%d (2) {
54  ["pathName":"SplFileInfo":private]=>
55  string(%d) "%s"
56  ["fileName":"SplFileInfo":private]=>
57  string(%d) "fileobject_001a.txt"
58}
59object(SplFileInfo)#%d (2) {
60  ["pathName":"SplFileInfo":private]=>
61  string(%d) "%s"
62  ["fileName":"SplFileInfo":private]=>
63  string(%d) "fileobject_001a.txt"
64}
65bool(false)
66bool(true)
67bool(true)
68%s(%d) "%sfileobject_001a.txt"
69string(%d) "%sfileobject_001a.txt"
70bool(true)
71string(19) "fileobject_001a.txt"
72bool(true)
73string(%d) "%stests"
74bool(true)
75string(%d) "%sfileobject_001a.txt"
76string(19) "fileobject_001a.txt"
77string(%d) "%stests"
78===1===
79object(SplFileInfo)#%d (2) {
80  ["pathName":"SplFileInfo":private]=>
81  string(%d) "%s"
82  ["fileName":"SplFileInfo":private]=>
83  string(%d) "%s"
84}
85object(SplFileInfo)#%d (2) {
86  ["pathName":"SplFileInfo":private]=>
87  string(%d) "%s"
88  ["fileName":"SplFileInfo":private]=>
89  string(%d) "%s"
90}
91bool(false)
92bool(true)
93bool(true)
94LogicException: Cannot use SplFileObject with directories
95LogicException: Cannot use SplFileObject with directories
96===2===
97object(SplFileInfo)#%d (2) {
98  ["pathName":"SplFileInfo":private]=>
99  string(%d) "%s"
100  ["fileName":"SplFileInfo":private]=>
101  string(%d) "%s"
102}
103object(SplFileInfo)#%d (2) {
104  ["pathName":"SplFileInfo":private]=>
105  string(%d) "%s"
106  ["fileName":"SplFileInfo":private]=>
107  string(%d) "%s"
108}
109bool(false)
110bool(true)
111bool(true)
112LogicException: Cannot use SplFileObject with directories
113LogicException: Cannot use SplFileObject with directories
114===DONE===
115