Add pear modules, mail and net_smtp via composer (#93)

Add pear modules, mail and net_smtp via composer, remove php 5.6 build due to phpunit 6
This commit is contained in:
Thilina Hasantha
2018-01-08 23:13:43 +01:00
committed by GitHub
parent 359e3f8382
commit e7792e7d79
2349 changed files with 117270 additions and 83170 deletions

View File

@@ -1,6 +1,21 @@
CHANGELOG
=========
3.4.0
-----
* support for passing relative paths to `Filesystem::makePathRelative()` is deprecated and will be removed in 4.0
3.3.0
-----
* added `appendToFile()` to append contents to existing files
3.2.0
-----
* added `readlink()` as a platform independent method to read links
3.0.0
-----

View File

@@ -37,7 +37,8 @@ class Filesystem
*/
public function copy($originFile, $targetFile, $overwriteNewerFiles = false)
{
if (stream_is_local($originFile) && !is_file($originFile)) {
$originIsLocal = stream_is_local($originFile) || 0 === stripos($originFile, 'file://');
if ($originIsLocal && !is_file($originFile)) {
throw new FileNotFoundException(sprintf('Failed to copy "%s" because file does not exist.', $originFile), 0, null, $originFile);
}
@@ -68,11 +69,13 @@ class Filesystem
throw new IOException(sprintf('Failed to copy "%s" to "%s".', $originFile, $targetFile), 0, null, $originFile);
}
// Like `cp`, preserve executable permission bits
@chmod($targetFile, fileperms($targetFile) | (fileperms($originFile) & 0111));
if ($originIsLocal) {
// Like `cp`, preserve executable permission bits
@chmod($targetFile, fileperms($targetFile) | (fileperms($originFile) & 0111));
if (stream_is_local($originFile) && $bytesCopied !== ($bytesOrigin = filesize($originFile))) {
throw new IOException(sprintf('Failed to copy the whole content of "%s" to "%s" (%g of %g bytes copied).', $originFile, $targetFile, $bytesCopied, $bytesOrigin), 0, null, $originFile);
if ($bytesCopied !== $bytesOrigin = filesize($originFile)) {
throw new IOException(sprintf('Failed to copy the whole content of "%s" to "%s" (%g of %g bytes copied).', $originFile, $targetFile, $bytesCopied, $bytesOrigin), 0, null, $originFile);
}
}
}
}
@@ -80,14 +83,14 @@ class Filesystem
/**
* Creates a directory recursively.
*
* @param string|array|\Traversable $dirs The directory path
* @param int $mode The directory mode
* @param string|iterable $dirs The directory path
* @param int $mode The directory mode
*
* @throws IOException On any directory creation failure
*/
public function mkdir($dirs, $mode = 0777)
{
foreach ($this->toIterator($dirs) as $dir) {
foreach ($this->toIterable($dirs) as $dir) {
if (is_dir($dir)) {
continue;
}
@@ -108,15 +111,17 @@ class Filesystem
/**
* Checks the existence of files or directories.
*
* @param string|array|\Traversable $files A filename, an array of files, or a \Traversable instance to check
* @param string|iterable $files A filename, an array of files, or a \Traversable instance to check
*
* @return bool true if the file exists, false otherwise
*/
public function exists($files)
{
foreach ($this->toIterator($files) as $file) {
if ('\\' === DIRECTORY_SEPARATOR && strlen($file) > 258) {
throw new IOException('Could not check if file exist because path length exceeds 258 characters.', 0, null, $file);
$maxPathLength = PHP_MAXPATHLEN - 2;
foreach ($this->toIterable($files) as $file) {
if (strlen($file) > $maxPathLength) {
throw new IOException(sprintf('Could not check if file exist because path length exceeds %d characters.', $maxPathLength), 0, null, $file);
}
if (!file_exists($file)) {
@@ -130,15 +135,15 @@ class Filesystem
/**
* Sets access and modification time of file.
*
* @param string|array|\Traversable $files A filename, an array of files, or a \Traversable instance to create
* @param int $time The touch time as a Unix timestamp
* @param int $atime The access time as a Unix timestamp
* @param string|iterable $files A filename, an array of files, or a \Traversable instance to create
* @param int $time The touch time as a Unix timestamp
* @param int $atime The access time as a Unix timestamp
*
* @throws IOException When touch fails
*/
public function touch($files, $time = null, $atime = null)
{
foreach ($this->toIterator($files) as $file) {
foreach ($this->toIterable($files) as $file) {
$touch = $time ? @touch($file, $time, $atime) : @touch($file);
if (true !== $touch) {
throw new IOException(sprintf('Failed to touch "%s".', $file), 0, null, $file);
@@ -149,7 +154,7 @@ class Filesystem
/**
* Removes files or directories.
*
* @param string|array|\Traversable $files A filename, an array of files, or a \Traversable instance to remove
* @param string|iterable $files A filename, an array of files, or a \Traversable instance to remove
*
* @throws IOException When removal fails
*/
@@ -185,16 +190,16 @@ class Filesystem
/**
* Change mode for an array of files or directories.
*
* @param string|array|\Traversable $files A filename, an array of files, or a \Traversable instance to change mode
* @param int $mode The new mode (octal)
* @param int $umask The mode mask (octal)
* @param bool $recursive Whether change the mod recursively or not
* @param string|iterable $files A filename, an array of files, or a \Traversable instance to change mode
* @param int $mode The new mode (octal)
* @param int $umask The mode mask (octal)
* @param bool $recursive Whether change the mod recursively or not
*
* @throws IOException When the change fail
*/
public function chmod($files, $mode, $umask = 0000, $recursive = false)
{
foreach ($this->toIterator($files) as $file) {
foreach ($this->toIterable($files) as $file) {
if (true !== @chmod($file, $mode & ~$umask)) {
throw new IOException(sprintf('Failed to chmod file "%s".', $file), 0, null, $file);
}
@@ -207,15 +212,15 @@ class Filesystem
/**
* Change the owner of an array of files or directories.
*
* @param string|array|\Traversable $files A filename, an array of files, or a \Traversable instance to change owner
* @param string $user The new owner user name
* @param bool $recursive Whether change the owner recursively or not
* @param string|iterable $files A filename, an array of files, or a \Traversable instance to change owner
* @param string $user The new owner user name
* @param bool $recursive Whether change the owner recursively or not
*
* @throws IOException When the change fail
*/
public function chown($files, $user, $recursive = false)
{
foreach ($this->toIterator($files) as $file) {
foreach ($this->toIterable($files) as $file) {
if ($recursive && is_dir($file) && !is_link($file)) {
$this->chown(new \FilesystemIterator($file), $user, true);
}
@@ -234,15 +239,15 @@ class Filesystem
/**
* Change the group of an array of files or directories.
*
* @param string|array|\Traversable $files A filename, an array of files, or a \Traversable instance to change group
* @param string $group The group name
* @param bool $recursive Whether change the group recursively or not
* @param string|iterable $files A filename, an array of files, or a \Traversable instance to change group
* @param string $group The group name
* @param bool $recursive Whether change the group recursively or not
*
* @throws IOException When the change fail
*/
public function chgrp($files, $group, $recursive = false)
{
foreach ($this->toIterator($files) as $file) {
foreach ($this->toIterable($files) as $file) {
if ($recursive && is_dir($file) && !is_link($file)) {
$this->chgrp(new \FilesystemIterator($file), $group, true);
}
@@ -276,6 +281,13 @@ class Filesystem
}
if (true !== @rename($origin, $target)) {
if (is_dir($origin)) {
// See https://bugs.php.net/bug.php?id=54097 & http://php.net/manual/en/function.rename.php#113943
$this->mirror($origin, $target, null, array('override' => $overwrite, 'delete' => $overwrite));
$this->remove($origin);
return;
}
throw new IOException(sprintf('Cannot rename "%s" to "%s".', $origin, $target), 0, null, $target);
}
}
@@ -291,8 +303,10 @@ class Filesystem
*/
private function isReadable($filename)
{
if ('\\' === DIRECTORY_SEPARATOR && strlen($filename) > 258) {
throw new IOException('Could not check if file is readable because path length exceeds 258 characters.', 0, null, $filename);
$maxPathLength = PHP_MAXPATHLEN - 2;
if (strlen($filename) > $maxPathLength) {
throw new IOException(sprintf('Could not check if file is readable because path length exceeds %d characters.', $maxPathLength), 0, null, $filename);
}
return is_readable($filename);
@@ -332,16 +346,100 @@ class Filesystem
}
if (!$ok && true !== @symlink($originDir, $targetDir)) {
$report = error_get_last();
if (is_array($report)) {
if ('\\' === DIRECTORY_SEPARATOR && false !== strpos($report['message'], 'error code(1314)')) {
throw new IOException('Unable to create symlink due to error code 1314: \'A required privilege is not held by the client\'. Do you have the required Administrator-rights?', 0, null, $targetDir);
}
}
throw new IOException(sprintf('Failed to create symbolic link from "%s" to "%s".', $originDir, $targetDir), 0, null, $targetDir);
$this->linkException($originDir, $targetDir, 'symbolic');
}
}
/**
* Creates a hard link, or several hard links to a file.
*
* @param string $originFile The original file
* @param string|string[] $targetFiles The target file(s)
*
* @throws FileNotFoundException When original file is missing or not a file
* @throws IOException When link fails, including if link already exists
*/
public function hardlink($originFile, $targetFiles)
{
if (!$this->exists($originFile)) {
throw new FileNotFoundException(null, 0, null, $originFile);
}
if (!is_file($originFile)) {
throw new FileNotFoundException(sprintf('Origin file "%s" is not a file', $originFile));
}
foreach ($this->toIterable($targetFiles) as $targetFile) {
if (is_file($targetFile)) {
if (fileinode($originFile) === fileinode($targetFile)) {
continue;
}
$this->remove($targetFile);
}
if (true !== @link($originFile, $targetFile)) {
$this->linkException($originFile, $targetFile, 'hard');
}
}
}
/**
* @param string $origin
* @param string $target
* @param string $linkType Name of the link type, typically 'symbolic' or 'hard'
*/
private function linkException($origin, $target, $linkType)
{
$report = error_get_last();
if (is_array($report)) {
if ('\\' === DIRECTORY_SEPARATOR && false !== strpos($report['message'], 'error code(1314)')) {
throw new IOException(sprintf('Unable to create %s link due to error code 1314: \'A required privilege is not held by the client\'. Do you have the required Administrator-rights?', $linkType), 0, null, $target);
}
}
throw new IOException(sprintf('Failed to create %s link from "%s" to "%s".', $linkType, $origin, $target), 0, null, $target);
}
/**
* Resolves links in paths.
*
* With $canonicalize = false (default)
* - if $path does not exist or is not a link, returns null
* - if $path is a link, returns the next direct target of the link without considering the existence of the target
*
* With $canonicalize = true
* - if $path does not exist, returns null
* - if $path exists, returns its absolute fully resolved final version
*
* @param string $path A filesystem path
* @param bool $canonicalize Whether or not to return a canonicalized path
*
* @return string|null
*/
public function readlink($path, $canonicalize = false)
{
if (!$canonicalize && !is_link($path)) {
return;
}
if ($canonicalize) {
if (!$this->exists($path)) {
return;
}
if ('\\' === DIRECTORY_SEPARATOR) {
$path = readlink($path);
}
return realpath($path);
}
if ('\\' === DIRECTORY_SEPARATOR) {
return realpath($path);
}
return readlink($path);
}
/**
* Given an existing path, convert it to a path relative to a given starting path.
*
@@ -352,16 +450,48 @@ class Filesystem
*/
public function makePathRelative($endPath, $startPath)
{
if (!$this->isAbsolutePath($endPath) || !$this->isAbsolutePath($startPath)) {
@trigger_error(sprintf('Support for passing relative paths to %s() is deprecated since Symfony 3.4 and will be removed in 4.0.', __METHOD__), E_USER_DEPRECATED);
}
// Normalize separators on Windows
if ('\\' === DIRECTORY_SEPARATOR) {
$endPath = str_replace('\\', '/', $endPath);
$startPath = str_replace('\\', '/', $startPath);
}
$stripDriveLetter = function ($path) {
if (strlen($path) > 2 && ':' === $path[1] && '/' === $path[2] && ctype_alpha($path[0])) {
return substr($path, 2);
}
return $path;
};
$endPath = $stripDriveLetter($endPath);
$startPath = $stripDriveLetter($startPath);
// Split the paths into arrays
$startPathArr = explode('/', trim($startPath, '/'));
$endPathArr = explode('/', trim($endPath, '/'));
$normalizePathArray = function ($pathSegments, $absolute) {
$result = array();
foreach ($pathSegments as $segment) {
if ('..' === $segment && ($absolute || count($result))) {
array_pop($result);
} elseif ('.' !== $segment) {
$result[] = $segment;
}
}
return $result;
};
$startPathArr = $normalizePathArray($startPathArr, static::isAbsolutePath($startPath));
$endPathArr = $normalizePathArray($endPathArr, static::isAbsolutePath($endPath));
// Find for which directory the common path stops
$index = 0;
while (isset($startPathArr[$index]) && isset($endPathArr[$index]) && $startPathArr[$index] === $endPathArr[$index]) {
@@ -369,19 +499,14 @@ class Filesystem
}
// Determine how deep the start path is relative to the common path (ie, "web/bundles" = 2 levels)
if (count($startPathArr) === 1 && $startPathArr[0] === '') {
if (1 === count($startPathArr) && '' === $startPathArr[0]) {
$depth = 0;
} else {
$depth = count($startPathArr) - $index;
}
// When we need to traverse from the start, and we are starting from a root path, don't add '../'
if ('/' === $startPath[0] && 0 === $index && 0 === $depth) {
$traverser = '';
} else {
// Repeated "../" for each level need to reach the common path
$traverser = str_repeat('../', $depth);
}
// Repeated "../" for each level need to reach the common path
$traverser = str_repeat('../', $depth);
$endPathRemainder = implode('/', array_slice($endPathArr, $index));
@@ -409,6 +534,7 @@ class Filesystem
{
$targetDir = rtrim($targetDir, '/\\');
$originDir = rtrim($originDir, '/\\');
$originDirLen = strlen($originDir);
// Iterate in destination folder to remove obsolete entries
if ($this->exists($targetDir) && isset($options['delete']) && $options['delete']) {
@@ -417,8 +543,9 @@ class Filesystem
$flags = \FilesystemIterator::SKIP_DOTS;
$deleteIterator = new \RecursiveIteratorIterator(new \RecursiveDirectoryIterator($targetDir, $flags), \RecursiveIteratorIterator::CHILD_FIRST);
}
$targetDirLen = strlen($targetDir);
foreach ($deleteIterator as $file) {
$origin = str_replace($targetDir, $originDir, $file->getPathname());
$origin = $originDir.substr($file->getPathname(), $targetDirLen);
if (!$this->exists($origin)) {
$this->remove($file);
}
@@ -440,7 +567,7 @@ class Filesystem
}
foreach ($iterator as $file) {
$target = str_replace($originDir, $targetDir, $file->getPathname());
$target = $targetDir.substr($file->getPathname(), $originDirLen);
if ($copyOnWindows) {
if (is_file($file)) {
@@ -475,7 +602,7 @@ class Filesystem
{
return strspn($file, '/\\', 0, 1)
|| (strlen($file) > 3 && ctype_alpha($file[0])
&& substr($file, 1, 1) === ':'
&& ':' === $file[1]
&& strspn($file, '/\\', 2, 1)
)
|| null !== parse_url($file, PHP_URL_SCHEME)
@@ -540,7 +667,7 @@ class Filesystem
* @param string $filename The file to be written to
* @param string $content The data to write into the file
*
* @throws IOException If the file cannot be written to.
* @throws IOException if the file cannot be written to
*/
public function dumpFile($filename, $content)
{
@@ -548,7 +675,9 @@ class Filesystem
if (!is_dir($dir)) {
$this->mkdir($dir);
} elseif (!is_writable($dir)) {
}
if (!is_writable($dir)) {
throw new IOException(sprintf('Unable to write to the "%s" directory.', $dir), 0, null, $dir);
}
@@ -560,22 +689,44 @@ class Filesystem
throw new IOException(sprintf('Failed to write file "%s".', $filename), 0, null, $filename);
}
@chmod($tmpFile, 0666 & ~umask());
@chmod($tmpFile, file_exists($filename) ? fileperms($filename) : 0666 & ~umask());
$this->rename($tmpFile, $filename, true);
}
/**
* Appends content to an existing file.
*
* @param string $filename The file to which to append content
* @param string $content The content to append
*
* @throws IOException If the file is not writable
*/
public function appendToFile($filename, $content)
{
$dir = dirname($filename);
if (!is_dir($dir)) {
$this->mkdir($dir);
}
if (!is_writable($dir)) {
throw new IOException(sprintf('Unable to write to the "%s" directory.', $dir), 0, null, $dir);
}
if (false === @file_put_contents($filename, $content, FILE_APPEND)) {
throw new IOException(sprintf('Failed to write file "%s".', $filename), 0, null, $filename);
}
}
/**
* @param mixed $files
*
* @return \Traversable
* @return array|\Traversable
*/
private function toIterator($files)
private function toIterable($files)
{
if (!$files instanceof \Traversable) {
$files = new \ArrayObject(is_array($files) ? $files : array($files));
}
return $files;
return is_array($files) || $files instanceof \Traversable ? $files : array($files);
}
/**

View File

@@ -1,4 +1,4 @@
Copyright (c) 2004-2016 Fabien Potencier
Copyright (c) 2004-2018 Fabien Potencier
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal

View File

@@ -12,6 +12,10 @@
namespace Symfony\Component\Filesystem;
use Symfony\Component\Filesystem\Exception\IOException;
use Symfony\Component\Lock\Store\FlockStore;
use Symfony\Component\Lock\Store\SemaphoreStore;
@trigger_error(sprintf('The %s class is deprecated since Symfony 3.4 and will be removed in 4.0. Use %s or %s instead.', LockHandler::class, SemaphoreStore::class, FlockStore::class), E_USER_DEPRECATED);
/**
* LockHandler class provides a simple abstraction to lock anything by means of
@@ -25,6 +29,8 @@ use Symfony\Component\Filesystem\Exception\IOException;
* @author Grégoire Pineau <lyrixx@lyrixx.info>
* @author Romain Neutron <imprec@gmail.com>
* @author Nicolas Grekas <p@tchwork.com>
*
* @deprecated since version 3.4, to be removed in 4.0. Use Symfony\Component\Lock\Store\SemaphoreStore or Symfony\Component\Lock\Store\FlockStore instead.
*/
class LockHandler
{
@@ -56,7 +62,7 @@ class LockHandler
/**
* Lock the resource.
*
* @param bool $blocking wait until the lock is released
* @param bool $blocking Wait until the lock is released
*
* @return bool Returns true if the lock was acquired, false otherwise
*
@@ -68,8 +74,12 @@ class LockHandler
return true;
}
$error = null;
// Silence error reporting
set_error_handler(function () {});
set_error_handler(function ($errno, $msg) use (&$error) {
$error = $msg;
});
if (!$this->handle = fopen($this->file, 'r')) {
if ($this->handle = fopen($this->file, 'x')) {
@@ -82,8 +92,7 @@ class LockHandler
restore_error_handler();
if (!$this->handle) {
$error = error_get_last();
throw new IOException($error['message'], 0, null, $this->file);
throw new IOException($error, 0, null, $this->file);
}
// On Windows, even if PHP doc says the contrary, LOCK_NB works, see

View File

@@ -11,13 +11,14 @@
namespace Symfony\Component\Filesystem\Tests;
use PHPUnit\Framework\TestCase;
use Symfony\Component\Filesystem\Exception\IOException;
use Symfony\Component\Filesystem\Exception\FileNotFoundException;
/**
* Test class for Filesystem.
*/
class ExceptionTest extends \PHPUnit_Framework_TestCase
class ExceptionTest extends TestCase
{
public function testGetPath()
{

View File

@@ -26,7 +26,7 @@ class FilesystemTest extends FilesystemTestCase
$this->filesystem->copy($sourceFilePath, $targetFilePath);
$this->assertFileExists($targetFilePath);
$this->assertEquals('SOURCE FILE', file_get_contents($targetFilePath));
$this->assertStringEqualsFile($targetFilePath, 'SOURCE FILE');
}
/**
@@ -73,7 +73,7 @@ class FilesystemTest extends FilesystemTestCase
$this->filesystem->copy($sourceFilePath, $targetFilePath);
$this->assertFileExists($targetFilePath);
$this->assertEquals('SOURCE FILE', file_get_contents($targetFilePath));
$this->assertStringEqualsFile($targetFilePath, 'SOURCE FILE');
}
public function testCopyDoesNotOverrideExistingFileByDefault()
@@ -92,7 +92,7 @@ class FilesystemTest extends FilesystemTestCase
$this->filesystem->copy($sourceFilePath, $targetFilePath);
$this->assertFileExists($targetFilePath);
$this->assertEquals('TARGET FILE', file_get_contents($targetFilePath));
$this->assertStringEqualsFile($targetFilePath, 'TARGET FILE');
}
public function testCopyOverridesExistingFileIfForced()
@@ -111,7 +111,7 @@ class FilesystemTest extends FilesystemTestCase
$this->filesystem->copy($sourceFilePath, $targetFilePath, true);
$this->assertFileExists($targetFilePath);
$this->assertEquals('SOURCE FILE', file_get_contents($targetFilePath));
$this->assertStringEqualsFile($targetFilePath, 'SOURCE FILE');
}
/**
@@ -153,9 +153,12 @@ class FilesystemTest extends FilesystemTestCase
$this->assertTrue(is_dir($targetFileDirectory));
$this->assertFileExists($targetFilePath);
$this->assertEquals('SOURCE FILE', file_get_contents($targetFilePath));
$this->assertStringEqualsFile($targetFilePath, 'SOURCE FILE');
}
/**
* @group network
*/
public function testCopyForOriginUrlsAndExistingLocalFileDefaultsToCopy()
{
$sourceFilePath = 'http://symfony.com/images/common/logo/logo_symfony_header.png';
@@ -372,15 +375,15 @@ class FilesystemTest extends FilesystemTestCase
public function testFilesExistsFails()
{
if ('\\' !== DIRECTORY_SEPARATOR) {
$this->markTestSkipped('Test covers edge case on Windows only.');
$this->markTestSkipped('Long file names are an issue on Windows');
}
$basePath = $this->workspace.'\\directory\\';
$maxPathLength = PHP_MAXPATHLEN - 2;
$oldPath = getcwd();
mkdir($basePath);
chdir($basePath);
$file = str_repeat('T', 259 - strlen($basePath));
$file = str_repeat('T', $maxPathLength - strlen($basePath) + 1);
$path = $basePath.$file;
exec('TYPE NUL >>'.$file); // equivalent of touch, we can not use the php touch() here because it suffers from the same limitation
$this->longPathNamesWindows[] = $path; // save this so we can clean up later
@@ -442,14 +445,22 @@ class FilesystemTest extends FilesystemTestCase
$this->assertFilePermissions(400, $file);
}
public function testChmodWrongMod()
public function testChmodWithWrongModLeavesPreviousPermissionsUntouched()
{
$this->markAsSkippedIfChmodIsMissing();
if (defined('HHVM_VERSION')) {
$this->markTestSkipped('chmod() changes permissions even when passing invalid modes on HHVM');
}
$dir = $this->workspace.DIRECTORY_SEPARATOR.'file';
touch($dir);
$permissions = fileperms($dir);
$this->filesystem->chmod($dir, 'Wrongmode');
$this->assertSame($permissions, fileperms($dir));
}
public function testChmodRecursive()
@@ -536,7 +547,10 @@ class FilesystemTest extends FilesystemTestCase
$dir = $this->workspace.DIRECTORY_SEPARATOR.'dir';
mkdir($dir);
$this->filesystem->chown($dir, $this->getFileOwner($dir));
$owner = $this->getFileOwner($dir);
$this->filesystem->chown($dir, $owner);
$this->assertSame($owner, $this->getFileOwner($dir));
}
public function testChownRecursive()
@@ -548,7 +562,10 @@ class FilesystemTest extends FilesystemTestCase
$file = $dir.DIRECTORY_SEPARATOR.'file';
touch($file);
$this->filesystem->chown($dir, $this->getFileOwner($dir), true);
$owner = $this->getFileOwner($dir);
$this->filesystem->chown($dir, $owner, true);
$this->assertSame($owner, $this->getFileOwner($file));
}
public function testChownSymlink()
@@ -562,7 +579,27 @@ class FilesystemTest extends FilesystemTestCase
$this->filesystem->symlink($file, $link);
$this->filesystem->chown($link, $this->getFileOwner($link));
$owner = $this->getFileOwner($link);
$this->filesystem->chown($link, $owner);
$this->assertSame($owner, $this->getFileOwner($link));
}
public function testChownLink()
{
$this->markAsSkippedIfLinkIsMissing();
$file = $this->workspace.DIRECTORY_SEPARATOR.'file';
$link = $this->workspace.DIRECTORY_SEPARATOR.'link';
touch($file);
$this->filesystem->hardlink($file, $link);
$owner = $this->getFileOwner($link);
$this->filesystem->chown($link, $owner);
$this->assertSame($owner, $this->getFileOwner($link));
}
/**
@@ -582,6 +619,23 @@ class FilesystemTest extends FilesystemTestCase
$this->filesystem->chown($link, 'user'.time().mt_rand(1000, 9999));
}
/**
* @expectedException \Symfony\Component\Filesystem\Exception\IOException
*/
public function testChownLinkFails()
{
$this->markAsSkippedIfLinkIsMissing();
$file = $this->workspace.DIRECTORY_SEPARATOR.'file';
$link = $this->workspace.DIRECTORY_SEPARATOR.'link';
touch($file);
$this->filesystem->hardlink($file, $link);
$this->filesystem->chown($link, 'user'.time().mt_rand(1000, 9999));
}
/**
* @expectedException \Symfony\Component\Filesystem\Exception\IOException
*/
@@ -602,7 +656,10 @@ class FilesystemTest extends FilesystemTestCase
$dir = $this->workspace.DIRECTORY_SEPARATOR.'dir';
mkdir($dir);
$this->filesystem->chgrp($dir, $this->getFileGroup($dir));
$group = $this->getFileGroup($dir);
$this->filesystem->chgrp($dir, $group);
$this->assertSame($group, $this->getFileGroup($dir));
}
public function testChgrpRecursive()
@@ -614,7 +671,10 @@ class FilesystemTest extends FilesystemTestCase
$file = $dir.DIRECTORY_SEPARATOR.'file';
touch($file);
$this->filesystem->chgrp($dir, $this->getFileGroup($dir), true);
$group = $this->getFileGroup($dir);
$this->filesystem->chgrp($dir, $group, true);
$this->assertSame($group, $this->getFileGroup($file));
}
public function testChgrpSymlink()
@@ -628,7 +688,27 @@ class FilesystemTest extends FilesystemTestCase
$this->filesystem->symlink($file, $link);
$this->filesystem->chgrp($link, $this->getFileGroup($link));
$group = $this->getFileGroup($link);
$this->filesystem->chgrp($link, $group);
$this->assertSame($group, $this->getFileGroup($link));
}
public function testChgrpLink()
{
$this->markAsSkippedIfLinkIsMissing();
$file = $this->workspace.DIRECTORY_SEPARATOR.'file';
$link = $this->workspace.DIRECTORY_SEPARATOR.'link';
touch($file);
$this->filesystem->hardlink($file, $link);
$group = $this->getFileGroup($link);
$this->filesystem->chgrp($link, $group);
$this->assertSame($group, $this->getFileGroup($link));
}
/**
@@ -648,6 +728,23 @@ class FilesystemTest extends FilesystemTestCase
$this->filesystem->chgrp($link, 'user'.time().mt_rand(1000, 9999));
}
/**
* @expectedException \Symfony\Component\Filesystem\Exception\IOException
*/
public function testChgrpLinkFails()
{
$this->markAsSkippedIfLinkIsMissing();
$file = $this->workspace.DIRECTORY_SEPARATOR.'file';
$link = $this->workspace.DIRECTORY_SEPARATOR.'link';
touch($file);
$this->filesystem->hardlink($file, $link);
$this->filesystem->chgrp($link, 'user'.time().mt_rand(1000, 9999));
}
/**
* @expectedException \Symfony\Component\Filesystem\Exception\IOException
*/
@@ -743,9 +840,9 @@ class FilesystemTest extends FilesystemTestCase
$this->filesystem->remove($link);
$this->assertTrue(!is_link($link));
$this->assertTrue(!is_file($link));
$this->assertTrue(!is_dir($link));
$this->assertFalse(is_link($link));
$this->assertFalse(is_file($link));
$this->assertFalse(is_dir($link));
}
public function testSymlinkIsOverwrittenIfPointsToDifferentTarget()
@@ -799,6 +896,193 @@ class FilesystemTest extends FilesystemTestCase
$this->assertEquals($file, readlink($link2));
}
public function testLink()
{
$this->markAsSkippedIfLinkIsMissing();
$file = $this->workspace.DIRECTORY_SEPARATOR.'file';
$link = $this->workspace.DIRECTORY_SEPARATOR.'link';
touch($file);
$this->filesystem->hardlink($file, $link);
$this->assertTrue(is_file($link));
$this->assertEquals(fileinode($file), fileinode($link));
}
/**
* @depends testLink
*/
public function testRemoveLink()
{
$this->markAsSkippedIfLinkIsMissing();
$link = $this->workspace.DIRECTORY_SEPARATOR.'link';
$this->filesystem->remove($link);
$this->assertTrue(!is_file($link));
}
public function testLinkIsOverwrittenIfPointsToDifferentTarget()
{
$this->markAsSkippedIfLinkIsMissing();
$file = $this->workspace.DIRECTORY_SEPARATOR.'file';
$file2 = $this->workspace.DIRECTORY_SEPARATOR.'file2';
$link = $this->workspace.DIRECTORY_SEPARATOR.'link';
touch($file);
touch($file2);
link($file2, $link);
$this->filesystem->hardlink($file, $link);
$this->assertTrue(is_file($link));
$this->assertEquals(fileinode($file), fileinode($link));
}
public function testLinkIsNotOverwrittenIfAlreadyCreated()
{
$this->markAsSkippedIfLinkIsMissing();
$file = $this->workspace.DIRECTORY_SEPARATOR.'file';
$link = $this->workspace.DIRECTORY_SEPARATOR.'link';
touch($file);
link($file, $link);
$this->filesystem->hardlink($file, $link);
$this->assertTrue(is_file($link));
$this->assertEquals(fileinode($file), fileinode($link));
}
public function testLinkWithSeveralTargets()
{
$this->markAsSkippedIfLinkIsMissing();
$file = $this->workspace.DIRECTORY_SEPARATOR.'file';
$link1 = $this->workspace.DIRECTORY_SEPARATOR.'link';
$link2 = $this->workspace.DIRECTORY_SEPARATOR.'link2';
touch($file);
$this->filesystem->hardlink($file, array($link1, $link2));
$this->assertTrue(is_file($link1));
$this->assertEquals(fileinode($file), fileinode($link1));
$this->assertTrue(is_file($link2));
$this->assertEquals(fileinode($file), fileinode($link2));
}
public function testLinkWithSameTarget()
{
$this->markAsSkippedIfLinkIsMissing();
$file = $this->workspace.DIRECTORY_SEPARATOR.'file';
$link = $this->workspace.DIRECTORY_SEPARATOR.'link';
touch($file);
// practically same as testLinkIsNotOverwrittenIfAlreadyCreated
$this->filesystem->hardlink($file, array($link, $link));
$this->assertTrue(is_file($link));
$this->assertEquals(fileinode($file), fileinode($link));
}
public function testReadRelativeLink()
{
$this->markAsSkippedIfSymlinkIsMissing();
if ('\\' === DIRECTORY_SEPARATOR) {
$this->markTestSkipped('Relative symbolic links are not supported on Windows');
}
$file = $this->workspace.'/file';
$link1 = $this->workspace.'/dir/link';
$link2 = $this->workspace.'/dir/link2';
touch($file);
$this->filesystem->symlink('../file', $link1);
$this->filesystem->symlink('link', $link2);
$this->assertEquals($this->normalize('../file'), $this->filesystem->readlink($link1));
$this->assertEquals('link', $this->filesystem->readlink($link2));
$this->assertEquals($file, $this->filesystem->readlink($link1, true));
$this->assertEquals($file, $this->filesystem->readlink($link2, true));
$this->assertEquals($file, $this->filesystem->readlink($file, true));
}
public function testReadAbsoluteLink()
{
$this->markAsSkippedIfSymlinkIsMissing();
$file = $this->normalize($this->workspace.'/file');
$link1 = $this->normalize($this->workspace.'/dir/link');
$link2 = $this->normalize($this->workspace.'/dir/link2');
touch($file);
$this->filesystem->symlink($file, $link1);
$this->filesystem->symlink($link1, $link2);
$this->assertEquals($file, $this->filesystem->readlink($link1));
$this->assertEquals($link1, $this->filesystem->readlink($link2));
$this->assertEquals($file, $this->filesystem->readlink($link1, true));
$this->assertEquals($file, $this->filesystem->readlink($link2, true));
$this->assertEquals($file, $this->filesystem->readlink($file, true));
}
public function testReadBrokenLink()
{
$this->markAsSkippedIfSymlinkIsMissing();
if ('\\' === DIRECTORY_SEPARATOR) {
$this->markTestSkipped('Windows does not support creating "broken" symlinks');
}
$file = $this->workspace.'/file';
$link = $this->workspace.'/link';
$this->filesystem->symlink($file, $link);
$this->assertEquals($file, $this->filesystem->readlink($link));
$this->assertNull($this->filesystem->readlink($link, true));
touch($file);
$this->assertEquals($file, $this->filesystem->readlink($link, true));
}
public function testReadLinkDefaultPathDoesNotExist()
{
$this->assertNull($this->filesystem->readlink($this->normalize($this->workspace.'/invalid')));
}
public function testReadLinkDefaultPathNotLink()
{
$file = $this->normalize($this->workspace.'/file');
touch($file);
$this->assertNull($this->filesystem->readlink($file));
}
public function testReadLinkCanonicalizePath()
{
$this->markAsSkippedIfSymlinkIsMissing();
$file = $this->normalize($this->workspace.'/file');
mkdir($this->normalize($this->workspace.'/dir'));
touch($file);
$this->assertEquals($file, $this->filesystem->readlink($this->normalize($this->workspace.'/dir/../file'), true));
}
public function testReadLinkCanonicalizedPathDoesNotExist()
{
$this->assertNull($this->filesystem->readlink($this->normalize($this->workspace.'invalid'), true));
}
/**
* @dataProvider providePathsForMakePathRelative
*/
@@ -809,9 +1093,6 @@ class FilesystemTest extends FilesystemTestCase
$this->assertEquals($expectedPath, $path);
}
/**
* @return array
*/
public function providePathsForMakePathRelative()
{
$paths = array(
@@ -819,7 +1100,6 @@ class FilesystemTest extends FilesystemTestCase
array('/var/lib/symfony/src/Symfony/', '/var/lib/symfony/src/Symfony/Component/', '../'),
array('/var/lib/symfony/src/Symfony', '/var/lib/symfony/src/Symfony/Component', '../'),
array('/var/lib/symfony/src/Symfony', '/var/lib/symfony/src/Symfony/Component/', '../'),
array('var/lib/symfony/', 'var/lib/symfony/src/Symfony/Component', '../../../'),
array('/usr/lib/symfony/', '/var/lib/symfony/src/Symfony/Component', '../../../../../../usr/lib/symfony/'),
array('/var/lib/symfony/src/Symfony/', '/var/lib/symfony/', 'src/Symfony/'),
array('/aa/bb', '/aa/bb', './'),
@@ -842,6 +1122,16 @@ class FilesystemTest extends FilesystemTestCase
array('/a/aab/bb/', '/b/aab', '../../a/aab/bb/'),
array('/aab/bb', '/aa', '../aab/bb/'),
array('/aab', '/aa', '../aab/'),
array('/aa/bb/cc', '/aa/dd/..', 'bb/cc/'),
array('/aa/../bb/cc', '/aa/dd/..', '../bb/cc/'),
array('/aa/bb/../../cc', '/aa/../dd/..', 'cc/'),
array('/../aa/bb/cc', '/aa/dd/..', 'bb/cc/'),
array('/../../aa/../bb/cc', '/aa/dd/..', '../bb/cc/'),
array('C:/aa/bb/cc', 'C:/aa/dd/..', 'bb/cc/'),
array('c:/aa/../bb/cc', 'c:/aa/dd/..', '../bb/cc/'),
array('C:/aa/bb/../../cc', 'C:/aa/../dd/..', 'cc/'),
array('C:/../aa/bb/cc', 'C:/aa/dd/..', 'bb/cc/'),
array('C:/../../aa/../bb/cc', 'C:/aa/dd/..', '../bb/cc/'),
);
if ('\\' === DIRECTORY_SEPARATOR) {
@@ -851,6 +1141,36 @@ class FilesystemTest extends FilesystemTestCase
return $paths;
}
/**
* @group legacy
* @dataProvider provideLegacyPathsForMakePathRelativeWithRelativePaths
* @expectedDeprecation Support for passing relative paths to Symfony\Component\Filesystem\Filesystem::makePathRelative() is deprecated since Symfony 3.4 and will be removed in 4.0.
*/
public function testMakePathRelativeWithRelativePaths($endPath, $startPath, $expectedPath)
{
$path = $this->filesystem->makePathRelative($endPath, $startPath);
$this->assertEquals($expectedPath, $path);
}
public function provideLegacyPathsForMakePathRelativeWithRelativePaths()
{
return array(
array('usr/lib/symfony/', 'var/lib/symfony/src/Symfony/Component', '../../../../../../usr/lib/symfony/'),
array('aa/bb', 'aa/cc', '../bb/'),
array('aa/cc', 'bb/cc', '../../aa/cc/'),
array('aa/bb', 'aa/./cc', '../bb/'),
array('aa/./bb', 'aa/cc', '../bb/'),
array('aa/./bb', 'aa/./cc', '../bb/'),
array('../../', '../../', './'),
array('../aa/bb/', 'aa/bb/', '../../../aa/bb/'),
array('../../../', '../../', '../'),
array('', '', './'),
array('', 'aa/', '../'),
array('aa/', '', 'aa/'),
);
}
public function testMirrorCopiesFilesAndDirectoriesRecursively()
{
$sourcePath = $this->workspace.DIRECTORY_SEPARATOR.'source'.DIRECTORY_SEPARATOR;
@@ -970,6 +1290,53 @@ class FilesystemTest extends FilesystemTestCase
$this->assertEquals('\\' === DIRECTORY_SEPARATOR ? realpath($sourcePath.'\nested') : 'nested', readlink($targetPath.DIRECTORY_SEPARATOR.'link1'));
}
public function testMirrorContentsWithSameNameAsSourceOrTargetWithoutDeleteOption()
{
$sourcePath = $this->workspace.DIRECTORY_SEPARATOR.'source'.DIRECTORY_SEPARATOR;
mkdir($sourcePath);
touch($sourcePath.'source');
touch($sourcePath.'target');
$targetPath = $this->workspace.DIRECTORY_SEPARATOR.'target'.DIRECTORY_SEPARATOR;
$oldPath = getcwd();
chdir($this->workspace);
$this->filesystem->mirror('source', $targetPath);
chdir($oldPath);
$this->assertTrue(is_dir($targetPath));
$this->assertFileExists($targetPath.'source');
$this->assertFileExists($targetPath.'target');
}
public function testMirrorContentsWithSameNameAsSourceOrTargetWithDeleteOption()
{
$sourcePath = $this->workspace.DIRECTORY_SEPARATOR.'source'.DIRECTORY_SEPARATOR;
mkdir($sourcePath);
touch($sourcePath.'source');
$targetPath = $this->workspace.DIRECTORY_SEPARATOR.'target'.DIRECTORY_SEPARATOR;
mkdir($targetPath);
touch($targetPath.'source');
touch($targetPath.'target');
$oldPath = getcwd();
chdir($this->workspace);
$this->filesystem->mirror('source', 'target', null, array('delete' => true));
chdir($oldPath);
$this->assertTrue(is_dir($targetPath));
$this->assertFileExists($targetPath.'source');
$this->assertFileNotExists($targetPath.'target');
}
/**
* @dataProvider providePathsForIsAbsolutePath
*/
@@ -980,9 +1347,6 @@ class FilesystemTest extends FilesystemTestCase
$this->assertEquals($expectedResult, $result);
}
/**
* @return array
*/
public function providePathsForIsAbsolutePath()
{
return array(
@@ -1110,7 +1474,7 @@ class FilesystemTest extends FilesystemTestCase
$this->filesystem->dumpFile($filename, 'bar');
$this->assertFileExists($filename);
$this->assertSame('bar', file_get_contents($filename));
$this->assertStringEqualsFile($filename, 'bar');
// skip mode check on Windows
if ('\\' !== DIRECTORY_SEPARATOR) {
@@ -1127,7 +1491,7 @@ class FilesystemTest extends FilesystemTestCase
$this->filesystem->dumpFile($filename, 'bar');
$this->assertFileExists($filename);
$this->assertSame('bar', file_get_contents($filename));
$this->assertStringEqualsFile($filename, 'bar');
}
public function testDumpFileWithFileScheme()
@@ -1139,10 +1503,10 @@ class FilesystemTest extends FilesystemTestCase
$scheme = 'file://';
$filename = $scheme.$this->workspace.DIRECTORY_SEPARATOR.'foo'.DIRECTORY_SEPARATOR.'baz.txt';
$this->filesystem->dumpFile($filename, 'bar', null);
$this->filesystem->dumpFile($filename, 'bar');
$this->assertFileExists($filename);
$this->assertSame('bar', file_get_contents($filename));
$this->assertStringEqualsFile($filename, 'bar');
}
public function testDumpFileWithZlibScheme()
@@ -1150,11 +1514,99 @@ class FilesystemTest extends FilesystemTestCase
$scheme = 'compress.zlib://';
$filename = $this->workspace.DIRECTORY_SEPARATOR.'foo'.DIRECTORY_SEPARATOR.'baz.txt';
$this->filesystem->dumpFile($filename, 'bar', null);
$this->filesystem->dumpFile($filename, 'bar');
// Zlib stat uses file:// wrapper so remove scheme
$this->assertFileExists(str_replace($scheme, '', $filename));
$this->assertSame('bar', file_get_contents($filename));
$this->assertStringEqualsFile($filename, 'bar');
}
public function testAppendToFile()
{
$filename = $this->workspace.DIRECTORY_SEPARATOR.'foo'.DIRECTORY_SEPARATOR.'bar.txt';
// skip mode check on Windows
if ('\\' !== DIRECTORY_SEPARATOR) {
$oldMask = umask(0002);
}
$this->filesystem->dumpFile($filename, 'foo');
$this->filesystem->appendToFile($filename, 'bar');
$this->assertFileExists($filename);
$this->assertStringEqualsFile($filename, 'foobar');
// skip mode check on Windows
if ('\\' !== DIRECTORY_SEPARATOR) {
$this->assertFilePermissions(664, $filename);
umask($oldMask);
}
}
public function testAppendToFileWithScheme()
{
if (defined('HHVM_VERSION')) {
$this->markTestSkipped('HHVM does not handle the file:// scheme correctly');
}
$scheme = 'file://';
$filename = $scheme.$this->workspace.DIRECTORY_SEPARATOR.'foo'.DIRECTORY_SEPARATOR.'baz.txt';
$this->filesystem->dumpFile($filename, 'foo');
$this->filesystem->appendToFile($filename, 'bar');
$this->assertFileExists($filename);
$this->assertStringEqualsFile($filename, 'foobar');
}
public function testAppendToFileWithZlibScheme()
{
$scheme = 'compress.zlib://';
$filename = $this->workspace.DIRECTORY_SEPARATOR.'foo'.DIRECTORY_SEPARATOR.'baz.txt';
$this->filesystem->dumpFile($filename, 'foo');
// Zlib stat uses file:// wrapper so remove it
$this->assertStringEqualsFile(str_replace($scheme, '', $filename), 'foo');
$this->filesystem->appendToFile($filename, 'bar');
$this->assertFileExists($filename);
$this->assertStringEqualsFile($filename, 'foobar');
}
public function testAppendToFileCreateTheFileIfNotExists()
{
$filename = $this->workspace.DIRECTORY_SEPARATOR.'foo'.DIRECTORY_SEPARATOR.'bar.txt';
// skip mode check on Windows
if ('\\' !== DIRECTORY_SEPARATOR) {
$oldMask = umask(0002);
}
$this->filesystem->appendToFile($filename, 'bar');
// skip mode check on Windows
if ('\\' !== DIRECTORY_SEPARATOR) {
$this->assertFilePermissions(664, $filename);
umask($oldMask);
}
$this->assertFileExists($filename);
$this->assertStringEqualsFile($filename, 'bar');
}
public function testDumpKeepsExistingPermissionsWhenOverwritingAnExistingFile()
{
$this->markAsSkippedIfChmodIsMissing();
$filename = $this->workspace.DIRECTORY_SEPARATOR.'foo.txt';
file_put_contents($filename, 'FOO BAR');
chmod($filename, 0745);
$this->filesystem->dumpFile($filename, 'bar', null);
$this->assertFilePermissions(745, $filename);
}
public function testCopyShouldKeepExecutionPermission()
@@ -1171,4 +1623,16 @@ class FilesystemTest extends FilesystemTestCase
$this->assertFilePermissions(767, $targetFilePath);
}
/**
* Normalize the given path (transform each blackslash into a real directory separator).
*
* @param string $path
*
* @return string
*/
private function normalize($path)
{
return str_replace('/', DIRECTORY_SEPARATOR, $path);
}
}

View File

@@ -11,9 +11,10 @@
namespace Symfony\Component\Filesystem\Tests;
use PHPUnit\Framework\TestCase;
use Symfony\Component\Filesystem\Filesystem;
class FilesystemTestCase extends \PHPUnit_Framework_TestCase
class FilesystemTestCase extends TestCase
{
private $umask;
@@ -29,16 +30,42 @@ class FilesystemTestCase extends \PHPUnit_Framework_TestCase
*/
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 && null === self::$symlinkOnWindows) {
$target = tempnam(sys_get_temp_dir(), 'sl');
$link = sys_get_temp_dir().'/sl'.microtime(true).mt_rand();
self::$symlinkOnWindows = @symlink($target, $link) && is_link($link);
@unlink($link);
unlink($target);
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);
}
}
}
@@ -65,7 +92,7 @@ class FilesystemTestCase extends \PHPUnit_Framework_TestCase
}
/**
* @param int $expectedFilePerms expected file permissions as three digits (i.e. 755)
* @param int $expectedFilePerms Expected file permissions as three digits (i.e. 755)
* @param string $filePath
*/
protected function assertFilePermissions($expectedFilePerms, $filePath)
@@ -100,6 +127,17 @@ class FilesystemTestCase extends \PHPUnit_Framework_TestCase
$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) {

View File

@@ -11,9 +11,15 @@
namespace Symfony\Component\Filesystem\Tests;
use PHPUnit\Framework\TestCase;
use Symfony\Component\Filesystem\Exception\IOException;
use Symfony\Component\Filesystem\Filesystem;
use Symfony\Component\Filesystem\LockHandler;
class LockHandlerTest extends \PHPUnit_Framework_TestCase
/**
* @group legacy
*/
class LockHandlerTest extends TestCase
{
/**
* @expectedException \Symfony\Component\Filesystem\Exception\IOException
@@ -39,6 +45,44 @@ class LockHandlerTest extends \PHPUnit_Framework_TestCase
new LockHandler('lock', '/');
}
public function testErrorHandlingInLockIfLockPathBecomesUnwritable()
{
// skip test on Windows; PHP can't easily set file as unreadable on Windows
if ('\\' === DIRECTORY_SEPARATOR) {
$this->markTestSkipped('This test cannot run on Windows.');
}
$lockPath = sys_get_temp_dir().'/'.uniqid('', true);
$e = null;
$wrongMessage = null;
try {
mkdir($lockPath);
$lockHandler = new LockHandler('lock', $lockPath);
chmod($lockPath, 0444);
$lockHandler->lock();
} catch (IOException $e) {
if (false === strpos($e->getMessage(), 'Permission denied')) {
$wrongMessage = $e->getMessage();
} else {
$this->addToAssertionCount(1);
}
} catch (\Exception $e) {
} catch (\Throwable $e) {
}
if (is_dir($lockPath)) {
$fs = new Filesystem();
$fs->remove($lockPath);
}
$this->assertInstanceOf('Symfony\Component\Filesystem\Exception\IOException', $e, sprintf('Expected IOException to be thrown, got %s instead.', get_class($e)));
$this->assertNull($wrongMessage, sprintf('Expected exception message to contain "Permission denied", got "%s" instead.', $wrongMessage));
}
public function testConstructSanitizeName()
{
$lock = new LockHandler('<?php echo "% hello word ! %" ?>');

View File

@@ -16,7 +16,7 @@
}
],
"require": {
"php": ">=5.5.9"
"php": "^5.5.9|>=7.0.8"
},
"autoload": {
"psr-4": { "Symfony\\Component\\Filesystem\\": "" },
@@ -27,7 +27,7 @@
"minimum-stability": "dev",
"extra": {
"branch-alias": {
"dev-master": "3.1-dev"
"dev-master": "3.4-dev"
}
}
}

View File

@@ -5,6 +5,8 @@
backupGlobals="false"
colors="true"
bootstrap="vendor/autoload.php"
failOnRisky="true"
failOnWarning="true"
>
<php>
<ini name="error_reporting" value="-1" />