-
-
Notifications
You must be signed in to change notification settings - Fork 15
/
Copy pathFlockStoreTest.php
104 lines (82 loc) · 2.91 KB
/
FlockStoreTest.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
<?php
/*
* This file is part of the Symfony package.
*
* (c) Fabien Potencier <fabien@symfony.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Symfony\Component\Lock\Tests\Store;
use Symfony\Component\Lock\Exception\InvalidArgumentException;
use Symfony\Component\Lock\Key;
use Symfony\Component\Lock\PersistingStoreInterface;
use Symfony\Component\Lock\Store\FlockStore;
/**
* @author Jérémy Derussé <jeremy@derusse.com>
*/
class FlockStoreTest extends AbstractStoreTestCase
{
use BlockingStoreTestTrait;
use SharedLockStoreTestTrait;
use UnserializableTestTrait;
protected function getStore(): PersistingStoreInterface
{
return new FlockStore();
}
public function testConstructWhenRepositoryCannotBeCreated()
{
$this->expectException(InvalidArgumentException::class);
$this->expectExceptionMessage('The FlockStore directory "/a/b/c/d/e" does not exists and cannot be created.');
if (!getenv('USER') || 'root' === getenv('USER')) {
$this->markTestSkipped('This test will fail if run under superuser');
}
new FlockStore('/a/b/c/d/e');
}
public function testConstructWhenRepositoryIsNotWriteable()
{
$this->expectException(InvalidArgumentException::class);
$this->expectExceptionMessage('The FlockStore directory "/" is not writable.');
if (!getenv('USER') || 'root' === getenv('USER')) {
$this->markTestSkipped('This test will fail if run under superuser');
}
new FlockStore('/');
}
public function testConstructWithSubdir()
{
new FlockStore($dir = (sys_get_temp_dir().'/sf-flock'));
$this->assertDirectoryExists($dir);
// cleanup
@rmdir($dir);
}
public function testSaveSanitizeName()
{
$store = $this->getStore();
$key = new Key('<?php echo "% hello word ! %" ?>');
$file = \sprintf(
'%s/sf.-php-echo-hello-word-.%s.lock',
sys_get_temp_dir(),
strtr(substr(base64_encode(hash('sha256', $key, true)), 0, 7), '/', '_')
);
// ensure the file does not exist before the store
@unlink($file);
$store->save($key);
$this->assertFileExists($file);
$store->delete($key);
}
public function testSaveSanitizeLongName()
{
$store = $this->getStore();
$key = new Key(str_repeat(__CLASS__, 100));
$file = \sprintf(
'%s/sf.Symfony-Component-Lock-Tests-Store-FlockStoreTestS.%s.lock',
sys_get_temp_dir(),
strtr(substr(base64_encode(hash('sha256', $key, true)), 0, 7), '/', '_')
);
// ensure the file does not exist before the store
@unlink($file);
$store->save($key);
$this->assertFileExists($file);
$store->delete($key);
}
}