Skip to content

Fix Generator path regex to tolerate either directory separator#112

Merged
dereuromark merged 1 commit into
masterfrom
fix/find-existing-dos-tolerates-ds
May 11, 2026
Merged

Fix Generator path regex to tolerate either directory separator#112
dereuromark merged 1 commit into
masterfrom
fix/find-existing-dos-tolerates-ds

Conversation

@dereuromark
Copy link
Copy Markdown
Contributor

Summary

Generator::findExistingDtos() and Generator::findExistingMappers() both matched on 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 normalized 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.

How spotted

Surfaced while auditing dereuromark/cakephp-dto, which has its own (duplicated) Generator carrying 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 findExistingDtos and findExistingMappers. 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.

`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.
@dereuromark dereuromark added the bug Something isn't working label May 11, 2026
@codecov
Copy link
Copy Markdown

codecov Bot commented May 11, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 83.07%. Comparing base (49ddfe2) to head (2481285).

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.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@dereuromark dereuromark merged commit 0f7b1b6 into master May 11, 2026
12 checks passed
@dereuromark dereuromark deleted the fix/find-existing-dos-tolerates-ds branch May 11, 2026 13:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant