Fix Generator path regex to tolerate either directory separator#112
Merged
Conversation
`findExistingDtos()` and `findExistingMappers()` both used regex patterns
with hardcoded forward slashes:
#src/Dto/(.+)<suffix>\.php$#
#Mapper/(.+)<suffix>Mapper\.php$#
RecursiveDirectoryIterator yields paths using the host OS separator, so on
Windows where paths come back with backslashes the regex never matched —
and the "delete generated DTOs no longer in the spec" pass silently
no-op'd, leaving stale files behind on every regenerate.
Replacement pattern accepts either separator via a character class
`[/\\\\]`. Captured nested paths are normalised to forward-slash form so
the same nested entry (e.g. `Sub/Foo` on Linux, `Sub\Foo` on Windows)
doesn't land in the result map as two distinct keys depending on host OS.
Driving the Windows path on a Linux CI box is awkward; the regression
tests exercise the host OS path layout (so the now-DS-tolerant regex still
matches the common case) plus the new normalisation step for nested
directories. Both tests cover the Dto and Mapper variants symmetrically.
phpunit (809/809), phpstan, phpcs all clean.
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #112 +/- ##
=========================================
Coverage 83.06% 83.07%
Complexity 1555 1555
=========================================
Files 45 45
Lines 3833 3835 +2
=========================================
+ Hits 3184 3186 +2
Misses 649 649 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Generator::findExistingDtos()andGenerator::findExistingMappers()both matched on regex patterns with hardcoded forward slashes:RecursiveDirectoryIteratoryields paths using the host OS separator, so on Windows where paths come back with backslashes the regex never matched — and the "delete generated DTOs no longer in the spec" pass silently no-op'd, leaving stale files behind on every regenerate.Replacement pattern accepts either separator via a character class
[/\\]. Captured nested paths are normalized to forward-slash form so the same nested entry (e.g.Sub/Fooon Linux,Sub\\Fooon Windows) doesn't land in the result map as two distinct keys depending on host OS.How spotted
Surfaced while auditing
dereuromark/cakephp-dto, which has its own (duplicated)Generatorcarrying the identical bug — already fixed in dereuromark/cakephp-dto#112. This PR ports the equivalent fix to the upstream library so other downstream users get it too.Tests
Two new regression tests, one each for
findExistingDtosandfindExistingMappers. Exercising the Windows path directly on a Linux CI box is awkward, so each test drives the now-DS-tolerant regex via a temp-dir round trip on the host OS path layout (proves the common case still works) plus asserts that nested-directory entries get normalized to the canonical forward-slash form.phpunit (809/809), phpstan, and phpcs all clean.