-
-
Notifications
You must be signed in to change notification settings - Fork 33
Restore File::unique() helper #186
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: develop
Are you sure you want to change the base?
Changes from all commits
45d0748
0f2b4c4
c9e9095
0c9dbc5
bf4762e
d66cc3f
43ba814
dfc23f7
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | |||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -11,6 +11,27 @@ | ||||||||||
| $this->filesystem = new Filesystem(); | |||||||||||
| } | |||||||||||
|
|
|||||||||||
| public function testUnique() | |||||||||||
| { | |||||||||||
| $cases = [ | |||||||||||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Fix indentation — confirmed code-quality pipeline failure. Line 16 uses 6 spaces; the pipeline reports 🔧 Proposed fix- $cases = [
+ $cases = [📝 Committable suggestion
Suggested change
🧰 Tools🪛 GitHub Actions: Code Quality[error] 16-16: ERR: Line indented incorrectly; expected at least 8 spaces 🤖 Prompt for AI Agents |
|||||||||||
| // File exists, make it unique | |||||||||||
| 'winter_1.cms' => ['winter.cms', ['winter.cms', 'test_5']], | |||||||||||
|
|
|||||||||||
| // File already unique, return original | |||||||||||
| 'winter.cms' => ['winter.cms', ['winter_1.cms']], | |||||||||||
|
|
|||||||||||
| // Last index available is incremented | |||||||||||
| 'winter_4.cms' => ['winter.cms', ['winter_1.cms', 'test_5', 'winter_3.cms']], | |||||||||||
| 'winter_98.cms' => ['winter.cms', ['winter_97.cms', 'test_5', 'winter_1.cms']], | |||||||||||
|
|
|||||||||||
| // Separator as space | |||||||||||
| 'winter 1.cms' => ['winter.cms', ['winter_1.cms', 'test_5', 'winter_3.cms'], ' '], | |||||||||||
| ]; | |||||||||||
|
Comment on lines
+18
to
+29
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Test case B's expected value contradicts the implementation and causes the confirmed pipeline failure (line 31). The failing assertion is case B: 'winter.cms' => ['winter.cms', ['winter_1.cms']], // expected: 'winter.cms'which calls Tracing through the implementation:
Cases B and C have the same precondition (
There is no single consistent rule that produces both results. The docblock examples ( Most likely fix: case B's expected value should be 🔧 Proposed fix- // File already unique, return original
- 'winter.cms' => ['winter.cms', ['winter_1.cms']],
+ // Only one indexed variant exists; next index is returned
+ 'winter_2.cms' => ['winter.cms', ['winter_1.cms']],If instead the intent is that 🤖 Prompt for AI Agents |
|||||||||||
| foreach ($cases as $output => $config) { | |||||||||||
| $this->assertSame($output, $this->filesystem->unique(...$config)); | |||||||||||
|
Check failure on line 31 in tests/Filesystem/FilesystemTest.php
|
|||||||||||
| } | |||||||||||
| } | |||||||||||
|
|
|||||||||||
| /** | |||||||||||
| * @dataProvider providePathsForIsAbsolutePath | |||||||||||
| * @see Symfony\Component\Filesystem\Tests\FilesystemTest::testIsAbsolutePath | |||||||||||
|
|
|||||||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@damsfx it should probably allow the input to be returned unmodified if it doesn't exist within the array.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@LukeTowers If the entry doesn't exist in the array, it must be returned with another index anyway, right?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@damsfx I'm making the suggestion that if it doesn't exist in the array it should be returned unmodified. The method is intended to give you a unique filename provided the input of a desired filename and a list of already existing options. If the filename provided is already unique, then there's no need to modify it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@LukeTowers So in a such case, the same filename is needed in the array of references to get the next incremented name.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The suggested change above should list all the cases that I think the method should need to handle, I've already updated the tests so it should just require a minor change in the method itself.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@LukeTowers Your modifications in tests goes to a failure for me.
FAILED !
The function return
wintert_2.cmsin that case.What I don't understand is why you want to return the unmodified value if it's unique.
In any case, we should return the incremented value! 🤯
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@damsfx The tests are failing because the method doesn't currently have the logic to allow the name to be returned unmodified. The method claims to return a unique filename given the input of a desired filename and a list of existing filenames; why does it have to always return an incremented value if the desired filename isn't present?
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@LukeTowers
Apply a unique index to a filename from provided list ...Maybe we should then say
Apply a unique index to a filename from provided list ONLY if it is found in the list ...or change the name of the method which is perhaps the source of the confusion.In any case, the current function respects the logic of the original one:
68bb7ac
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@LukeTowers Do we continue with this PR in draft?