Skip to content

feat(ConfigLoader): add validation for complete configuration before warmUp#139

Merged
s2x merged 3 commits intomasterfrom
feature/issue-35-configloader-validation
Apr 14, 2026
Merged

feat(ConfigLoader): add validation for complete configuration before warmUp#139
s2x merged 3 commits intomasterfrom
feature/issue-35-configloader-validation

Conversation

@s2x
Copy link
Copy Markdown
Collaborator

@s2x s2x commented Apr 14, 2026

Summary

Add validation in warmUp() method to ensure all three config sections (workerman, process, scheduler) are set before writing to cache.

Problem

In the ConfigLoader class, the $config property is populated by three separate setter calls. If the warmUp() method is called before all three sections are set, the saved configuration will be incomplete. There is no validation that all three sections have been set.

Changes

src/ConfigSection.php (new file)

  • Add enum ConfigSection with cases: WORKERMAN, PROCESS, SCHEDULER
  • Uses string values for clarity

src/ConfigLoader.php

  • Add validation in warmUp() method using ConfigSection enum
  • Throws LogicException with descriptive message when any config section is missing
  • Lists all missing sections (e.g., "Missing: process, scheduler")
  • Refactored to use ConfigSection enum instead of magic numbers

tests/ConfigLoaderTest.php (new file)

  • 9 comprehensive tests covering:
    • Missing workerman config
    • Missing process config
    • Missing scheduler config
    • Multiple missing sections
    • All sections missing
    • Complete configuration (success case)
    • Getter methods validation

Testing

Unit tests pass:

PHPUnit 10.5.63
OK (9 tests, 21 assertions)

BREAKING CHANGE

Cache format changed from numeric indices to string keys:

  • Old format: [0 => ..., 1 => ..., 2 => ...]
  • New format: ['workerman' => ..., 'process' => ..., 'scheduler' => ...]

Existing cache must be cleared after upgrade:

rm -rf var/cache/*

Closes #35

Piotr Hałas added 2 commits April 14, 2026 21:42
…warmUp

Add validation in warmUp() method to ensure all three config sections
(workerman, process, scheduler) are set before writing to cache.

This prevents incomplete configuration from being cached and causing
hard-to-debug errors later during use.

Closes #35
@s2x s2x force-pushed the feature/issue-35-configloader-validation branch from 4b0cf11 to b4ca6c4 Compare April 14, 2026 20:09
…warmUp

Add ConfigSection enum and validation in warmUp() to ensure all three
config sections (workerman, process, scheduler) are set before writing
to cache.

- Add ConfigSection enum with WORKERMAN, PROCESS, SCHEDULER cases
- Use string keys ('workerman', 'process', 'scheduler') for clarity
- Add validation in warmUp() with descriptive error message
- Add comprehensive test coverage

BREAKING CHANGE: Cache format changed from numeric indices [0,1,2]
to string keys ['workerman', 'process', 'scheduler']

Closes #35
@s2x s2x force-pushed the feature/issue-35-configloader-validation branch from b4ca6c4 to 10fb790 Compare April 14, 2026 20:12
@s2x s2x merged commit 1774b8d into master Apr 14, 2026
22 checks passed
@s2x s2x deleted the feature/issue-35-configloader-validation branch April 14, 2026 20:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

ConfigLoader — Incomplete Configuration Not Guaranteed

1 participant