mirror of
https://github.com/Combodo/iTop.git
synced 2026-03-07 18:14:12 +01:00
Package operations: 2 installs, 23 updates, 0 removals - Updating psr/log (1.1.0 => 1.1.2) - Updating symfony/debug (v3.4.30 => v3.4.35) - Updating symfony/console (v3.4.30 => v3.4.35) - Updating symfony/dotenv (v3.4.30 => v3.4.35) - Updating symfony/routing (v3.4.30 => v3.4.35) - Updating symfony/finder (v3.4.30 => v3.4.35) - Updating symfony/filesystem (v3.4.30 => v3.4.35) - Installing symfony/polyfill-util (v1.12.0) - Installing symfony/polyfill-php56 (v1.12.0) - Updating symfony/http-foundation (v3.4.30 => v3.4.35) - Updating symfony/event-dispatcher (v3.4.30 => v3.4.35) - Updating symfony/http-kernel (v3.4.30 => v3.4.35) - Updating symfony/config (v3.4.30 => v3.4.35) - Updating symfony/dependency-injection (v3.4.30 => v3.4.35) - Updating symfony/class-loader (v3.4.30 => v3.4.35) - Updating symfony/cache (v3.4.30 => v3.4.35) - Updating symfony/framework-bundle (v3.4.30 => v3.4.35) - Updating twig/twig (v1.42.2 => v1.42.4) - Updating symfony/twig-bridge (v3.4.30 => v3.4.35) - Updating symfony/twig-bundle (v3.4.30 => v3.4.35) - Updating symfony/yaml (v3.4.30 => v3.4.35) - Updating symfony/stopwatch (v3.4.30 => v3.4.35) - Updating symfony/var-dumper (v3.4.30 => v3.4.35) - Updating symfony/web-profiler-bundle (v3.4.30 => v3.4.35) - Updating symfony/css-selector (v3.4.30 => v3.4.35)
145 lines
4.2 KiB
PHP
145 lines
4.2 KiB
PHP
<?php
|
|
|
|
/*
|
|
* This file is part of the Symfony package.
|
|
*
|
|
* (c) Fabien Potencier <fabien@symfony.com>
|
|
*
|
|
* 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\Exception\IOException;
|
|
use Symfony\Component\Filesystem\Filesystem;
|
|
use Symfony\Component\Filesystem\LockHandler;
|
|
|
|
/**
|
|
* @group legacy
|
|
*/
|
|
class LockHandlerTest extends TestCase
|
|
{
|
|
public function testConstructWhenRepositoryDoesNotExist()
|
|
{
|
|
$this->expectException('Symfony\Component\Filesystem\Exception\IOException');
|
|
$this->expectExceptionMessage('Failed to create "/a/b/c/d/e": mkdir(): Permission denied.');
|
|
if (!getenv('USER') || 'root' === getenv('USER')) {
|
|
$this->markTestSkipped('This test will fail if run under superuser');
|
|
}
|
|
new LockHandler('lock', '/a/b/c/d/e');
|
|
}
|
|
|
|
public function testConstructWhenRepositoryIsNotWriteable()
|
|
{
|
|
$this->expectException('Symfony\Component\Filesystem\Exception\IOException');
|
|
$this->expectExceptionMessage('The directory "/" is not writable.');
|
|
if (!getenv('USER') || 'root' === getenv('USER')) {
|
|
$this->markTestSkipped('This test will fail if run under superuser');
|
|
}
|
|
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.');
|
|
}
|
|
|
|
if (!getenv('USER') || 'root' === getenv('USER')) {
|
|
$this->markTestSkipped('This test will fail if run under superuser');
|
|
}
|
|
|
|
$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 ! %" ?>');
|
|
|
|
$file = sprintf('%s/sf.-php-echo-hello-word-.4b3d9d0d27ddef3a78a64685dda3a963e478659a9e5240feaf7b4173a8f28d5f.lock', sys_get_temp_dir());
|
|
// ensure the file does not exist before the lock
|
|
@unlink($file);
|
|
|
|
$lock->lock();
|
|
|
|
$this->assertFileExists($file);
|
|
|
|
$lock->release();
|
|
}
|
|
|
|
public function testLockRelease()
|
|
{
|
|
$name = 'symfony-test-filesystem.lock';
|
|
|
|
$l1 = new LockHandler($name);
|
|
$l2 = new LockHandler($name);
|
|
|
|
$this->assertTrue($l1->lock());
|
|
$this->assertFalse($l2->lock());
|
|
|
|
$l1->release();
|
|
|
|
$this->assertTrue($l2->lock());
|
|
$l2->release();
|
|
}
|
|
|
|
public function testLockTwice()
|
|
{
|
|
$name = 'symfony-test-filesystem.lock';
|
|
|
|
$lockHandler = new LockHandler($name);
|
|
|
|
$this->assertTrue($lockHandler->lock());
|
|
$this->assertTrue($lockHandler->lock());
|
|
|
|
$lockHandler->release();
|
|
}
|
|
|
|
public function testLockIsReleased()
|
|
{
|
|
$name = 'symfony-test-filesystem.lock';
|
|
|
|
$l1 = new LockHandler($name);
|
|
$l2 = new LockHandler($name);
|
|
|
|
$this->assertTrue($l1->lock());
|
|
$this->assertFalse($l2->lock());
|
|
|
|
$l1 = null;
|
|
|
|
$this->assertTrue($l2->lock());
|
|
$l2->release();
|
|
}
|
|
}
|