Skip to content

[7.x] Fix failing tests#1254

Merged
duncanmcclean merged 3 commits into
7.xfrom
claude/debug-failing-tests-012tVZBN9hRKyfiXGtvhhhjH
Nov 24, 2025
Merged

[7.x] Fix failing tests#1254
duncanmcclean merged 3 commits into
7.xfrom
claude/debug-failing-tests-012tVZBN9hRKyfiXGtvhhhjH

Conversation

@duncanmcclean
Copy link
Copy Markdown
Owner

@duncanmcclean duncanmcclean commented Nov 24, 2025

I'm not entirely sure why a bunch of tests started failing all of a sudden... they all passed on the 16th October, but now they're failing. 🤷‍♂️

Claude managed to "fix" them. Thanks Claude!

Between October and November 2024, PHPUnit was upgraded from 10.x to 11.x,
which introduced stricter error handling for undefined array keys. This caused
tests to fail when accessing $variantOption['price'] for variant options that
don't have a price key defined.

The fix uses the null coalescing operator to provide a default null value
when the 'price' key is not present, matching the pattern already used for
the 'stock' key on line 139.

This resolves 35 failing tests in the MigrateProductTypeTest suite and
other tests that create variant options without price values.
This commit resolves all code-related test failures that emerged between
October 16th and November 24th, 2025, reducing failures from 165 to 24.

The remaining 24 failures are environmental (missing PHP 8.4 PDO SQLite).

## Root Cause Analysis

Between October 16th and November 24th, PHPUnit was upgraded from 10.x to 11.x
(currently 11.5.33). PHPUnit 11 introduced much stricter error handling,
converting PHP warnings (including undefined array key access) into exceptions
during test execution.

## Fixes Applied

1. **Undefined Array Key Errors (135 failures → 0)**
   - src/Products/Product.php:136 - Added null coalescing for 'price' key
   - src/Orders/HasLineItems.php:37-38 - Added null coalescing for 'product'
     and 'quantity' keys

2. **Test Pollution / Blueprint Artifacts (30 failures → 0)**
   - tests/Listeners/EnforceEntryBlueprintFieldsTest.php - Added afterEach
     cleanup to delete blueprint test artifacts that were persisting to disk
   - tests/Helpers/RefreshContent.php - Added Stache entries store clearing
   - tests/Orders/EntryOrderRepositoryTest.php - Added Stache clearing in
     beforeEach to prevent data accumulation across tests
   - tests/Products/EntryProductRepositoryTest.php - Added Stache clearing in
     beforeEach to prevent data accumulation across tests

## Test Results

Before fixes: 165 failed, 3 incomplete, 30 skipped, 350 passed
After fixes:  24 failed, 3 incomplete, 30 skipped, 491 passed

The remaining 24 failures are all "could not find driver" (QueryException)
errors related to missing pdo_sqlite extension in PHP 8.4 environment. These
are EloquentOrderRepositoryTest, EloquentCustomerRepositoryTest, and
VerificationControllerEloquentTest failures that require database connectivity.
1. **EntryCustomerRepositoryTest** - Added Stache clearing in beforeEach to
   prevent customer data accumulation across tests

2. **EloquentQueryBuilder::whereStatusLogDate** - Fixed "Relation statusLog
   does not exist" error by using native Eloquent builder's whereHas instead
   of Statamic's overridden version which expects blueprint-based relationships
@duncanmcclean duncanmcclean merged commit 3f1d10e into 7.x Nov 24, 2025
37 checks passed
@duncanmcclean duncanmcclean deleted the claude/debug-failing-tests-012tVZBN9hRKyfiXGtvhhhjH branch November 24, 2025 23:33
@github-actions
Copy link
Copy Markdown

Released as part of v7.8.8.

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.

2 participants