8000 feature #30664 [Finder] Get filename without extension (antonch1989) · symfony/symfony@a35ad63 · GitHub
[go: up one dir, main page]

Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit a35ad63

Browse files
committed
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 ------- 821e55a [Finder] Get filename without extension
2 parents 19c6639 + 821e55a commit a35ad63

File tree

2 files changed

+41
-0
lines changed

2 files changed

+41
-0
lines changed

src/Symfony/Component/Finder/SplFileInfo.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,13 @@ public function getRelativePathname()
5757
return $this->relativePathname;
5858
}
5959

60+
public function getFilenameWithoutExtension(): string
61+
{
62+
$filename = $this->getFilename();
63+
64+
return \pathinfo($filename, PATHINFO_FILENAME);
65+
}
66+
6067
/**
6168
* Returns the contents of the file.
6269
*

src/Symfony/Component/Finder/Tests/FinderTest.php

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1007,6 +1007,40 @@ public function testRelativePathname()
10071007
$this->assertEquals($ref, $paths);
10081008
}
10091009

1010+
public function testGetFilenameWithoutExtension()
1011+
{
1012+
$finder = $this->buildFinder()->in(self::$tmpDir)->sortByName();
1013+
1014+
$fileNames = [];
1015+
1016+
foreach ($finder as $file) {
1017+
$fileNames[] = $file->getFilenameWithoutExtension();
1018+
}
1019+
1020+
$ref = [
1021+
'test',
1022+
'toto',
1023+
'test',
1024+
'foo',
1025+
'bar',
1026+
'foo bar',
1027+
'qux',
1028+
'baz_100_1',
1029+
'baz_1_2',
1030+
'qux_0_1',
1031+
'qux_1000_1',
1032+
'qux_1002_0',
1033+
'qux_10_2',
1034+
'qux_12_0',
1035+
'qux_2_0',
1036+
];
1037+
1038+
sort($fileNames);
1039+
sort($ref);
1040+
1041+
$this->assertEquals($ref, $fileNames);
1042+
}
1043+
1010< 46FD /code>1044
public function testAppendWithAFinder()
10111045
{
10121046
$finder = $this->buildFinder();

0 commit comments

Comments
 (0)
0