Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit12b0f44

Browse files
Add tests
1 parent11d7396 commit12b0f44

File tree

3 files changed

+51
-9
lines changed

3 files changed

+51
-9
lines changed

‎src/Symfony/Component/Console/Command/LockableTrait.php‎

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -28,15 +28,6 @@ trait LockableTrait
2828

2929
private ?LockFactory$lockFactory =null;
3030

31-
publicfunctionsetLockFactory(?LockFactory$lockFactory):void
32-
{
33-
if (null !==$this->lock) {
34-
thrownewLogicException('You cannot set the lockFactory if a lock is already in place.');
35-
}
36-
37-
$this->lockFactory =$lockFactory;
38-
}
39-
4031
/**
4132
* Locks a command.
4233
*/

‎src/Symfony/Component/Console/Tests/Command/LockableTraitTest.php‎

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
usePHPUnit\Framework\TestCase;
1515
useSymfony\Component\Console\Tester\CommandTester;
1616
useSymfony\Component\Lock\LockFactory;
17+
useSymfony\Component\Lock\LockInterface;
1718
useSymfony\Component\Lock\Store\FlockStore;
1819
useSymfony\Component\Lock\Store\SemaphoreStore;
1920

@@ -26,6 +27,7 @@ public static function setUpBeforeClass(): void
2627
self::$fixturesPath =__DIR__.'/../Fixtures/';
2728
require_onceself::$fixturesPath.'/FooLockCommand.php';
2829
require_onceself::$fixturesPath.'/FooLock2Command.php';
30+
require_onceself::$fixturesPath.'/FooLock3Command.php';
2931
}
3032

3133
publicfunctiontestLockIsReleased()
@@ -64,4 +66,18 @@ public function testMultipleLockCallsThrowLogicException()
6466
$tester =newCommandTester($command);
6567
$this->assertSame(1,$tester->execute([]));
6668
}
69+
70+
publicfunctiontestCustomLockFactoryIsUsed()
71+
{
72+
$lockFactory =$this->createMock(LockFactory::class);
73+
$command =new \FooLock3Command($lockFactory);
74+
75+
$tester =newCommandTester($command);
76+
77+
$lock =$this->createMock(LockInterface::class);
78+
$lock->method('acquire')->willReturn(false);
79+
80+
$lockFactory->expects(static::once())->method('createLock')->willReturn($lock);
81+
$this->assertSame(1,$tester->execute([]));
82+
}
6783
}
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
<?php
2+
3+
useSymfony\Component\Console\Command\Command;
4+
useSymfony\Component\Console\Command\LockableTrait;
5+
useSymfony\Component\Console\Input\InputInterface;
6+
useSymfony\Component\Console\Output\OutputInterface;
7+
useSymfony\Component\Lock\LockFactory;
8+
9+
class FooLock3Commandextends Command
10+
{
11+
use LockableTrait;
12+
13+
publicfunction__construct(LockFactory$lockFactory)
14+
{
15+
parent::__construct();
16+
17+
$this->lockFactory =$lockFactory;
18+
}
19+
20+
protectedfunctionconfigure():void
21+
{
22+
$this->setName('foo:lock3');
23+
}
24+
25+
protectedfunctionexecute(InputInterface$input,OutputInterface$output):int
26+
{
27+
if (!$this->lock()) {
28+
return1;
29+
}
30+
31+
$this->release();
32+
33+
return2;
34+
}
35+
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp