Add PHP unit tests
Check\* Combined\* Convert\* Create\Hash (stub)
This commit is contained in:
@@ -7,40 +7,42 @@ namespace tests;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
/**
|
||||
* Undocumented class
|
||||
* Test class for Check\File
|
||||
* @testdox CoreLibs\Check\File method tests
|
||||
*/
|
||||
final class CoreLibsCheckFileTest extends TestCase
|
||||
{
|
||||
/** @var array<mixed> */
|
||||
private $files = [];
|
||||
|
||||
protected function setUp(): void
|
||||
{
|
||||
// write a dummy files for testing
|
||||
}
|
||||
|
||||
protected function tearDown(): void
|
||||
{
|
||||
// unlink files
|
||||
}
|
||||
// private $files_list = [];
|
||||
/** @var string */
|
||||
private $base_folder = DIRECTORY_SEPARATOR . 'tmp' . DIRECTORY_SEPARATOR;
|
||||
|
||||
/**
|
||||
* main file list + data provider
|
||||
*
|
||||
* filename, file extension matching, lines in file, -1 for nothing
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function filesList(): array
|
||||
{
|
||||
return [
|
||||
['filename.txt', 'txt', 5]
|
||||
['filename.txt', 'txt', 5],
|
||||
['filename.csv', 'csv', 15],
|
||||
['filename.tsv', 'tsv', 0],
|
||||
['file_does_not_exits', '', -1],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Undocumented function
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function filesExtensionProvider(): array
|
||||
{
|
||||
$list = [];
|
||||
foreach ($this->filesList as $row) {
|
||||
foreach ($this->filesList() as $row) {
|
||||
$list[$row[0] . ' must be extension ' . $row[1]] = [$row[0], $row[1]];
|
||||
}
|
||||
return $list;
|
||||
@@ -49,40 +51,66 @@ final class CoreLibsCheckFileTest extends TestCase
|
||||
/**
|
||||
* Undocumented function
|
||||
*
|
||||
* @#dataProvider filesExtensionProvider
|
||||
* @#testdox File::getFilenameEnding Input $input must be $expected
|
||||
* //string $input, string $expected
|
||||
* @return array
|
||||
*/
|
||||
public function filesLinesProvider(): array
|
||||
{
|
||||
$list = [];
|
||||
foreach ($this->filesList() as $row) {
|
||||
$list[$row[0] . ' must have ' . $row[2] . ' lines'] = [$row[0], $row[2]];
|
||||
}
|
||||
return $list;
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests if file extension matches
|
||||
*
|
||||
* @param string $input
|
||||
* @param string $expected
|
||||
* @dataProvider filesExtensionProvider
|
||||
* @testdox getFilenameEnding $input must be extension $expected [$_dataName]
|
||||
*
|
||||
* @param string $input
|
||||
* @param string $expected
|
||||
* @return void
|
||||
*/
|
||||
public function testGetFilenameEnding(): void
|
||||
public function testGetFilenameEnding(string $input, string $expected): void
|
||||
{
|
||||
// getFilenameEnding
|
||||
/* $this->assertEquals(
|
||||
$this->assertEquals(
|
||||
$expected,
|
||||
\CoreLibs\Check\File::getFilenameEnding($input)
|
||||
); */
|
||||
$this->assertTrue(true, 'This should already work.');
|
||||
$this->markTestIncomplete(
|
||||
'testGetFilenameEnding has not been implemented yet.'
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Undocumented function
|
||||
* // string $input, string $expected
|
||||
* Tests the file line read
|
||||
*
|
||||
* @dataProvider filesLinesProvider
|
||||
* @testdox getLinesFromFile $input must have $expected lines [$_dataName]
|
||||
*
|
||||
* @param string $input file name
|
||||
* @param int $expected lines in file
|
||||
* @return void
|
||||
*/
|
||||
public function testGetLinesFromFile(): void
|
||||
public function testGetLinesFromFile(string $input, int $expected): void
|
||||
{
|
||||
// getLinesFromFile
|
||||
$this->assertTrue(true, 'This should already work.');
|
||||
$this->markTestIncomplete(
|
||||
'testGetLinesFromFile has not been implemented yet.'
|
||||
// create file
|
||||
if ($expected > -1) {
|
||||
$file = $this->base_folder . $input;
|
||||
$fp = fopen($file, 'w');
|
||||
for ($i = 0; $i < $expected; $i++) {
|
||||
fwrite($fp, 'This is row ' . ($i + 1) . PHP_EOL);
|
||||
}
|
||||
fclose($fp);
|
||||
}
|
||||
// test
|
||||
$this->assertEquals(
|
||||
$expected,
|
||||
\CoreLibs\Check\File::getLinesFromFile($this->base_folder . $input)
|
||||
);
|
||||
// unlink file
|
||||
if (is_file($this->base_folder . $input)) {
|
||||
unlink($this->base_folder . $input);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user