-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathFileSystemDataStoreTest.php
More file actions
132 lines (116 loc) · 3.53 KB
/
FileSystemDataStoreTest.php
File metadata and controls
132 lines (116 loc) · 3.53 KB
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
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
<?php
namespace Packaged\Dal\Tests\FileSystem;
use Exception;
use Packaged\Dal\DalResolver;
use Packaged\Dal\Exceptions\DataStore\DaoNotFoundException;
use Packaged\Dal\Exceptions\DataStore\DataStoreException;
use Packaged\Dal\FileSystem\FileSystemDao;
use Packaged\Dal\FileSystem\FileSystemDataStore;
use Packaged\Dal\Foundation\AbstractDao;
use Packaged\Dal\Foundation\Dao;
use Packaged\Helpers\Path;
use PHPUnit\Framework\TestCase;
class FileSystemDataStoreTest extends TestCase
{
protected function _getResourceLocation($filename)
{
return Path::system(dirname(__DIR__), 'resources', 'FileSystem', $filename);
}
protected function setUp(): void
{
$resolver = new DalResolver();
$resolver->boot();
}
protected function tearDown(): void
{
Dao::unsetDalResolver();
}
public function testIdProperty()
{
$mock = new FileSystemDao();
$this->assertEquals(['filepath'], $mock->getDaoIDProperties());
}
public function testLoad()
{
$file = new FileSystemDao($this->_getResourceLocation('fs.test'));
$this->assertFalse($file->isDaoLoaded());
$this->assertTrue($file->exists());
$file->load();
$this->assertTrue($file->isDaoLoaded());
}
public function testExceptionMissingFile()
{
$this->expectException(DaoNotFoundException::class);
$file = new FileSystemDao(
Path::system(dirname(dirname(__DIR__)), 'missing.file')
);
$file->load();
}
public function testInvalidFilesystemDao()
{
$this->expectException(DataStoreException::class);
$dao = $this->getMockForAbstractClass(AbstractDao::class);
$fs = new FileSystemDataStore();
$fs->load($dao);
}
public function testFilePathInfo()
{
$file = new FileSystemDao(
$this->_getResourceLocation('fs.test')
);
$this->assertEquals('test', $file->getExtension());
$this->assertEquals('fs', $file->getFilename());
$this->assertEquals('fs.test', $file->getBasename());
$this->assertEquals($this->_getResourceLocation(''), $file->getDirectory());
$this->assertEquals(
$this->_getResourceLocation('fs.test'),
$file->getFilePath()
);
}
public function testFileSize()
{
$file = new FileSystemDao($this->_getResourceLocation('filesize.test'));
$file->load();
$this->assertEquals(14, $file->getFileSize());
}
public function testFilesizeWithoutLoad()
{
$file = new FileSystemDao($this->_getResourceLocation('filesize.test'));
$this->assertEquals(14, $file->getFileSize());
}
public function testFilesizeWithoutLoadException()
{
$this->expectException(DaoNotFoundException::class);
$file = new FileSystemDao($this->_getResourceLocation('filesize.missing'));
$file->getFileSize();
}
public function testFileCRUD()
{
$crudLoc = $this->_getResourceLocation('crud.test');
$file = new FileSystemDao($crudLoc);
try
{
$file->load();
$this->assertFalse(true, "crud.test file exists, and shouldn't");
}
catch(Exception $e)
{
$this->assertEquals(404, $e->getCode());
}
$file->content = 'Test Content';
$file->save();
$file = null;
$file = new FileSystemDao($crudLoc);
$file->load();
$this->assertEquals('Test Content', $file->content);
$this->assertEquals('Test Content', $file->getContent());
$this->assertFileExists($crudLoc);
$file->delete();
$this->assertFileNotExists($crudLoc);
}
public function testStaticOpen()
{
$file = FileSystemDao::open($this->_getResourceLocation('fs.test'));
$this->assertEquals("content\n", $file->getContent());
}
}