Security update for Core, with self-updated composer
[yaffs-website] / vendor / symfony / console / Tests / Command / LockableTraitTest.php
1 <?php
2
3 /*
4  * This file is part of the Symfony package.
5  *
6  * (c) Fabien Potencier <fabien@symfony.com>
7  *
8  * For the full copyright and license information, please view the LICENSE
9  * file that was distributed with this source code.
10  */
11
12 namespace Symfony\Component\Console\Tests\Command;
13
14 use PHPUnit\Framework\TestCase;
15 use Symfony\Component\Console\Tester\CommandTester;
16 use Symfony\Component\Filesystem\LockHandler;
17
18 class LockableTraitTest extends TestCase
19 {
20     protected static $fixturesPath;
21
22     public static function setUpBeforeClass()
23     {
24         self::$fixturesPath = __DIR__.'/../Fixtures/';
25         require_once self::$fixturesPath.'/FooLockCommand.php';
26         require_once self::$fixturesPath.'/FooLock2Command.php';
27     }
28
29     public function testLockIsReleased()
30     {
31         $command = new \FooLockCommand();
32
33         $tester = new CommandTester($command);
34         $this->assertSame(2, $tester->execute(array()));
35         $this->assertSame(2, $tester->execute(array()));
36     }
37
38     public function testLockReturnsFalseIfAlreadyLockedByAnotherCommand()
39     {
40         $command = new \FooLockCommand();
41
42         $lock = new LockHandler($command->getName());
43         $lock->lock();
44
45         $tester = new CommandTester($command);
46         $this->assertSame(1, $tester->execute(array()));
47
48         $lock->release();
49         $this->assertSame(2, $tester->execute(array()));
50     }
51
52     public function testMultipleLockCallsThrowLogicException()
53     {
54         $command = new \FooLock2Command();
55
56         $tester = new CommandTester($command);
57         $this->assertSame(1, $tester->execute(array()));
58     }
59 }