LockableTraitTest.php 1.6 KB

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