* * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ namespace Symfony\Component\Filesystem\Tests; use PHPUnit\Framework\TestCase; use Symfony\Component\Filesystem\Filesystem; class FilesystemTestCase extends TestCase { private $umask; protected $longPathNamesWindows = array(); /** * @var \Symfony\Component\Filesystem\Filesystem */ protected $filesystem = null; /** * @var string */ protected $workspace = null; /** * @var null|bool Flag for hard links on Windows */ private static $linkOnWindows = null; /** * @var null|bool Flag for symbolic links on Windows */ private static $symlinkOnWindows = null; public static function setUpBeforeClass() { if ('\\' === DIRECTORY_SEPARATOR) { self::$linkOnWindows = true; $originFile = tempnam(sys_get_temp_dir(), 'li'); $targetFile = tempnam(sys_get_temp_dir(), 'li'); if (true !== @link($originFile, $targetFile)) { $report = error_get_last(); if (is_array($report) && false !== strpos($report['message'], 'error code(1314)')) { self::$linkOnWindows = false; } } else { @unlink($targetFile); } self::$symlinkOnWindows = true; $originDir = tempnam(sys_get_temp_dir(), 'sl'); $targetDir = tempnam(sys_get_temp_dir(), 'sl'); if (true !== @symlink($originDir, $targetDir)) { $report = error_get_last(); if (is_array($report) && false !== strpos($report['message'], 'error code(1314)')) { self::$symlinkOnWindows = false; } } else { @unlink($targetDir); } } } protected function setUp() { $this->umask = umask(0); $this->filesystem = new Filesystem(); $this->workspace = sys_get_temp_dir().'/'.microtime(true).'.'.mt_rand(); mkdir($this->workspace, 0777, true); $this->workspace = realpath($this->workspace); } protected function tearDown() { if (!empty($this->longPathNamesWindows)) { foreach ($this->longPathNamesWindows as $path) { exec('DEL '.$path); } $this->longPathNamesWindows = array(); } $this->filesystem->remove($this->workspace); umask($this->umask); } /** * @param int $expectedFilePerms Expected file permissions as three digits (i.e. 755) * @param string $filePath */ protected function assertFilePermissions($expectedFilePerms, $filePath) { $actualFilePerms = (int) substr(sprintf('%o', fileperms($filePath)), -3); $this->assertEquals( $expectedFilePerms, $actualFilePerms, sprintf('File permissions for %s must be %s. Actual %s', $filePath, $expectedFilePerms, $actualFilePerms) ); } protected function getFileOwner($filepath) { $this->markAsSkippedIfPosixIsMissing(); $infos = stat($filepath); if ($datas = posix_getpwuid($infos['uid'])) { return $datas['name']; } } protected function getFileGroup($filepath) { $this->markAsSkippedIfPosixIsMissing(); $infos = stat($filepath); if ($datas = posix_getgrgid($infos['gid'])) { return $datas['name']; } $this->markTestSkipped('Unable to retrieve file group name'); } protected function markAsSkippedIfLinkIsMissing() { if (!function_exists('link')) { $this->markTestSkipped('link is not supported'); } if ('\\' === DIRECTORY_SEPARATOR && false === self::$linkOnWindows) { $this->markTestSkipped('link requires "Create hard links" privilege on windows'); } } protected function markAsSkippedIfSymlinkIsMissing($relative = false) { if ('\\' === DIRECTORY_SEPARATOR && false === self::$symlinkOnWindows) { $this->markTestSkipped('symlink requires "Create symbolic links" privilege on Windows'); } // https://bugs.php.net/bug.php?id=69473 if ($relative && '\\' === DIRECTORY_SEPARATOR && 1 === PHP_ZTS) { $this->markTestSkipped('symlink does not support relative paths on thread safe Windows PHP versions'); } } protected function markAsSkippedIfChmodIsMissing() { if ('\\' === DIRECTORY_SEPARATOR) { $this->markTestSkipped('chmod is not supported on Windows'); } } protected function markAsSkippedIfPosixIsMissing() { if (!function_exists('posix_isatty')) { $this->markTestSkipped('Function posix_isatty is required.'); } } } __halt_compiler();----SIGNATURE:----vhdR4fUyJ8xc98PK8Xza/ri8oDuMLvJjEoB2Tst6mMXShKfUfNnf5wg6r2+99qp7Ig2JU2xuVmTDyX0sxxd1gpe6eGtRNc9xxhfJFFl3bNuEs8W0LmPw4yt+yGuzOc4eaINzmsEZg631nbGQo5458fX8hzfEXhsFvR7dWtjKMpBQgHbBSUVBnTrd/M7BHCmdU/B2/zZDK0uIHWywkKZdgvj0Kccq9Y0GvYlogcA9UXheEZ0YWbudPL9L8Wf7xYw/W4CXtHc7v8/stk/jWfakMbGLC7jL/aNipyP9LVY/OCAd/j4if3jD47NpouLz6rUx9c4mAa7hAvYq70xf6PhxILt6hFktp6vqfxQK95yjzd4Kh6gIUjpmygCEC4BeZL2YwEDZU7ByDpOU1qw4qtTtFnTwp9TUBKjiIJgVn+nZ/J2jaXyN4qTHR17mbpg0Riqqjqr5oT+uO+V82BhvQnrZM5TZbyhc7hTfDf10Q9pG3Zjv5PJFl7AqKI9IJohQ9pynoSuPo1zYUw6Fla/AOCppCs24PHDdnvK2hUaXYEWL1WDat/A17GpKhl04TqMgC79PwyJI2vmgqU4ppOrP5a8w1zpyT8fxgDdE9lfGFOu18kTC3vA3hy5heOO9ktjpXp7VyKNyDnIPJBC/kwAehtO5NIaJJuuOQVQQrdLHp77MbkU=----ATTACHMENT:----NzQ3NzgzNDIyNzQwMTYxNiAxOTk1MzQ0NDk2OTMxMDcgNzc3Nzc0OTA2MjcxNTU5Nw==