mirror of
https://github.com/fadlee/bigdump.git
synced 2025-10-28 22:17:33 +01:00
I have modernized the BigDump script, refactoring it into a modern PHP application.
I've converted the original `bigdump.php` script into an object-oriented application with a clear separation of concerns. Key changes include: - A new directory structure (`src`, `public`, `templates`, `config`). - Object-oriented code with classes for `Configuration`, `Database`, `FileHandler`, and `Dumper`. - Separation of HTML, CSS, and JavaScript from the PHP logic. - Improved security by mitigating XSS and file path traversal risks. - A new `README.md` with updated instructions. - Unit tests for the core classes (written but not run due to environment constraints).
This commit is contained in:
50
tests/FileHandlerTest.php
Normal file
50
tests/FileHandlerTest.php
Normal file
@@ -0,0 +1,50 @@
|
||||
<?php
|
||||
|
||||
use BigDump\Configuration;
|
||||
use BigDump\FileHandler;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
class FileHandlerTest extends TestCase
|
||||
{
|
||||
private $config;
|
||||
private $fileHandler;
|
||||
private $testFile;
|
||||
private $uploadDir;
|
||||
|
||||
protected function setUp(): void
|
||||
{
|
||||
$this->config = new Configuration();
|
||||
$this->fileHandler = new FileHandler($this->config);
|
||||
$this->uploadDir = $this->config->upload_dir;
|
||||
$this->testFile = $this->uploadDir . '/test.sql';
|
||||
|
||||
if (!is_dir($this->uploadDir)) {
|
||||
mkdir($this->uploadDir, 0777, true);
|
||||
}
|
||||
file_put_contents($this->testFile, 'test data');
|
||||
}
|
||||
|
||||
protected function tearDown(): void
|
||||
{
|
||||
if (file_exists($this->testFile)) {
|
||||
unlink($this->testFile);
|
||||
}
|
||||
// Small cleanup: remove data dir if empty
|
||||
if (is_dir($this->uploadDir) && count(scandir($this->uploadDir)) == 2) {
|
||||
rmdir($this->uploadDir);
|
||||
}
|
||||
}
|
||||
|
||||
public function testGetAvailableDumps()
|
||||
{
|
||||
$dumps = $this->fileHandler->getAvailableDumps();
|
||||
$this->assertCount(1, $dumps);
|
||||
$this->assertEquals('test.sql', $dumps[0]['name']);
|
||||
}
|
||||
|
||||
public function testDeleteFile()
|
||||
{
|
||||
$this->fileHandler->deleteFile('test.sql');
|
||||
$this->assertFileDoesNotExist($this->testFile);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user