]> granicus.if.org Git - php/commitdiff
Fix some tests and improve coverage for Windows in SPL
authorKalle Sommer Nielsen <kalle@php.net>
Sun, 30 Sep 2018 08:41:34 +0000 (10:41 +0200)
committerKalle Sommer Nielsen <kalle@php.net>
Sun, 30 Sep 2018 08:41:34 +0000 (10:41 +0200)
ext/spl/tests/DirectoryIterator_getExtension_basic.phpt
ext/spl/tests/DirectoryIterator_getGroup_basic.phpt
ext/spl/tests/DirectoryIterator_getInode_basic.phpt
ext/spl/tests/DirectoryIterator_getInode_error.phpt
ext/spl/tests/DirectoryIterator_getOwner_basic.phpt
ext/spl/tests/bug68825.phpt
ext/spl/tests/fileobject_001.phpt
ext/spl/tests/fileobject_002.phpt

index a35a524f359029c112b2a7694f017fb4067577ab..e356e2a017583afea65dc413288c344b82f6dce9 100644 (file)
@@ -1,29 +1,26 @@
 --TEST--
 SPL: DirectoryIterator::getExtension() basic test
---SKIPIF--
-<?php
-if (substr(PHP_OS, 0, 3) == 'WIN') {
-    die('skip.. only for Unix');
-}
-?>
 --FILE--
 <?php
 $dir = __DIR__ . DIRECTORY_SEPARATOR . md5('DirectoryIterator::getExtension') . DIRECTORY_SEPARATOR;
-mkdir($dir);
 
-$files = array('test.txt', 'test.extension', 'test..', 'test.', 'test');
+if (!mkdir($dir)) {
+    die('Failed to create test directory');
+}
+
+$files = array('test.txt', 'test.extension', 'test');
 foreach ($files as $file) {
     touch($dir . $file);
 }
 
 $dit_exts = array();
 $nfo_exts = array();
