[Miscellaneous] [Regex] Implement data providers in tests

This commit is contained in:
Meritoo
2019-12-18 20:32:21 +01:00
parent ddb3f0a544
commit 5cd58aec25
3 changed files with 227 additions and 48 deletions

View File

@@ -244,16 +244,16 @@ class RegexTest extends BaseTestCase
self::assertTrue(Regex::contains($this->simpleText, 'l'));
}
public function testIsFileName(): void
/**
* @param string $description Description of test
* @param string $fileName
* @param bool $expected Expected result
*
* @dataProvider provideFileName
*/
public function testIsFileName(string $description, string $fileName, bool $expected): void
{
$filePath = __FILE__;
$directoryPath = dirname($filePath);
self::assertTrue(Regex::isFileName($filePath));
self::assertTrue(Regex::isFileName('this-1_2 3 & my! 4+file.jpg'));
self::assertFalse(Regex::isFileName($directoryPath));
self::assertTrue(Regex::isFileName('directory1/directory2/this-1_2 3 & my! 4+file.jpg'));
static::assertSame($expected, Regex::isFileName($fileName), $description);
}
public function testIsQuoted()
@@ -2214,6 +2214,39 @@ class RegexTest extends BaseTestCase
];
}
public function provideFileName(): ?Generator
{
yield[
'An empty string',
'',
false,
];
yield[
'Path of this file, of file with test case',
__DIR__,
false,
];
yield[
'Name of this file, of file with test case',
__FILE__,
true,
];
yield[
'Complicated name of file',
'this-1_2 3 & my! 4+file.jpg',
true,
];
yield[
'Complicated name of file',
'directory1/directory2/this-1_2 3 & my! 4+file.jpg',
true,
];
}
/**
* {@inheritdoc}
*/