From b709145efac49d6302cb8ce5215636eda38c451e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jan=20Kucha=C5=99?= Date: Wed, 27 Apr 2016 18:29:23 +0200 Subject: [PATCH 1/5] curl driver: better error message --- src/Driver/CurlDriver.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Driver/CurlDriver.php b/src/Driver/CurlDriver.php index 4d0360b..4e79528 100644 --- a/src/Driver/CurlDriver.php +++ b/src/Driver/CurlDriver.php @@ -29,6 +29,6 @@ public function getFileSize($path) if ($data !== false && preg_match('/Content-Length: (\d+)/', $data, $matches)) { return BigInteger::of($matches[1]); } - throw new Exception("Curl haven't returned file size."); + throw new Exception("Curl haven't returned file size. File probably does not exist."); } } From 3981080b0223a75663ca4102b4b71ef8a50ab213 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jan=20Kucha=C5=99?= Date: Wed, 27 Apr 2016 19:08:52 +0200 Subject: [PATCH 2/5] tests: file name with UTF-8 --- tests/BigFileTools/Driver/BaseDriverTest.php | 8 ++++++++ tests/php-windows.ini | 1 + tests/setup-linux.sh | 1 + tests/setup-osx.sh | 1 + tests/setup.cmd | 7 ++++++- 5 files changed, 17 insertions(+), 1 deletion(-) diff --git a/tests/BigFileTools/Driver/BaseDriverTest.php b/tests/BigFileTools/Driver/BaseDriverTest.php index ba49c82..41bc9c4 100644 --- a/tests/BigFileTools/Driver/BaseDriverTest.php +++ b/tests/BigFileTools/Driver/BaseDriverTest.php @@ -50,6 +50,14 @@ public function testFileEmptyWithSpace() { ); } + public function testFileEmptyWithUtf8InName() { + Assert::equal( + TESTS_EMPTY_FILE_SIZE, + (string) $this->driver->getFileSize(TESTS_EMPTY_FILE_WITH_UTF8_PATH), + "Driver " . get_class($this->getDriver()) . "Failed for file empty file with UTF-8 characters in name." + ); + } + public function testFileSmall_Under2_31bites() { Assert::equal( TESTS_SMALL_FILE_SIZE, diff --git a/tests/php-windows.ini b/tests/php-windows.ini index cac1837..d6a2ff4 100644 --- a/tests/php-windows.ini +++ b/tests/php-windows.ini @@ -6,6 +6,7 @@ extension_dir = "./ext" extension=php_com_dotnet.dll ; for testing CURL driver +extension=php_mbstring.dll extension=php_curl.dll date.timezone = "Europe/Prague" diff --git a/tests/setup-linux.sh b/tests/setup-linux.sh index d7d8634..36489ce 100644 --- a/tests/setup-linux.sh +++ b/tests/setup-linux.sh @@ -8,6 +8,7 @@ bash tests/cleanup.sh touch tests/temp/emptyfile.tmp touch "tests/temp/empty - file.tmp" +touch "tests/temp/emptyfileěšů指事字.tmp" truncate -s 1M tests/temp/smallfile.tmp truncate -s 2050M tests/temp/mediumfile.tmp truncate -s 4100M tests/temp/bigfile.tmp diff --git a/tests/setup-osx.sh b/tests/setup-osx.sh index fdead43..bc419be 100644 --- a/tests/setup-osx.sh +++ b/tests/setup-osx.sh @@ -8,6 +8,7 @@ bash tests/cleanup.sh touch tests/temp/emptyfile.tmp touch "tests/temp/empty - file.tmp" +touch "tests/temp/emptyfileěšů指事字.tmp" gtruncate -s 1M tests/temp/smallfile.tmp gtruncate -s 2050M tests/temp/mediumfile.tmp gtruncate -s 4100M tests/temp/bigfile.tmp diff --git a/tests/setup.cmd b/tests/setup.cmd index c3b725b..2a0f911 100644 --- a/tests/setup.cmd +++ b/tests/setup.cmd @@ -1,7 +1,12 @@ -rem http://stackoverflow.com/a/986041/631369 call tests\cleanup.cmd + +rem UTF-8 support: http://stackoverflow.com/a/18088002/631369 +chcp 65001 + +rem http://stackoverflow.com/a/986041/631369 fsutil file createnew tests\temp\emptyfile.tmp 0 fsutil file createnew "tests\temp\empty - file.tmp" 0 +fsutil file createnew "tests\temp\emptyfileěšů指事字.tmp" 0 fsutil file createnew tests\temp\smallfile.tmp 1048576 fsutil file createnew tests\temp\mediumfile.tmp 2149580800 fsutil file createnew tests\temp\bigfile.tmp 4299161600 From cdc99fa020efb317fed5cc61eee1e55c2dd1fe15 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jan=20Kucha=C5=99?= Date: Wed, 27 Apr 2016 19:09:17 +0200 Subject: [PATCH 3/5] com driver: added utf-8 support --- src/Driver/ComDriver.php | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/Driver/ComDriver.php b/src/Driver/ComDriver.php index 696c675..0ed9bfb 100644 --- a/src/Driver/ComDriver.php +++ b/src/Driver/ComDriver.php @@ -21,9 +21,10 @@ public function __construct() public function getFileSize($path) { // Use the Windows COM interface - $fsobj = new \COM('Scripting.FileSystemObject'); - if (dirname($path) == '.') - $this->path = ((substr(getcwd(), -1) == DIRECTORY_SEPARATOR) ? getcwd() . basename($path) : getcwd() . DIRECTORY_SEPARATOR . basename($path)); + $fsobj = new \COM('Scripting.FileSystemObject', null, CP_UTF8); + if (dirname($path) == '.') { + $path = ((substr(getcwd(), -1) == DIRECTORY_SEPARATOR) ? getcwd() . basename($path) : getcwd() . DIRECTORY_SEPARATOR . basename($path)); + } $f = $fsobj->GetFile($path); return BigInteger::of($f->Size); } From 911bc32990aba2c94368db57d21910c7571ca897 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jan=20Kucha=C5=99?= Date: Wed, 27 Apr 2016 19:45:47 +0200 Subject: [PATCH 4/5] skipped utf-8 related tests on Windows version of PHP which does not support UTF-8 filenames --- tests/BigFileTools/Driver/CurlDriverTest.phpt | 10 ++++++++++ tests/BigFileTools/Driver/ExecDriverTest.phpt | 11 +++++++++++ tests/BigFileTools/Driver/NativeReadDriverTest.phpt | 11 +++++++++++ tests/BigFileTools/Driver/NativeSeekDriverTest.phpt | 10 ++++++++++ tests/bootstrap.php | 4 ++++ 5 files changed, 46 insertions(+) diff --git a/tests/BigFileTools/Driver/CurlDriverTest.phpt b/tests/BigFileTools/Driver/CurlDriverTest.phpt index 929a0fa..7ff3d2e 100644 --- a/tests/BigFileTools/Driver/CurlDriverTest.phpt +++ b/tests/BigFileTools/Driver/CurlDriverTest.phpt @@ -7,6 +7,8 @@ namespace BigFileTools\Driver; +use Tester\Environment; + $container = require __DIR__ . "/../../bootstrap.php"; class CurlDriverTest extends BaseDriverTest @@ -15,6 +17,14 @@ class CurlDriverTest extends BaseDriverTest { return new CurlDriver(); } + + public function testFileEmptyWithUtf8InName() + { + if (isWindows()) { + Environment::skip("CURL does not support UTF-8 on Windows."); + } + parent::testFileEmptyWithUtf8InName(); + } } (new CurlDriverTest())->run(); diff --git a/tests/BigFileTools/Driver/ExecDriverTest.phpt b/tests/BigFileTools/Driver/ExecDriverTest.phpt index 59da87b..1c58083 100644 --- a/tests/BigFileTools/Driver/ExecDriverTest.phpt +++ b/tests/BigFileTools/Driver/ExecDriverTest.phpt @@ -7,6 +7,8 @@ namespace BigFileTools\Driver; +use Tester\Environment; + $container = require __DIR__ . "/../../bootstrap.php"; class ExecDriverTest extends BaseDriverTest @@ -15,6 +17,15 @@ class ExecDriverTest extends BaseDriverTest { return new ExecDriver(); } + + public function testFileEmptyWithUtf8InName() + { + if (isWindows()) { + // @link http://stackoverflow.com/questions/13332321/php-exec-in-unicode-mode + Environment::skip("PHP does not support UTF-8 in commandline on Windows."); + } + parent::testFileEmptyWithUtf8InName(); + } } (new ExecDriverTest())->run(); diff --git a/tests/BigFileTools/Driver/NativeReadDriverTest.phpt b/tests/BigFileTools/Driver/NativeReadDriverTest.phpt index 9a7560c..6d0d12d 100644 --- a/tests/BigFileTools/Driver/NativeReadDriverTest.phpt +++ b/tests/BigFileTools/Driver/NativeReadDriverTest.phpt @@ -7,6 +7,8 @@ namespace BigFileTools\Driver; +use Tester\Environment; + $container = require __DIR__ . "/../../bootstrap.php"; class NativeReadDriverTest extends BaseDriverTest @@ -15,6 +17,15 @@ class NativeReadDriverTest extends BaseDriverTest { return new NativeReadDriver(); } + + public function testFileEmptyWithUtf8InName() + { + if (isWindows()) { + // @link http://stackoverflow.com/questions/6467501/php-how-to-create-unicode-filenames + Environment::skip("PHP does not support UTF-8 in filenames on Windows."); + } + parent::testFileEmptyWithUtf8InName(); + } } (new NativeReadDriverTest())->run(); diff --git a/tests/BigFileTools/Driver/NativeSeekDriverTest.phpt b/tests/BigFileTools/Driver/NativeSeekDriverTest.phpt index 0a2069b..47eb852 100644 --- a/tests/BigFileTools/Driver/NativeSeekDriverTest.phpt +++ b/tests/BigFileTools/Driver/NativeSeekDriverTest.phpt @@ -9,6 +9,7 @@ namespace BigFileTools\Driver; use BigFileTools\Utils; use Tester\Assert; +use Tester\Environment; $container = require __DIR__ . "/../../bootstrap.php"; @@ -30,6 +31,15 @@ class NativeSeekDriverTest extends BaseDriverTest parent::testFileBig_LargerThen2_32bites(); } } + + public function testFileEmptyWithUtf8InName() + { + if (isWindows()) { + // @link http://stackoverflow.com/questions/6467501/php-how-to-create-unicode-filenames + Environment::skip("PHP does not support UTF-8 in filenames on Windows."); + } + parent::testFileEmptyWithUtf8InName(); + } } (new NativeSeekDriverTest())->run(); diff --git a/tests/bootstrap.php b/tests/bootstrap.php index d607ce1..794bc3a 100644 --- a/tests/bootstrap.php +++ b/tests/bootstrap.php @@ -4,6 +4,10 @@ Tester\Environment::setup(); +function isWindows() { + return strtoupper(substr(PHP_OS, 0, 3)) === 'WIN'; +} + define("TESTS_EMPTY_FILE_PATH", __DIR__ . "/temp/emptyfile.tmp"); // 0B define("TESTS_EMPTY_FILE_WITH_SPACE_PATH", __DIR__ . "/temp/empty - file.tmp"); // 0B with with space in name define("TESTS_EMPTY_FILE_WITH_UTF8_PATH", __DIR__ . "/temp/emptyfileěšů指事字.tmp"); // 0B with utf-8 From bff570cdda4a86e39425c992461cf141941cfc19 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jan=20Kucha=C5=99?= Date: Wed, 27 Apr 2016 19:46:04 +0200 Subject: [PATCH 5/5] fixed formatting --- src/Driver/ExecDriver.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Driver/ExecDriver.php b/src/Driver/ExecDriver.php index 64df7ce..aa7d1a1 100644 --- a/src/Driver/ExecDriver.php +++ b/src/Driver/ExecDriver.php @@ -60,7 +60,7 @@ private function convertToInteger($valueAsString) { return BigInteger::of($trimmedInput); } catch (ArithmeticException $e) { - throw new Exception("Returned value cannot be converted to an integer.",0, $e); + throw new Exception("Returned value cannot be converted to an integer.", 0, $e); } }