[Finder] Get filename without extension
This commit is contained in:
parent
468bca8faa
commit
821e55ab80
@ -57,6 +57,13 @@ class SplFileInfo extends \SplFileInfo
|
||||
return $this->relativePathname;
|
||||
}
|
||||
|
||||
public function getFilenameWithoutExtension(): string
|
||||
{
|
||||
$filename = $this->getFilename();
|
||||
|
||||
return \pathinfo($filename, PATHINFO_FILENAME);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the contents of the file.
|
||||
*
|
||||
|
@ -1007,6 +1007,40 @@ class FinderTest extends Iterator\RealIteratorTestCase
|
||||
$this->assertEquals($ref, $paths);
|
||||
}
|
||||
|
||||
public function testGetFilenameWithoutExtension()
|
||||
{
|
||||
$finder = $this->buildFinder()->in(self::$tmpDir)->sortByName();
|
||||
|
||||
$fileNames = [];
|
||||
|
||||
foreach ($finder as $file) {
|
||||
$fileNames[] = $file->getFilenameWithoutExtension();
|
||||
}
|
||||
|
||||
$ref = [
|
||||
'test',
|
||||
'toto',
|
||||
'test',
|
||||
'foo',
|
||||
'bar',
|
||||
'foo bar',
|
||||
'qux',
|
||||
'baz_100_1',
|
||||
'baz_1_2',
|
||||
'qux_0_1',
|
||||
'qux_1000_1',
|
||||
'qux_1002_0',
|
||||
'qux_10_2',
|
||||
'qux_12_0',
|
||||
'qux_2_0',
|
||||
];
|
||||
|
||||
sort($fileNames);
|
||||
sort($ref);
|
||||
|
||||
$this->assertEquals($ref, $fileNames);
|
||||
}
|
||||
|
||||
public function testAppendWithAFinder()
|
||||
{
|
||||
$finder = $this->buildFinder();
|
||||
|
Reference in New Issue
Block a user