mirror of
https://github.com/phpbb/phpbb.git
synced 2025-08-09 10:16:36 +02:00
[ticket/16639] Add types and small changes in tests
PHPBB3-16639
This commit is contained in:
@@ -11,103 +11,141 @@
|
||||
*
|
||||
*/
|
||||
|
||||
class phpbb_storage_adapter_local_test extends phpbb_test_case
|
||||
{
|
||||
protected $adapter;
|
||||
|
||||
protected $path;
|
||||
|
||||
protected $filesystem;
|
||||
require_once __DIR__ . '/local_test_case.php';
|
||||
|
||||
class phpbb_storage_adapter_local_test extends phpbb_local_test_case
|
||||
{
|
||||
protected function setUp(): void
|
||||
{
|
||||
parent::setUp();
|
||||
|
||||
$this->filesystem = new \phpbb\filesystem\filesystem();
|
||||
$phpbb_root_path = getcwd() . DIRECTORY_SEPARATOR;
|
||||
|
||||
$this->adapter = new \phpbb\storage\adapter\local($this->filesystem, new \FastImageSize\FastImageSize(), new \phpbb\mimetype\guesser(array(new \phpbb\mimetype\extension_guesser)), $phpbb_root_path);
|
||||
$this->adapter->configure(['path' => 'test_path', 'subfolders' => false]);
|
||||
|
||||
$this->path = $phpbb_root_path . 'test_path/';
|
||||
mkdir($this->path);
|
||||
}
|
||||
|
||||
protected function tearDown(): void
|
||||
{
|
||||
$this->adapter = null;
|
||||
rmdir($this->path);
|
||||
}
|
||||
|
||||
public function test_put_contents()
|
||||
public function test_put_contents(): void
|
||||
{
|
||||
// When
|
||||
$this->adapter->put_contents('file.txt', 'abc');
|
||||
$this->assertTrue(file_exists($this->path . 'file.txt'));
|
||||
$this->assertEquals(file_get_contents($this->path . 'file.txt'), 'abc');
|
||||
|
||||
// Then
|
||||
$this->assertFileExists($this->path . 'file.txt');
|
||||
$this->assertFileContains($this->path . 'file.txt', 'abc');
|
||||
|
||||
// Clean test
|
||||
unlink($this->path . 'file.txt');
|
||||
}
|
||||
|
||||
public function test_get_contents()
|
||||
public function test_get_contents(): void
|
||||
{
|
||||
// Given
|
||||
file_put_contents($this->path . 'file.txt', 'abc');
|
||||
$this->assertEquals($this->adapter->get_contents('file.txt'), 'abc');
|
||||
|
||||
// When
|
||||
$content = $this->adapter->get_contents('file.txt');
|
||||
|
||||
// Then
|
||||
$this->assertEquals('abc', $content);
|
||||
|
||||
// Clean test
|
||||
unlink($this->path . 'file.txt');
|
||||
}
|
||||
|
||||
public function test_exists()
|
||||
public function test_exists(): void
|
||||
{
|
||||
// Given
|
||||
touch($this->path . 'file.txt');
|
||||
$this->assertTrue($this->adapter->exists('file.txt'));
|
||||
$this->assertFalse($this->adapter->exists('noexist.txt'));
|
||||
|
||||
// When
|
||||
$existent_file = $this->adapter->exists('file.txt');
|
||||
$non_existent_file = $this->adapter->exists('noexist.txt');
|
||||
|
||||
// Then
|
||||
$this->assertTrue($existent_file);
|
||||
$this->assertFalse($non_existent_file);
|
||||
|
||||
// Clean test
|
||||
unlink($this->path . 'file.txt');
|
||||
}
|
||||
|
||||
public function test_delete_file()
|
||||
public function test_delete_file(): void
|
||||
{
|
||||
// Given
|
||||
touch($this->path . 'file.txt');
|
||||
$this->assertTrue(file_exists($this->path . 'file.txt'));
|
||||
$this->assertFileExists($this->path . 'file.txt');
|
||||
|
||||
// When
|
||||
$this->adapter->delete('file.txt');
|
||||
$this->assertFalse(file_exists($this->path . 'file.txt'));
|
||||
|
||||
// Then
|
||||
$this->assertFileNotExists($this->path . 'file.txt');
|
||||
}
|
||||
|
||||
public function test_rename()
|
||||
public function test_rename(): void
|
||||
{
|
||||
// Given
|
||||
touch($this->path . 'file.txt');
|
||||
$this->assertFileExists($this->path . 'file.txt');
|
||||
$this->assertFileNotExists($this->path . 'file2.txt');
|
||||
|
||||
// When
|
||||
$this->adapter->rename('file.txt', 'file2.txt');
|
||||
$this->assertFalse(file_exists($this->path . 'file.txt'));
|
||||
$this->assertTrue(file_exists($this->path . 'file2.txt'));
|
||||
$this->assertFalse(file_exists($this->path . 'file.txt'));
|
||||
|
||||
// Then
|
||||
$this->assertFileNotExists($this->path . 'file.txt');
|
||||
$this->assertFileExists($this->path . 'file2.txt');
|
||||
|
||||
// Clean test
|
||||
unlink($this->path . 'file2.txt');
|
||||
}
|
||||
|
||||
public function test_copy()
|
||||
public function test_copy(): void
|
||||
{
|
||||
// Given
|
||||
file_put_contents($this->path . 'file.txt', 'abc');
|
||||
|
||||
// When
|
||||
$this->adapter->copy('file.txt', 'file2.txt');
|
||||
$this->assertEquals(file_get_contents($this->path . 'file.txt'), 'abc');
|
||||
$this->assertEquals(file_get_contents($this->path . 'file2.txt'), 'abc');
|
||||
|
||||
// Then
|
||||
$this->assertFileContains($this->path . 'file.txt', 'abc');
|
||||
$this->assertFileContains($this->path . 'file2.txt', 'abc');
|
||||
|
||||
// Clean test
|
||||
unlink($this->path . 'file.txt');
|
||||
unlink($this->path . 'file2.txt');
|
||||
}
|
||||
|
||||
public function test_read_stream()
|
||||
{
|
||||
// Given
|
||||
touch($this->path . 'file.txt');
|
||||
|
||||
// When
|
||||
$stream = $this->adapter->read_stream('file.txt');
|
||||
$this->assertTrue(is_resource($stream));
|
||||
|
||||
// Then
|
||||
$this->assertIsResource($stream);
|
||||
|
||||
// Clean test
|
||||
fclose($stream);
|
||||
unlink($this->path . 'file.txt');
|
||||
}
|
||||
|
||||
public function test_write_stream()
|
||||
{
|
||||
// Given
|
||||
file_put_contents($this->path . 'file.txt', 'abc');
|
||||
$stream = fopen($this->path . 'file.txt', 'rb');
|
||||
|
||||
// When
|
||||
$this->adapter->write_stream('file2.txt', $stream);
|
||||
fclose($stream);
|
||||
$this->assertEquals(file_get_contents($this->path . 'file2.txt'), 'abc');
|
||||
|
||||
// Then
|
||||
$this->assertFileContains($this->path . 'file2.txt', 'abc');
|
||||
|
||||
// Clean test
|
||||
unlink($this->path . 'file.txt');
|
||||
unlink($this->path . 'file2.txt');
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user