菜谱项目

LockableTraitTest.php 1.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  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 PHPUnit\Framework\TestCase;
  12. use Symfony\Component\Console\Tester\CommandTester;
  13. use Symfony\Component\Filesystem\LockHandler;
  14. class LockableTraitTest extends TestCase
  15. {
  16. protected static $fixturesPath;
  17. public static function setUpBeforeClass()
  18. {
  19. self::$fixturesPath = __DIR__.'/../Fixtures/';
  20. require_once self::$fixturesPath.'/FooLockCommand.php';
  21. require_once self::$fixturesPath.'/FooLock2Command.php';
  22. }
  23. public function testLockIsReleased()
  24. {
  25. $command = new \FooLockCommand();
  26. $tester = new CommandTester($command);
  27. $this->assertSame(2, $tester->execute(array()));
  28. $this->assertSame(2, $tester->execute(array()));
  29. }
  30. public function testLockReturnsFalseIfAlreadyLockedByAnotherCommand()
  31. {
  32. $command = new \FooLockCommand();
  33. $lock = new LockHandler($command->getName());
  34. $lock->lock();
  35. $tester = new CommandTester($command);
  36. $this->assertSame(1, $tester->execute(array()));
  37. $lock->release();
  38. $this->assertSame(2, $tester->execute(array()));
  39. }
  40. public function testMultipleLockCallsThrowLogicException()
  41. {
  42. $command = new \FooLock2Command();
  43. $tester = new CommandTester($command);
  44. $this->assertSame(1, $tester->execute(array()));
  45. }
  46. }