a622d1b4895f588f036ea3454978fbe018745ad1
[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\Lock\Factory;
17 use Symfony\Component\Lock\Store\FlockStore;
18 use Symfony\Component\Lock\Store\SemaphoreStore;
19
20 class LockableTraitTest extends TestCase
21 {
22     protected static $fixturesPath;
23
24     public static function setUpBeforeClass()
25     {
26         self::$fixturesPath = __DIR__.'/../Fixtures/';
27         require_once self::$fixturesPath.'/FooLockCommand.php';
28         require_once self::$fixturesPath.'/FooLock2Command.php';
29     }
30
31     public function testLockIsReleased()
32     {
33         $command = new \FooLockCommand();
34
35         $tester = new CommandTester($command);
36         $this->assertSame(2, $tester->execute(array()));
37         $this->assertSame(2, $tester->execute(array()));
38     }
39
40     public function testLockReturnsFalseIfAlreadyLockedByAnotherCommand()
41     {
42         $command = new \FooLockCommand();
43
44         if (SemaphoreStore::isSupported(false)) {
45             $store = new SemaphoreStore();
46         } else {
47             $store = new FlockStore();
48         }
49
50         $lock = (new Factory($store))->createLock($command->getName());
51         $lock->acquire();
52
53         $tester = new CommandTester($command);
54         $this->assertSame(1, $tester->execute(array()));
55
56         $lock->release();
57         $this->assertSame(2, $tester->execute(array()));
58     }
59
60     public function testMultipleLockCallsThrowLogicException()
61     {
62         $command = new \FooLock2Command();
63
64         $tester = new CommandTester($command);
65         $this->assertSame(1, $tester->execute(array()));
66     }
67 }