feature #30664 [Finder] Get filename without extension (antonch1989)

This PR was squashed before being merged into the 4.3-dev branch (closes #30664).

Discussion
----------

[Finder] Get filename without extension

| Q             | A
| ------------- | ---
| Branch?       | master
| Bug fix?      | no
| New feature?  | yes
| BC breaks?    | no
| Deprecations? | no
| Tests pass?   | yes
| Fixed tickets | #30655
| License       | MIT
| Doc PR        |

Commits
-------

821e55ab80 [Finder] Get filename without extension
This commit is contained in:
Fabien Potencier 2019-03-27 09:36:49 +01:00
commit a35ad63191
2 changed files with 41 additions and 0 deletions

View File

@ -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.
*

View 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();