Skip to content

[13.x] Add comprehensive integration tests for DatePeriod support in whereBetween/havingBetween#58839

Closed
mosabbirrakib wants to merge 1 commit intolaravel:masterfrom
mosabbirrakib:add-dateperiod-support-wherebetween
Closed

[13.x] Add comprehensive integration tests for DatePeriod support in whereBetween/havingBetween#58839
mosabbirrakib wants to merge 1 commit intolaravel:masterfrom
mosabbirrakib:add-dateperiod-support-wherebetween

Conversation

@mosabbirrakib
Copy link
Contributor

This PR adds comprehensive integration tests for the DatePeriod support that was added in PR #58687.

Problem

While PR #58687 added DatePeriod support to whereBetween() and havingBetween() methods with unit tests, it lacks comprehensive integration tests that verify the feature works correctly with real database queries across different scenarios and edge cases.

Solution

This PR adds comprehensive integration tests in QueryBuilderDatePeriodTest.php that test all DatePeriod scenarios with actual database queries.

Tests Added

whereBetween Tests:

whereBetween with DatePeriod - Basic DatePeriod with start and end dates
whereBetween with CarbonPeriod - Laravel's Carbon extension of DatePeriod
whereBetween with recurrences - DatePeriod using recurrence count instead of end date
whereBetween with EXCLUDE_START_DATE flag - Tests the DatePeriod::EXCLUDE_START_DATE flag
whereBetween with INCLUDE_END_DATE flag - Tests the DatePeriod::INCLUDE_END_DATE flag
whereBetween with both flags - Tests both inclusion/exclusion flags combined

whereNotBetween Tests:

whereNotBetween with DatePeriod - NOT BETWEEN with DatePeriod
whereNotBetween with EXCLUDE_START_DATE - NOT BETWEEN respecting exclusion flags

havingBetween Tests:

havingBetween with DatePeriod - HAVING BETWEEN with grouped queries
havingNotBetween with DatePeriod - HAVING NOT BETWEEN with grouped queries

Logical Operators:

orWhereBetween with DatePeriod - OR WHERE BETWEEN with DatePeriod
orWhereNotBetween with DatePeriod - OR WHERE NOT BETWEEN with DatePeriod

Test Structure

All tests use real database queries with actual data:

// Test data setup
Schema::create('events', function (Blueprint $table) {
    $table->increments('id');
    $table->string('name');
    $table->dateTime('event_date');
});

DB::table('events')->insert([
    ['name' => 'Event 1', 'event_date' => '2024-01-05 10:00:00'],
    ['name' => 'Event 2', 'event_date' => '2024-01-10 10:00:00'],
    ['name' => 'Event 3', 'event_date' => '2024-01-15 10:00:00'],
    ['name' => 'Event 4', 'event_date' => '2024-01-20 10:00:00'],
    ['name' => 'Event 5', 'event_date' => '2024-01-25 10:00:00'],
]);

Each test verifies:

  1. The query executes without errors
  2. The correct records are returned
  3. Edge cases are handled properly

Benefits to End Users

These integration tests ensure that:

  1. DatePeriod works correctly with real database queries - Not just SQL generation, but actual query execution
  2. All edge cases are covered - Recurrences, inclusion/exclusion flags, NOT BETWEEN logic
  3. The feature works across different database drivers - Integration tests run on all supported databases
  4. Future changes won't break DatePeriod support - Comprehensive test coverage prevents regressions
  5. Developers can see real-world usage examples - Tests serve as documentation

Why Integration Tests?

As Taylor mentioned in his feedback on PR #58480:

"Feel free to re-submit your change with a thorough explanation of the feature and tests - integration tests are preferred over unit tests."

Integration tests are preferred because they:

  • Test the feature end-to-end with real database queries
  • Verify the feature works across all supported database drivers
  • Catch issues that unit tests might miss (SQL dialect differences, type conversions, etc.)
  • Provide confidence that the feature works in real-world scenarios

Breaking Changes

None. This PR only adds tests for existing functionality that was merged in PR #58687.

Code Changes

  • 1 new file: tests/Integration/Database/QueryBuilderDatePeriodTest.php (268 lines)
  • 12 test methods covering all DatePeriod scenarios
  • 0 changes to production code - only adds tests

Relates to #58092

…whereBetween/havingBetween

This PR adds comprehensive integration tests for the DatePeriod support that was added in PR laravel#58687.

## Problem

While PR laravel#58687 added DatePeriod support to whereBetween() and havingBetween() methods with unit tests, it lacks comprehensive integration tests that verify the feature works correctly with real database queries.

## Solution

This PR adds comprehensive integration tests in QueryBuilderDatePeriodTest.php that test all DatePeriod scenarios with actual database queries:

- whereBetween with DatePeriod
- whereBetween with CarbonPeriod
- whereBetween with recurrences (no end date)
- whereBetween with EXCLUDE_START_DATE flag
- whereBetween with INCLUDE_END_DATE flag
- whereBetween with both flags combined
- whereNotBetween with DatePeriod
- whereNotBetween with EXCLUDE_START_DATE flag
- havingBetween with DatePeriod (grouped queries)
- havingNotBetween with DatePeriod
- orWhereBetween with DatePeriod
- orWhereNotBetween with DatePeriod

## Benefits to End Users

These integration tests ensure that:
1. DatePeriod works correctly with real database queries
2. All edge cases are covered (recurrences, inclusion/exclusion flags)
3. The feature works across different database drivers
4. Future changes won't break DatePeriod support

## Breaking Changes

None. This only adds tests for existing functionality.

Relates to laravel#58092
@mosabbirrakib
Copy link
Contributor Author

Closing to create a new PR with complete implementation including Builder.php changes

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

Comments