Skip to content
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

Enhance Dotenv Component: Improved Parsing, Type Detection, and Unit Tests #2

Merged
merged 6 commits into from
Oct 12, 2024

Conversation

walmir-silva
Copy link
Contributor

This pull request introduces several enhancements to the Dotenv component, focusing on improving the overall flexibility and reliability of environment variable management in modern PHP applications. Key changes include:

  • Refined parsing system with better error handling and strict mode support.
    
  • Enhanced type detection and casting with customizable detectors and casters.
    
  • Comprehensive unit tests for various components including Casters, Detectors, and Parsers.
    
  • Minor code refactoring and bug fixes for better performance and maintainability.
    

- Improve DefaultParser and StrictParser implementations
- Create new traits: LineParsing and ValueInterpolation
- Update DotenvFactory to use enhanced parsers
- Add integration and functional tests

New files:
- src/Parser/Trait/LineParsing.php
- src/Parser/Trait/ValueInterpolation.php
- tests/Functional/DotenvFunctionalTest.php
- tests/Integration/DotenvIntegrationTest.php

Modified files:
- src/DotenvFactory.php
- src/Parser/DefaultParser.php
- src/Parser/StrictParser.php
…d components

This commit introduces a suite of unit tests to ensure thorough coverage for various components of our environment variable handling system. The new tests include:

Casters:
- ArrayCasterTest
- BooleanCasterTest
- FloatCasterTest
- IntegerCasterTest
- JsonCasterTest
- NullCasterTest
- StringCasterTest
- TypeCasterRegistryTest

Detectors:
- ArrayDetectorTest
- BooleanDetectorTest
- JsonDetectorTest
- NullDetectorTest
- NumericDetectorTest
- StringDetectorTest
- TypeDetectorRegistryTest

Other components:
- DotenvFunctionalTest
- FileLoaderTest

Key features of these tests:
- Extensive use of data providers for thorough input testing
- Mock objects to simulate various behaviors and dependencies
- Priority checking for detectors
- Edge case handling and invalid input testing
- Verification of default type detection and casting
- Ensures correct prioritization in registries
- Comprehensive testing of file loading scenarios, including error cases
This commit introduces several improvements to the type casting system and integration tests:

1. TypeSystem:
   - Implement TypeSystem class to manage type detection and casting
   - Ensure proper application of casters in the processing chain

2. ArrayCaster:
   - Refactor to process array elements recursively
   - Inject TypeSystem for proper type conversion of array elements

3. TypeCasterRegistry:
   - Update to use the new ArrayCaster with TypeSystem injection
   - Improve error handling for unregistered casters

4. DotenvIntegrationTest:
   - Refine assertions to match expected type conversions
   - Ensure proper testing of complex data types (arrays, JSON)

5. Other test classes:
   - Update TypeCasterRegistryTest to reflect new behavior
   - Adjust other test classes as needed for consistency
- Updated data provider methods to be static to adhere to PHPUnit requirements.
- Modified files include various test files under `tests/Unit` directory.
- Removed unused `DotenvTest.php`.
- Fix minor issues in configuration, source, and test files:
  - Adjustments in `docker-compose.yml` and `phpunit.xml` to fix parameters.
  - Fixes in `Dotenv` class to improve variable loading logic.
  - Corrections in parsers (`DefaultParser`, `StrictParser`) for consistent handling.
  - Updates in `ArrayCaster` to enhance precision in array conversion.
  - Corrections in unit and functional tests (`DotenvFunctionalTest`, `BooleanCasterTest`, `NullCasterTest`, `StringCasterTest`, `NullDetectorTest`, `NumericDetectorTest`) to reflect changes in corresponding classes and ensure test coverage.
@walmir-silva walmir-silva merged commit 01f8ceb into main Oct 12, 2024
1 check passed
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.

1 participant