@@ -18,14 +18,20 @@ Subject: Fix tests
1818 is not documented and should be probably resolved in a system-agnostic
1919 way at some point. On Solaris 11.4 unlink() works as expected,
2020 otherwise.
21+
22+ Added helper function to get relative path to fix some tests as they
23+ are creating directories and files all over the place on the system,
24+ when test fails.
2125---
22- ext/dom/tests/dom_xinclude.phpt | 4 ++--
23- ext/standard/tests/file/copy_variation4.phpt | 12 +++++++++---
24- ext/zip/tests/gh18431.phpt | 4 ++++
25- ext/zip/tests/oo_addemptydir_error.phpt | 2 +-
26- ext/zip/tests/oo_addglob2.phpt | 6 ++++++
27- ext/zip/tests/oo_encryption.phpt | 6 ++++++
28- 6 files changed, 28 insertions(+), 6 deletions(-)
26+ ext/dom/tests/dom_xinclude.phpt | 4 ++--
27+ ext/standard/tests/file/copy_variation4.phpt | 12 ++++++++---
28+ ext/standard/tests/file/file.inc | 21 +++++++++++++++++++
29+ .../tests/file/unlink_variation10.phpt | 12 ++++++++---
30+ ext/zip/tests/gh18431.phpt | 4 ++++
31+ ext/zip/tests/oo_addemptydir_error.phpt | 2 +-
32+ ext/zip/tests/oo_addglob2.phpt | 6 ++++++
33+ ext/zip/tests/oo_encryption.phpt | 6 ++++++
34+ 8 files changed, 58 insertions(+), 9 deletions(-)
2935
3036diff --git a/ext/dom/tests/dom_xinclude.phpt b/ext/dom/tests/dom_xinclude.phpt
3137index 0dfeb2dfb4a..410431de877 100644
@@ -67,6 +73,64 @@ index d467cb4ce9a..f31a1ddb117 100644
6773 --FILE--
6874 <?php
6975 /* Test copy() function: In creation of destination file names with empty string, nulls & bools
76+ diff --git a/ext/standard/tests/file/file.inc b/ext/standard/tests/file/file.inc
77+ index c972784f9da..c7665d2846d 100644
78+ --- a/ext/standard/tests/file/file.inc
79+ +++ b/ext/standard/tests/file/file.inc
80+ @@ -654,4 +654,25 @@ function compare_stats($stat1, $stat2, $fields, $op = "==", $flag = false ) {
81+ return $result;
82+ }
83+
84+ + /**
85+ + * Get a relative path.
86+ + */
87+ + function relativePath($from, $to)
88+ + {
89+ + $from = str_replace(['/', '\\'], DIRECTORY_SEPARATOR, $from);
90+ + $to = str_replace(['/', '\\'], DIRECTORY_SEPARATOR, $to);
91+ +
92+ + $fromArray = explode(DIRECTORY_SEPARATOR, rtrim($from, DIRECTORY_SEPARATOR));
93+ + $toArray = explode(DIRECTORY_SEPARATOR, rtrim($to, DIRECTORY_SEPARATOR));
94+ +
95+ + while (count($fromArray) && count($toArray) && ($fromArray[0] == $toArray[0])) {
96+ + array_shift($fromArray);
97+ + array_shift($toArray);
98+ + }
99+ +
100+ + $relativePath = str_pad('', count($fromArray) * 3, '..' . DIRECTORY_SEPARATOR) . implode(DIRECTORY_SEPARATOR, $toArray);
101+ +
102+ + return ($relativePath === '') ? '.' : $relativePath;
103+ + }
104+ +
105+ ?>
106+ diff --git a/ext/standard/tests/file/unlink_variation10.phpt b/ext/standard/tests/file/unlink_variation10.phpt
107+ index 127b070d23a..a3355a99560 100644
108+ --- a/ext/standard/tests/file/unlink_variation10.phpt
109+ +++ b/ext/standard/tests/file/unlink_variation10.phpt
110+ @@ -10,14 +10,20 @@
111+ ?>
112+ --FILE--
113+ <?php
114+ +
115+ + // include the file.inc for function relativePath().
116+ + include(__DIR__ . '/file.inc');
117+ +
118+ echo "*** Testing unlink() : variation ***\n";
119+
120+ - $workDir = "unlinkVar10.tmp";
121+ - $tmpDir = "subDir.tmp";
122+ + $cwd = getcwd();
123+ + $relativePath = relativePath($cwd, __DIR__);
124+ +
125+ + $workDir = $relativePath . '/unlinkVar10.tmp';
126+ + $tmpDir = $relativePath . '/subDir.tmp';
127+ $dirToLinkTo = $workDir.'/'."linkme.tmp";
128+
129+ mkdir($workDir);
130+ - $cwd = getcwd();
131+ mkdir($dirToLinkTo);
132+
133+ $dirs = array(
70134diff --git a/ext/zip/tests/gh18431.phpt b/ext/zip/tests/gh18431.phpt
71135index d4eb89c36c6..dcd7db6f400 100644
72136--- a/ext/zip/tests/gh18431.phpt
0 commit comments