|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace SourcesTests\Files\Volume; |
|
4
|
|
|
|
|
5
|
|
|
|
|
6
|
|
|
use CommonTestClass; |
|
7
|
|
|
use kalanis\kw_auth\AuthException; |
|
8
|
|
|
use kalanis\kw_auth\Sources; |
|
9
|
|
|
use kalanis\kw_auth\Translations; |
|
10
|
|
|
|
|
11
|
|
|
|
|
12
|
|
|
class BasicTest extends CommonTestClass |
|
13
|
|
|
{ |
|
14
|
|
|
protected $sourcePath = ''; |
|
15
|
|
|
protected $testingPath = ''; |
|
16
|
|
|
|
|
17
|
|
|
protected function setUp(): void |
|
18
|
|
|
{ |
|
19
|
|
|
$this->sourcePath = __DIR__ . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR . 'data' . DIRECTORY_SEPARATOR . '.groups'; |
|
20
|
|
|
$this->testingPath = __DIR__ . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR . 'data' . DIRECTORY_SEPARATOR . '.groups-duplicate'; |
|
21
|
|
|
} |
|
22
|
|
|
|
|
23
|
|
|
protected function tearDown(): void |
|
24
|
|
|
{ |
|
25
|
|
|
if (is_file($this->testingPath)) { |
|
26
|
|
|
unlink($this->testingPath); |
|
27
|
|
|
} |
|
28
|
|
|
} |
|
29
|
|
|
|
|
30
|
|
|
/** |
|
31
|
|
|
* @throws AuthException |
|
32
|
|
|
*/ |
|
33
|
|
|
public function testFiles(): void |
|
34
|
|
|
{ |
|
35
|
|
|
$lib = new MockFiles(); |
|
36
|
|
|
$lib->setLang(new Translations()); |
|
37
|
|
|
$content = $lib->open($this->sourcePath); |
|
38
|
|
|
$this->assertNotEmpty($content); |
|
39
|
|
|
$lib->save($this->testingPath, $content); |
|
40
|
|
|
chmod($this->testingPath, 0444); |
|
41
|
|
|
$this->expectException(AuthException::class); |
|
42
|
|
|
$lib->save($this->testingPath, $content); |
|
43
|
|
|
} |
|
44
|
|
|
|
|
45
|
|
|
/** |
|
46
|
|
|
* @throws AuthException |
|
47
|
|
|
*/ |
|
48
|
|
|
public function testFilesOpenCrash(): void |
|
49
|
|
|
{ |
|
50
|
|
|
$lib = new MockFiles(); |
|
51
|
|
|
$lib->setLang(new Translations()); |
|
52
|
|
|
$this->expectException(AuthException::class); |
|
53
|
|
|
$lib->open($this->testingPath); |
|
54
|
|
|
} |
|
55
|
|
|
} |
|
56
|
|
|
|
|
57
|
|
|
|
|
58
|
|
|
class MockFiles |
|
59
|
|
|
{ |
|
60
|
|
|
use Sources\Files\Volume\TVolume; |
|
61
|
|
|
use Sources\Files\TLines; |
|
62
|
|
|
|
|
63
|
|
|
/** |
|
64
|
|
|
* @param string $path |
|
65
|
|
|
* @throws AuthException |
|
66
|
|
|
* @return string[][] |
|
67
|
|
|
*/ |
|
68
|
|
|
public function open(string $path): array |
|
69
|
|
|
{ |
|
70
|
|
|
return $this->openFile($path); |
|
71
|
|
|
} |
|
72
|
|
|
|
|
73
|
|
|
/** |
|
74
|
|
|
* @param string $path |
|
75
|
|
|
* @param string[][] $content |
|
76
|
|
|
* @throws AuthException |
|
77
|
|
|
*/ |
|
78
|
|
|
public function save(string $path, array $content): void |
|
79
|
|
|
{ |
|
80
|
|
|
$this->saveFile($path, $content); |
|
81
|
|
|
} |
|
82
|
|
|
} |
|
83
|
|
|
|