-$skip = array('.', '..');
 
 foreach (new DirectoryIterator($dir) as $file) {
-    if (in_array($file->getFilename(), $skip)) {
+    if ($file->isDot()) {
         continue;
     }
+
     $dit_exts[] = $file->getExtension();
     $nfo_exts[] = pathinfo($file->getFilename(), PATHINFO_EXTENSION);
 }
@@ -34,7 +31,7 @@ var_dump($dit_exts);
 --CLEAN--
 <?php
 $dir   = __DIR__ . DIRECTORY_SEPARATOR . md5('DirectoryIterator::getExtension') . DIRECTORY_SEPARATOR;
-$files = array('test.txt', 'test.extension', 'test..', 'test.', 'test');
+$files = array('test.txt', 'test.extension', 'test');
 foreach ($files as $file) {
     unlink($dir . $file);
 }
@@ -42,16 +39,12 @@ rmdir($dir);
 ?>
 --EXPECT--
 bool(true)
-array(5) {
+array(3) {
   [0]=>
   string(0) ""
   [1]=>
-  string(0) ""
-  [2]=>
-  string(0) ""
-  [3]=>
   string(9) "extension"
-  [4]=>
+  [2]=>
   string(3) "txt"
 }
 
index 81ab6c09216285eefb4777d31cd358e75a32e38d..74586b7e0f608760b0f01ea75d816e73603a6535 100644 (file)
@@ -2,7 +2,8 @@
 SPL: DirectoryIterator test getGroup
 --SKIPIF--
 <?php
-if (posix_geteuid() == 0) die('SKIP Cannot run test as root.');
+if (PHP_OS_FAMILY === 'Windows') { die('SKIP Testing file groups, not available for Windows'); }
+if (!extension_loaded('posix') || posix_geteuid() == 0) { die('SKIP Cannot run test as root.'); }
 --CREDITS--
 Cesare D'Amico <cesare.damico@gruppovolta.it>
 Andrea Giorgini <agiorg@gmail.com>
index a6b128a222739db842e658d72dbbceb9e822680a..95d20881bcfe6da9087aa0be275101330f308a32 100644 (file)
@@ -10,7 +10,7 @@ Jacopo Romei <jacopo@sviluppoagile.it>
 #Test Fest Cesena (Italy) on 2009-06-20
 --SKIPIF--
 <?php
-if (substr(PHP_OS, 0, 3) == 'WIN') die("skip this test not for Windows platforms");
+if (PHP_OS_FAMILY === 'Windows') { die('SKIP Testing file inodes, not available for Windows'); }
 ?>
 --FILE--
 <?php
index 570bb21fda12bfa9960fd1d2d7cf6e8176711498..b6a07f6be9b93e020bf0f869d3b090937a54424e 100644 (file)
@@ -10,7 +10,7 @@ Jacopo Romei <jacopo@sviluppoagile.it>
 #Test Fest Cesena (Italy) on 2009-06-20
 --SKIPIF--
 <?php
-if (substr(PHP_OS, 0, 3) == 'WIN') die("skip this test not for Windows platforms");
+if (PHP_OS_FAMILY === 'Windows') { die('SKIP Testing file inodes, not available for Windows'); }
 ?>
 --FILE--
 <?php
index 709510d7cf691b511adfe999bcf28cbe5e9d7190..0981a7d28686ef82c8c7df391b05cecdf43192a8 100644 (file)
@@ -2,7 +2,8 @@
 SPL: DirectoryIterator test getOwner
 --SKIPIF--
 <?php
-if (posix_geteuid() == 0) die('SKIP Cannot run test as root.');
+if (PHP_OS_FAMILY === 'Windows') { die('SKIP Testing file ownership, not available for Windows'); }
+if (!extension_loaded('posix') || posix_geteuid() == 0) die('SKIP Cannot run test as root.');
 --CREDITS--
 Cesare D'Amico <cesare.damico@gruppovolta.it>
 Andrea Giorgini <agiorg@gmail.com>
index b1ed5fb60f42a4a3f9acd28f07177eaed322d0e1..6bc03cb73476c806614c45fa177bce777b95884b 100644 (file)
@@ -3,12 +3,16 @@ Bug #68825 (Exception in DirectoryIterator::getLinkTarget())
 --FILE--
 <?php
 $dir = __DIR__ . '/bug68825';
-mkdir($dir);
-symlink(__FILE__, "$dir/foo");
+
+if (!mkdir($dir)) {
+    die('Failed to create temporary directory for testing');
+} else if (!symlink(__FILE__, $dir . '/bug.phpt')) {
+    die('Failed to create symbolic link');
+}
 
 $di = new \DirectoryIterator($dir);
 foreach ($di as $entry) {
-    if ('foo' === $entry->getFilename()) {
+    if ('bug' === $entry->getFilename()) {
         var_dump($entry->getLinkTarget());
     }
 }
@@ -20,6 +24,6 @@ string(%d) "%s%eext%espl%etests%ebug68825.php"
 --CLEAN--
 <?php
 $dir = __DIR__ . '/bug68825';
-unlink("$dir/foo");
+unlink($dir . '/bug.phpt');
 rmdir($dir);
 ?>
index 61f688d79f0d73aab77a8ac8d45fc4df1784fc5e..35a5156401111d1b48ec3d5063211ca91ca0ac86 100644 (file)
@@ -40,12 +40,12 @@ foreach($o as $n => $l)
 
 ?>
 ===DONE===
---EXPECT--
+--EXPECTF--
 int(0)
-string(2) "0
+string(%d) "0
 "
 int(0)
-string(2) "0
+string(%d) "0
 "
 int(0)
 int(1)
index 8031e98fdcc9b34545d804637f6bed086b692314..1f7e4eaf14f3267e5a5313a6f68868139feafbbb 100644 (file)
@@ -12,6 +12,10 @@ function test($name)
        var_dump($o->key());
        while(($c = $o->fgetc()) !== false)
        {
+        // Kinda ugly but works around new lines mess
+        if ($c === "\r") {
+            continue;
+        }
                var_dump($o->key(), $c, $o->eof());
        }
        echo "===EOF?===\n";