4 * This file is part of the Symfony package.
6 * (c) Fabien Potencier <fabien@symfony.com>
8 * For the full copyright and license information, please view the LICENSE
9 * file that was distributed with this source code.
12 namespace Symfony\Component\Console\Tests\Command;
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;
20 class LockableTraitTest extends TestCase
22 protected static $fixturesPath;
24 public static function setUpBeforeClass()
26 self::$fixturesPath = __DIR__.'/../Fixtures/';
27 require_once self::$fixturesPath.'/FooLockCommand.php';
28 require_once self::$fixturesPath.'/FooLock2Command.php';
31 public function testLockIsReleased()
33 $command = new \FooLockCommand();
35 $tester = new CommandTester($command);
36 $this->assertSame(2, $tester->execute(array()));
37 $this->assertSame(2, $tester->execute(array()));
40 public function testLockReturnsFalseIfAlreadyLockedByAnotherCommand()
42 $command = new \FooLockCommand();
44 if (SemaphoreStore::isSupported(false)) {
45 $store = new SemaphoreStore();
47 $store = new FlockStore();
50 $lock = (new Factory($store))->createLock($command->getName());
53 $tester = new CommandTester($command);
54 $this->assertSame(1, $tester->execute(array()));
57 $this->assertSame(2, $tester->execute(array()));
60 public function testMultipleLockCallsThrowLogicException()
62 $command = new \FooLock2Command();
64 $tester = new CommandTester($command);
65 $this->assertSame(1, $tester->execute(array()));