Skip to content

Commit 6633cc2

Browse files
committed
Covered unit test
1 parent e59ee3a commit 6633cc2

File tree

1 file changed

+64
-0
lines changed
  • lib/internal/Magento/Framework/Lock/Test/Unit/Backend

1 file changed

+64
-0
lines changed
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
declare(strict_types=1);
7+
8+
namespace Magento\Framework\Lock\Test\Unit\Backend;
9+
10+
use Magento\Framework\Cache\FrontendInterface;
11+
use Magento\Framework\Lock\Backend\Cache;
12+
use Magento\Framework\TestFramework\Unit\Helper\ObjectManager as ObjectManagerHelper;
13+
use PHPUnit\Framework\MockObject\MockObject;
14+
use PHPUnit\Framework\TestCase;
15+
16+
class CacheTest extends TestCase
17+
{
18+
const LOCK_PREFIX = 'LOCKED_RECORD_INFO_';
19+
20+
/**
21+
* @var FrontendInterface|MockObject
22+
*/
23+
private $frontendCacheMock;
24+
25+
/**
26+
* @var Cache
27+
*/
28+
private $cache;
29+
30+
/**
31+
* @inheritDoc
32+
*/
33+
public function setUp()
34+
{
35+
$this->frontendCacheMock = $this->createMock(FrontendInterface::class);
36+
37+
$objectManager = new ObjectManagerHelper($this);
38+
39+
$this->cache = $objectManager->getObject(
40+
Cache::class,
41+
[
42+
'cache' => $this->frontendCacheMock
43+
]
44+
);
45+
}
46+
47+
/**
48+
* Verify released a lock.
49+
*
50+
* @return void
51+
*/
52+
public function testUnlock(): void
53+
{
54+
$identifier = 'lock_name';
55+
56+
$this->frontendCacheMock
57+
->expects($this->once())
58+
->method('remove')
59+
->with(self::LOCK_PREFIX . $identifier)
60+
->willReturn(true);
61+
62+
$this->assertEquals(true, $this->cache->unlock($identifier));
63+
}
64+
}

0 commit comments

Comments
 (0)