Last active
August 29, 2015 14:05
-
-
Save k-holy/4b59ffb569548e8e01f6 to your computer and use it in GitHub Desktop.
Windowsで末尾に5Cを含むファイルの扱いを検証
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
namespace Acme; | |
define('OS_IS_WIN', (strncasecmp(PHP_OS, 'WIN', 3) === 0)); | |
setlocale(LC_ALL, OS_IS_WIN ? 'Japanese_Japan.932' : 'ja_JP.UTF-8'); | |
$LC_ALL = setlocale(LC_ALL, 0); | |
class U | |
{ | |
public static function H($data, $default=null) | |
{ | |
$var = $default; | |
if (isset($data)) { | |
if (is_bool($data)) { | |
$var = ($data) ? 'TRUE' : 'FALSE'; | |
} else { | |
if (OS_IS_WIN) { | |
$data = mb_convert_encoding($data, 'UTF-8', 'CP932'); | |
} | |
$var = htmlspecialchars($data, ENT_QUOTES, 'UTF-8'); | |
} | |
} | |
return $var; | |
} | |
} | |
$files = array(); | |
// 日本語(非5C)のファイル | |
$path = __DIR__ . DIRECTORY_SEPARATOR . '日本語.txt'; | |
if (OS_IS_WIN) { | |
$path = mb_convert_encoding($path, 'CP932', 'UTF-8'); | |
} | |
$files['日本語(非5C)のファイル'] = new \SplFileInfo($path); | |
// 日本語(非5C)のディレクトリ | |
$path = __DIR__ . DIRECTORY_SEPARATOR . '日本語'; | |
if (OS_IS_WIN) { | |
$path = mb_convert_encoding($path, 'CP932', 'UTF-8'); | |
} | |
$files['日本語(非5C)のディレクトリ '] = new \SplFileInfo($path); | |
// 日本語(非5C)のディレクトリをパスに含むファイル | |
$path = __DIR__ . DIRECTORY_SEPARATOR . '日本語' . DIRECTORY_SEPARATOR . 'test.txt'; | |
if (OS_IS_WIN) { | |
$path = mb_convert_encoding($path, 'CP932', 'UTF-8'); | |
} | |
$files['日本語(非5C)のディレクトリをパスに含むファイル '] = new \SplFileInfo($path); | |
// 日本語(5C)のファイル | |
$path = __DIR__ . DIRECTORY_SEPARATOR . '表.txt'; | |
if (OS_IS_WIN) { | |
$path = mb_convert_encoding($path, 'CP932', 'UTF-8'); | |
} | |
$files['日本語(5C)のファイル'] = new \SplFileInfo($path); | |
// 日本語(5C)のディレクトリ | |
$path = __DIR__ . DIRECTORY_SEPARATOR . '表'; | |
if (OS_IS_WIN) { | |
$path = mb_convert_encoding($path, 'CP932', 'UTF-8'); | |
} | |
$files['日本語(5C)のディレクトリ'] = new \SplFileInfo($path); | |
// 日本語(5C)のディレクトリをパスに含むファイル | |
$path = __DIR__ . DIRECTORY_SEPARATOR . '表' . DIRECTORY_SEPARATOR . 'test.txt'; | |
if (OS_IS_WIN) { | |
$path = mb_convert_encoding($path, 'CP932', 'UTF-8'); | |
} | |
$files['日本語(5C)のディレクトリをパスに含むファイル '] = new \SplFileInfo($path); | |
?> | |
<!DOCTYPE html> | |
<html> | |
<head> | |
<meta charset="utf-8" /> | |
<meta name="robots" content="noindex,nofollow" /> | |
<style type="text/css"> | |
body {font-family:monospace;} | |
table { | |
width:80%; | |
border-collapse:collapse; | |
margin:10px 0px; | |
} | |
caption { | |
text-align:left; | |
font-size:120%; | |
font-weight:bold; | |
} | |
th, td { | |
text-align:left; | |
padding:2px; | |
border:solid 1px #999999; | |
} | |
th { | |
width:25em; | |
} | |
</style> | |
<title>SplFileInfo @<?=U::H($_SERVER['HTTP_HOST'])?></title> | |
</head> | |
<body> | |
<h1><?=U::H(PHP_OS)?>(<?=OS_IS_WIN ? 'Windows' : 'Not Windows'?>)</h1> | |
<h2><?=U::H($LC_ALL)?></h2> | |
<?php foreach ($files as $k => $file) : ?> | |
<table> | |
<caption><h3><?=$k?></h3></caption> | |
<tr> | |
<th>SplFileInfo::getPathname()</th> | |
<td><?=U::H($file->getPathname())?></td> | |
</tr> | |
<tr> | |
<th>SplFileInfo::getPath()</th> | |
<td><?=U::H($file->getPath())?></td> | |
</tr> | |
<tr> | |
<th>SplFileInfo::getFilename()</th> | |
<td><?=U::H($file->getFilename())?></td> | |
</tr> | |
<tr> | |
<th>SplFileInfo::getBasename()</th> | |
<td><?=U::H($file->getBasename())?></td> | |
</tr> | |
<tr> | |
<th>SplFileInfo::getExtension()</th> | |
<td><?=U::H(method_exists($file, 'getExtension') ? $file->getExtension() : 'METHOD IS NOT EXISTS')?></td> | |
</tr> | |
<tr> | |
<th>dirname($file)</th> | |
<td><?=U::H(dirname((string)$file))?></td> | |
</tr> | |
<tr> | |
<th>basename($file)</th> | |
<td><?=U::H(basename((string)$file))?></td> | |
</tr> | |
<tr> | |
<th>pathinfo($file, PATHINFO_DIRNAME)</th> | |
<td><?=U::H(pathinfo((string)$file, PATHINFO_DIRNAME))?></td> | |
</tr> | |
<tr> | |
<th>pathinfo($file, PATHINFO_BASENAME)</th> | |
<td><?=U::H(pathinfo((string)$file, PATHINFO_BASENAME))?></td> | |
</tr> | |
<tr> | |
<th>pathinfo($file, PATHINFO_FILENAME)</th> | |
<td><?=U::H(pathinfo((string)$file, PATHINFO_FILENAME))?></td> | |
</tr> | |
<tr> | |
<th>pathinfo($file, PATHINFO_EXTENSION)</th> | |
<td><?=U::H(pathinfo((string)$file, PATHINFO_EXTENSION))?></td> | |
</tr> | |
<tr> | |
<th>SplFileInfo::getRealPath()</th> | |
<td><?=U::H($file->getRealPath())?></td> | |
</tr> | |
<tr> | |
<th>SplFileInfo::getType()</th> | |
<td><?php try{ echo U::H($file->getType()); }catch(\RuntimeException $e){ echo U::H($e->getMessage());}?></td> | |
</tr> | |
<tr> | |
<th>SplFileInfo::isDir()</th> | |
<td><?=U::H($file->isDir())?></td> | |
</tr> | |
<tr> | |
<th>SplFileInfo::isFile()</th> | |
<td><?=U::H($file->isFile())?></td> | |
</tr> | |
<tr> | |
<th>SplFileInfo::isReadable()</th> | |
<td><?=U::H($file->isReadable())?></td> | |
</tr> | |
<tr> | |
<th>SplFileInfo::getPathInfo()</th> | |
<td><?=U::H((string)$file->getPathInfo())?></td> | |
</tr> | |
<tr> | |
<th>SplFileInfo::__toString()</th> | |
<td><?=U::H((string)$file)?></td> | |
</tr> | |
</table> | |
<?php endforeach ?> | |
</body> | |
</html> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
namespace Acme\Test; | |
class SplFileInfoTest extends \PHPUnit_Framework_TestCase | |
{ | |
private $isWin; | |
private $testDir; | |
public function setUp() | |
{ | |
$this->isWin = (strncasecmp(PHP_OS, 'WIN', 3) === 0); | |
$this->testDir = __DIR__ . DIRECTORY_SEPARATOR . 'SplFileInfoTest'; | |
} | |
private function convert($path) | |
{ | |
return mb_convert_encoding($path, 'CP932', 'UTF-8'); | |
} | |
// 日本語(非5C)のファイル(Windows) | |
public function testJapaneseFileOnWindows() | |
{ | |
if (!$this->isWin) { | |
$this->markTestSkipped('OS is not Windows'); | |
} | |
$this->setLocale(LC_CTYPE, 'Japanese_Japan.932'); | |
$path = $this->convert($this->testDir . DIRECTORY_SEPARATOR . '日本語.txt'); | |
$fileInfo = new \SplFileInfo($path); | |
$pathinfo = pathinfo($path); | |
$this->assertEquals($path, $fileInfo->getRealPath()); | |
$this->assertEquals($path, $fileInfo->getPathname()); | |
$this->assertEquals($this->convert('日本語.txt'), $pathinfo['basename']); | |
$this->assertEquals($pathinfo['basename'], $fileInfo->getBasename()); | |
$this->assertEquals($pathinfo['basename'], basename($path)); | |
$this->assertEquals($this->testDir, $pathinfo['dirname']); | |
$this->assertEquals($pathinfo['dirname'], $fileInfo->getPath()); | |
$this->assertEquals($pathinfo['dirname'], dirname($path)); | |
$this->assertEquals( 'txt', $pathinfo['extension']); | |
$this->assertEquals($pathinfo['extension'], $fileInfo->getExtension()); | |
$this->assertEquals('file', $fileInfo->getType()); | |
$this->assertTrue($fileInfo->isFile()); | |
$this->assertFalse($fileInfo->isDir()); | |
} | |
// 日本語(非5C)のディレクトリ(Windows) | |
public function testJapaneseDirectoryOnWindows() | |
{ | |
if (!$this->isWin) { | |
$this->markTestSkipped('OS is not Windows'); | |
} | |
$this->setLocale(LC_CTYPE, 'Japanese_Japan.932'); | |
$path = $this->convert($this->testDir . DIRECTORY_SEPARATOR . '日本語'); | |
$fileInfo = new \SplFileInfo($path); | |
$pathinfo = pathinfo($path); | |
$this->assertEquals($path, $fileInfo->getRealPath()); | |
$this->assertEquals($path, $fileInfo->getPathname()); | |
$this->assertEquals($this->convert('日本語'), $pathinfo['basename']); | |
$this->assertEquals($pathinfo['basename'], $fileInfo->getBasename()); | |
$this->assertEquals($pathinfo['basename'], basename($path)); | |
$this->assertEquals($this->testDir, $pathinfo['dirname']); | |
$this->assertEquals($pathinfo['dirname'], $fileInfo->getPath()); | |
$this->assertEquals($pathinfo['dirname'], dirname($path)); | |
$this->assertArrayNotHasKey('extension', $pathinfo); | |
$this->assertEmpty($fileInfo->getExtension()); | |
$this->assertEquals('dir', $fileInfo->getType()); | |
$this->assertFalse($fileInfo->isFile()); | |
$this->assertTrue($fileInfo->isDir()); | |
} | |
// 日本語(非5C)のディレクトリをパスに含むファイル(Windows) | |
public function testFileIncludesJapaneseInPathOnWindows() | |
{ | |
if (!$this->isWin) { | |
$this->markTestSkipped('OS is not Windows'); | |
} | |
$this->setLocale(LC_CTYPE, 'Japanese_Japan.932'); | |
$path = $this->convert($this->testDir . DIRECTORY_SEPARATOR . '日本語' . DIRECTORY_SEPARATOR . 'test.txt'); | |
$fileInfo = new \SplFileInfo($path); | |
$pathinfo = pathinfo($path); | |
$this->assertEquals($path, $fileInfo->getRealPath()); | |
$this->assertEquals($path, $fileInfo->getPathname()); | |
$this->assertEquals('test.txt', $pathinfo['basename']); | |
$this->assertEquals($pathinfo['basename'], $fileInfo->getBasename()); | |
$this->assertEquals($pathinfo['basename'], basename($path)); | |
$this->assertNotEquals($this->convert($this->testDir . DIRECTORY_SEPARATOR . '日本語'), $pathinfo['dirname']); // !! | |
$this->assertNotEquals($pathinfo['dirname'], $fileInfo->getPath()); // !! | |
$this->assertEquals($pathinfo['dirname'], dirname($path)); | |
$this->assertEquals('txt', $pathinfo['extension']); | |
$this->assertEquals($pathinfo['extension'], $fileInfo->getExtension()); | |
$this->assertEquals('file', $fileInfo->getType()); | |
$this->assertTrue($fileInfo->isFile()); | |
$this->assertFalse($fileInfo->isDir()); | |
} | |
// 日本語(5C)のファイル(Windows) | |
public function testJapaneseFileIncludes5cOnWindows() | |
{ | |
if (!$this->isWin) { | |
$this->markTestSkipped('OS is not Windows'); | |
} | |
$this->setLocale(LC_CTYPE, 'Japanese_Japan.932'); | |
$path = $this->convert($this->testDir . DIRECTORY_SEPARATOR . '表.txt'); | |
$fileInfo = new \SplFileInfo($path); | |
$pathinfo = pathinfo($path); | |
$this->assertFalse($fileInfo->getRealPath()); // !! | |
$this->assertEquals($path, $fileInfo->getPathname()); | |
$this->assertEquals($this->convert('表.txt'), $pathinfo['basename']); | |
$this->assertNotEquals($pathinfo['basename'], $fileInfo->getBasename()); // !! | |
$this->assertEquals($pathinfo['basename'], basename($path)); | |
$this->assertEquals($this->testDir, $pathinfo['dirname']); | |
$this->assertNotEquals($pathinfo['dirname'], $fileInfo->getPath()); // !! | |
$this->assertEquals($pathinfo['dirname'], dirname($path)); | |
$this->assertEquals( 'txt', $pathinfo['extension']); | |
$this->assertEquals($pathinfo['extension'], $fileInfo->getExtension()); | |
$this->assertEquals('file', $fileInfo->getType()); | |
$this->assertFalse($fileInfo->isFile()); // !! | |
$this->assertFalse($fileInfo->isDir()); | |
} | |
// 日本語(5C)のディレクトリ(Windows) | |
public function testJapaneseDirectoryIncludes5cOnWindows() | |
{ | |
if (!$this->isWin) { | |
$this->markTestSkipped('OS is not Windows'); | |
} | |
$this->setLocale(LC_CTYPE, 'Japanese_Japan.932'); | |
$path = $this->convert($this->testDir . DIRECTORY_SEPARATOR . '表'); | |
$fileInfo = new \SplFileInfo($path); | |
$pathinfo = pathinfo($path); | |
$this->assertFalse($fileInfo->getRealPath()); // !! | |
$this->assertNotEquals($path, $fileInfo->getPathname()); // !! | |
$this->assertEquals($this->convert('表'), $pathinfo['basename']); | |
$this->assertNotEquals($pathinfo['basename'], $fileInfo->getBasename()); // !! | |
$this->assertEquals($pathinfo['basename'], basename($path)); | |
$this->assertEquals($this->testDir, $pathinfo['dirname']); | |
$this->assertEquals($pathinfo['dirname'], $fileInfo->getPath()); | |
$this->assertEquals($pathinfo['dirname'], dirname($path)); | |
$this->assertArrayNotHasKey('extension', $pathinfo); | |
$this->assertEmpty($fileInfo->getExtension()); | |
$this->assertEquals('dir', $fileInfo->getType()); | |
$this->assertFalse($fileInfo->isFile()); | |
$this->assertFalse($fileInfo->isDir()); // !! | |
} | |
// 日本語(5C)のディレクトリをパスに含むファイル(Windows) | |
public function testFileIncludesJapaneseIncludes5cInPathOnWindows() | |
{ | |
if (!$this->isWin) { | |
$this->markTestSkipped('OS is not Windows'); | |
} | |
$this->setLocale(LC_CTYPE, 'Japanese_Japan.932'); | |
$path = $this->convert($this->testDir . DIRECTORY_SEPARATOR . '表' . DIRECTORY_SEPARATOR . 'test.txt'); | |
$fileInfo = new \SplFileInfo($path); | |
$pathinfo = pathinfo($path); | |
$this->assertFalse($fileInfo->getRealPath()); // !! | |
$this->assertEquals($path, $fileInfo->getPathname()); | |
$this->assertEquals('test.txt', $pathinfo['basename']); | |
$this->assertEquals($pathinfo['basename'], $fileInfo->getBasename()); | |
$this->assertEquals($pathinfo['basename'], basename($path)); | |
$this->assertEquals($this->convert($this->testDir . DIRECTORY_SEPARATOR . '表'), $pathinfo['dirname']); | |
$this->assertEquals($pathinfo['dirname'], $fileInfo->getPath()); | |
$this->assertEquals($pathinfo['dirname'], dirname($path)); | |
$this->assertEquals('txt', $pathinfo['extension']); | |
$this->assertEquals($pathinfo['extension'], $fileInfo->getExtension()); | |
try { | |
$this->assertEquals('file', $fileInfo->getType()); | |
} catch (\RuntimeException $e) { | |
$this->assertStringStartsWith('SplFileInfo::getType(): Lstat failed', $e->getMessage()); // !! | |
} | |
$this->assertFalse($fileInfo->isFile()); // !! | |
$this->assertFalse($fileInfo->isDir()); | |
} | |
// 日本語のファイル(非Windows) | |
public function testJapaneseFile() | |
{ | |
if ($this->isWin) { | |
$this->markTestSkipped('OS is Windows'); | |
} | |
$this->setLocale(LC_CTYPE, 'ja_JP.UTF-8'); | |
$path = $this->testDir . DIRECTORY_SEPARATOR . '日本語.txt'; | |
$fileInfo = new \SplFileInfo($path); | |
$pathinfo = pathinfo($path); | |
$this->assertEquals($path, $fileInfo->getRealPath()); | |
$this->assertEquals($path, $fileInfo->getPathname()); | |
$this->assertEquals('日本語.txt', $pathinfo['basename']); | |
$this->assertEquals($pathinfo['basename'], $fileInfo->getBasename()); | |
$this->assertEquals($pathinfo['basename'], basename($path)); | |
$this->assertEquals($this->testDir, $pathinfo['dirname']); | |
$this->assertEquals($pathinfo['dirname'], $fileInfo->getPath()); | |
$this->assertEquals($pathinfo['dirname'], dirname($path)); | |
$this->assertEquals( 'txt', $pathinfo['extension']); | |
$this->assertEquals($pathinfo['extension'], $fileInfo->getExtension()); | |
$this->assertEquals('file', $fileInfo->getType()); | |
$this->assertTrue($fileInfo->isFile()); | |
$this->assertFalse($fileInfo->isDir()); | |
} | |
// 日本語(非5C)のディレクトリ(非Windows) | |
public function testJapaneseDirectory() | |
{ | |
if ($this->isWin) { | |
$this->markTestSkipped('OS is Windows'); | |
} | |
$this->setLocale(LC_CTYPE, 'ja_JP.UTF-8'); | |
$path = $this->testDir . DIRECTORY_SEPARATOR . '日本語'; | |
$fileInfo = new \SplFileInfo($path); | |
$pathinfo = pathinfo($path); | |
$this->assertEquals($path, $fileInfo->getRealPath()); | |
$this->assertEquals($path, $fileInfo->getPathname()); | |
$this->assertEquals('日本語', $pathinfo['basename']); | |
$this->assertEquals($pathinfo['basename'], $fileInfo->getBasename()); | |
$this->assertEquals($pathinfo['basename'], basename($path)); | |
$this->assertEquals($this->testDir, $pathinfo['dirname']); | |
$this->assertEquals($pathinfo['dirname'], $fileInfo->getPath()); | |
$this->assertEquals($pathinfo['dirname'], dirname($path)); | |
$this->assertArrayNotHasKey('extension', $pathinfo); | |
$this->assertEmpty($fileInfo->getExtension()); | |
$this->assertEquals('dir', $fileInfo->getType()); | |
$this->assertFalse($fileInfo->isFile()); | |
$this->assertTrue($fileInfo->isDir()); | |
} | |
// 日本語(非5C)のディレクトリをパスに含むファイル(非Windows) | |
public function testFileIncludesJapaneseInPath() | |
{ | |
if ($this->isWin) { | |
$this->markTestSkipped('OS is Windows'); | |
} | |
$this->setLocale(LC_CTYPE, 'ja_JP.UTF-8'); | |
$path = $this->testDir . DIRECTORY_SEPARATOR . '日本語' . DIRECTORY_SEPARATOR . 'test.txt'; | |
$fileInfo = new \SplFileInfo($path); | |
$pathinfo = pathinfo($path); | |
$this->assertEquals($path, $fileInfo->getRealPath()); | |
$this->assertEquals($path, $fileInfo->getPathname()); | |
$this->assertEquals('test.txt', $pathinfo['basename']); | |
$this->assertEquals($pathinfo['basename'], $fileInfo->getBasename()); | |
$this->assertEquals($pathinfo['basename'], basename($path)); | |
$this->assertEquals($this->testDir . DIRECTORY_SEPARATOR . '日本語', $pathinfo['dirname']); | |
$this->assertEquals($pathinfo['dirname'], $fileInfo->getPath()); | |
$this->assertEquals($pathinfo['dirname'], dirname($path)); | |
$this->assertEquals('txt', $pathinfo['extension']); | |
$this->assertEquals($pathinfo['extension'], $fileInfo->getExtension()); | |
$this->assertEquals('file', $fileInfo->getType()); | |
$this->assertTrue($fileInfo->isFile()); | |
$this->assertFalse($fileInfo->isDir()); | |
} | |
// 存在しない日本語のファイル | |
public function testJapaneseFileNotExisting() | |
{ | |
if (!$this->isWin) { | |
$this->setLocale(LC_CTYPE, 'ja_JP.UTF-8'); | |
} | |
$path = $this->testDir . DIRECTORY_SEPARATOR . 'ソ.txt'; | |
$fileInfo = new \SplFileInfo($path); | |
$pathinfo = pathinfo($path); | |
$this->assertFalse($fileInfo->getRealPath()); | |
$this->assertEquals($path, $fileInfo->getPathname()); | |
$this->assertEquals('ソ.txt', $pathinfo['basename']); | |
$this->assertEquals($pathinfo['basename'], $fileInfo->getBasename()); | |
$this->assertEquals($pathinfo['basename'], basename($path)); | |
$this->assertEquals($this->testDir, $pathinfo['dirname']); | |
$this->assertEquals($pathinfo['dirname'], $fileInfo->getPath()); | |
$this->assertEquals($pathinfo['dirname'], dirname($path)); | |
$this->assertEquals( 'txt', $pathinfo['extension']); | |
$this->assertEquals($pathinfo['extension'], $fileInfo->getExtension()); | |
try { | |
$fileInfo->getType(); | |
} catch (\RuntimeException $e) { | |
$this->assertStringStartsWith('SplFileInfo::getType(): Lstat failed', $e->getMessage()); | |
} | |
$this->assertFalse($fileInfo->isFile()); | |
$this->assertFalse($fileInfo->isDir()); | |
} | |
// 存在しない日本語のディレクトリ | |
public function testJapaneseDirectoryNotExisting() | |
{ | |
if (!$this->isWin) { | |
$this->setLocale(LC_CTYPE, 'ja_JP.UTF-8'); | |
} | |
$path = $this->testDir . DIRECTORY_SEPARATOR . 'ソ'; | |
$fileInfo = new \SplFileInfo($path); | |
$pathinfo = pathinfo($path); | |
$this->assertFalse($fileInfo->getRealPath()); | |
$this->assertEquals($path, $fileInfo->getPathname()); | |
$this->assertEquals('ソ', $pathinfo['basename']); | |
$this->assertEquals($pathinfo['basename'], $fileInfo->getBasename()); | |
$this->assertEquals($pathinfo['basename'], basename($path)); | |
$this->assertEquals($this->testDir, $pathinfo['dirname']); | |
$this->assertEquals($pathinfo['dirname'], $fileInfo->getPath()); | |
$this->assertEquals($pathinfo['dirname'], dirname($path)); | |
$this->assertArrayNotHasKey('extension', $pathinfo); | |
$this->assertEmpty($fileInfo->getExtension()); | |
try { | |
$fileInfo->getType(); | |
} catch (\RuntimeException $e) { | |
$this->assertStringStartsWith('SplFileInfo::getType(): Lstat failed', $e->getMessage()); | |
} | |
$this->assertFalse($fileInfo->isFile()); | |
$this->assertFalse($fileInfo->isDir()); | |
} | |
// 存在しない日本語のディレクトリをパスに含むファイル | |
public function testFileIncludesJapaneseInPathNotExisting() | |
{ | |
if (!$this->isWin) { | |
$this->setLocale(LC_CTYPE, 'ja_JP.UTF-8'); | |
} | |
$path = $this->testDir . DIRECTORY_SEPARATOR . 'ソ' . DIRECTORY_SEPARATOR . 'test.txt'; | |
$fileInfo = new \SplFileInfo($path); | |
$pathinfo = pathinfo($path); | |
$this->assertFalse($fileInfo->getRealPath()); | |
$this->assertEquals($path, $fileInfo->getPathname()); | |
$this->assertEquals('test.txt', $pathinfo['basename']); | |
$this->assertEquals($pathinfo['basename'], $fileInfo->getBasename()); | |
$this->assertEquals($pathinfo['basename'], basename($path)); | |
$this->assertEquals($this->testDir . DIRECTORY_SEPARATOR . 'ソ', $pathinfo['dirname']); | |
$this->assertEquals($pathinfo['dirname'], $fileInfo->getPath()); | |
$this->assertEquals($pathinfo['dirname'], dirname($path)); | |
$this->assertEquals('txt', $pathinfo['extension']); | |
$this->assertEquals($pathinfo['extension'], $fileInfo->getExtension()); | |
try { | |
$fileInfo->getType(); | |
} catch (\RuntimeException $e) { | |
$this->assertStringStartsWith('SplFileInfo::getType(): Lstat failed', $e->getMessage()); | |
} | |
$this->assertFalse($fileInfo->isFile()); | |
$this->assertFalse($fileInfo->isDir()); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
テストを通すためにアサーションを修正した結果を添付。(Windows7 + PHP 5.6.0)
これは確定かな。
以下の場合でおかしな結果が返されている。
非5Cでもdirname()が変だったり、盤石と思えたSplFileInfo::getPathname()が5Cのディレクトリだけ変だったり、意味が分からない…。
Linux + ja_JP.UTF-8 の場合は全て問題なし。