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\Filesystem\LockHandler;
18 class LockableTraitTest extends TestCase
20 protected static $fixturesPath;
22 public static function setUpBeforeClass()
24 self::$fixturesPath = __DIR__.'/../Fixtures/';
25 require_once self::$fixturesPath.'/FooLockCommand.php';
26 require_once self::$fixturesPath.'/FooLock2Command.php';
29 public function testLockIsReleased()
31 $command = new \FooLockCommand();
33 $tester = new CommandTester($command);
34 $this->assertSame(2, $tester->execute(array()));
35 $this->assertSame(2, $tester->execute(array()));
38 public function testLockReturnsFalseIfAlreadyLockedByAnotherCommand()
40 $command = new \FooLockCommand();
42 $lock = new LockHandler($command->getName());
45 $tester = new CommandTester($command);
46 $this->assertSame(1, $tester->execute(array()));
49 $this->assertSame(2, $tester->execute(array()));
52 public function testMultipleLockCallsThrowLogicException()
54 $command = new \FooLock2Command();
56 $tester = new CommandTester($command);
57 $this->assertSame(1, $tester->execute(array()));