mirror of
https://github.com/wiosna-dev/common-library.git
synced 2026-03-12 09:31:51 +01:00
[Miscellaneous] [Regex] Use simpler & stronger pattern to match name of file
This commit is contained in:
@@ -94,11 +94,14 @@ class MiscellaneousTest extends BaseTestCase
|
||||
self::assertEquals($withoutExtension, Miscellaneous::getFileNameWithoutExtension($fileName));
|
||||
}
|
||||
|
||||
public function testGetFileNameFromPath()
|
||||
public function testGetFileNameFromPath(): void
|
||||
{
|
||||
// Path with file
|
||||
self::assertEquals('sit.amet.JPG', Miscellaneous::getFileNameFromPath('lorem/ipsum-dolor/sit.amet.JPG'));
|
||||
|
||||
// Path with complicated name of file
|
||||
self::assertEquals('this-1_2 3 & my! 4+file.jpg', Miscellaneous::getFileNameFromPath('lorem/ipsum-dolor/this-1_2 3 & my! 4+file.jpg'));
|
||||
|
||||
// Path without file
|
||||
self::assertEquals('', Miscellaneous::getFileNameFromPath('lorem/ipsum-dolor/sit-amet'));
|
||||
|
||||
|
||||
@@ -244,13 +244,16 @@ class RegexTest extends BaseTestCase
|
||||
self::assertTrue(Regex::contains($this->simpleText, 'l'));
|
||||
}
|
||||
|
||||
public function testIsFileName()
|
||||
public function testIsFileName(): 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'));
|
||||
}
|
||||
|
||||
public function testIsQuoted()
|
||||
|
||||
Reference in New Issue
Block a user