mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-09-01 04:23:49 +00:00
re-implements document lock manager for wopi
This commit is contained in:
@@ -0,0 +1,78 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Chill is a software for social workers
|
||||
*
|
||||
* For the full copyright and license information, please view
|
||||
* the LICENSE file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Chill\WopiBundle\Tests\Service\Wopi;
|
||||
|
||||
use Chill\DocStoreBundle\Entity\StoredObject;
|
||||
use Chill\MainBundle\Redis\ChillRedis;
|
||||
use Chill\WopiBundle\Service\Wopi\ChillDocumentLockManager;
|
||||
use Prophecy\PhpUnit\ProphecyTrait;
|
||||
use Psr\Http\Message\RequestInterface;
|
||||
use Symfony\Bundle\FrameworkBundle\Test\KernelTestCase;
|
||||
|
||||
/**
|
||||
* @internal
|
||||
* @coversNothing
|
||||
*/
|
||||
final class ChillDocumentLockManagerTest extends KernelTestCase
|
||||
{
|
||||
use ProphecyTrait;
|
||||
|
||||
protected function setUp(): void
|
||||
{
|
||||
self::bootKernel();
|
||||
}
|
||||
|
||||
public function testMultipleLoops()
|
||||
{
|
||||
$manager = $this->makeManager(1);
|
||||
$document = new StoredObject();
|
||||
$request = $this->prophesize(RequestInterface::class);
|
||||
|
||||
$i = 0;
|
||||
|
||||
while (50 > ++$i) {
|
||||
$this->assertFalse($manager->hasLock($document, $request->reveal()));
|
||||
|
||||
$this->assertTrue($manager->setLock($document, 'dummy', $request->reveal()));
|
||||
|
||||
$this->assertEquals('dummy', $manager->getLock($document, $request->reveal()));
|
||||
|
||||
$this->assertTrue($manager->deleteLock($document, $request->reveal()));
|
||||
|
||||
$this->assertFalse($manager->hasLock($document, $request->reveal()));
|
||||
}
|
||||
}
|
||||
|
||||
public function testSingleLock()
|
||||
{
|
||||
$manager = $this->makeManager(1);
|
||||
$document = new StoredObject();
|
||||
$request = $this->prophesize(RequestInterface::class);
|
||||
|
||||
$this->assertFalse($manager->hasLock($document, $request->reveal()));
|
||||
|
||||
$this->assertTrue($manager->setLock($document, 'dummy', $request->reveal()));
|
||||
|
||||
$this->assertEquals('dummy', $manager->getLock($document, $request->reveal()));
|
||||
|
||||
$this->assertTrue($manager->deleteLock($document, $request->reveal()));
|
||||
|
||||
$this->assertFalse($manager->hasLock($document, $request->reveal()));
|
||||
}
|
||||
|
||||
private function makeManager(int $ttlAfterDeleteSeconds): ChillDocumentLockManager
|
||||
{
|
||||
$redis = self::$container->get(ChillRedis::class);
|
||||
|
||||
return new ChillDocumentLockManager($redis, $ttlAfterDeleteSeconds);
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user