← Home ← Codex ← DEBT
Browse by Category
+ added · updated 7d
← Back to glossary

Integration Testing

Testing PHP 5.0+ Intermediate
debt(d7/e5/b5/t7)
d7 Detectability Operational debt — how invisible misuse is to your safety net

Closest to 'only careful code review or runtime testing' (d7). The detection_hints note 'automated: no' and the code_pattern is 'No integration test suite; only unit tests; business logic untested against real DB schema.' PHPUnit/Pest can run integration tests if they exist, but the absence of integration tests — or their misconfiguration (shared state, real external services) — is only visible through deliberate code review or when bugs surface in staging/production. No tool automatically flags the gap.

e5 Effort Remediation debt — work required to fix once spotted

Closest to 'touches multiple files / significant refactor in one component' (e5). The quick_fix points to running integration tests against a real DB in a Docker container in CI with transaction rollback — this isn't a one-liner. It requires setting up Docker infrastructure, configuring CI pipelines, isolating test data, and potentially refactoring existing tests that share state or hit real external services. This spans multiple files and configuration layers.

b5 Burden Structural debt — long-term weight of choosing wrong

Closest to 'persistent productivity tax' (b5). Integration testing applies to all PHP contexts (web, cli, queue-worker) per applies_to. Once adopted, every new feature or database change must be covered; misconfigured integration tests (shared state, slow suites) slow many work streams. However, a well-maintained suite is beneficial rather than purely a burden, so it doesn't reach b7.

t7 Trap Cognitive debt — how counter-intuitive correct behaviour is

Closest to 'serious trap' (t7). The misconception field states developers treat integration tests as 'just slow unit tests' to be minimised, missing that they catch contract mismatches between layers that unit tests with mocks entirely miss. The common_mistakes reinforce this: not running them in CI, sharing database state, and hitting real external services are all contradictions of what developers familiar only with unit testing would assume. This contradicts the mental model carried over from unit testing practices.

About DEBT scoring →

Also Known As

integration tests component testing service integration test

TL;DR

Tests that verify multiple components work correctly together — often involving real databases, HTTP clients, or third-party services.

Explanation

Integration tests verify that components interact correctly when combined — e.g., that a repository correctly persists and retrieves domain objects from a real database, or that an HTTP controller returns the expected response for a given request. They are slower and more expensive than unit tests but catch bugs that only emerge from component interactions. In PHP, integration tests typically use a test database, in-memory SQLite, or containers (via Docker or Laravel TestContainers). Follow the Test Pyramid: many unit tests, fewer integration tests, few E2E tests.

Diagram

flowchart TD
    subgraph Unit Tests - Isolated
        UT[Test business logic<br/>all dependencies mocked<br/>fast milliseconds]
    end
    subgraph Integration Tests - Real Dependencies
        IT[Test component interactions<br/>real DB real cache real queue<br/>slower seconds]
    end
    subgraph What Integration Tests Catch
        N1[N+1 query bugs<br/>mocks hide these]
        N2[Transaction isolation issues]
        N3[ORM mapping problems]
        N4[Migration correctness]
    end
    IT --> N1 & N2 & N3 & N4
    style UT fill:#238636,color:#fff
    style IT fill:#d29922,color:#fff

Common Misconception

Integration tests are just slow unit tests and should be minimised. Integration tests verify that components work together — they catch contract mismatches between layers that unit tests with mocks miss entirely. A test pyramid needs both, with unit tests forming the base.

Why It Matters

Integration tests verify that components work correctly together — they catch the mismatches between units that pass individually but fail when combined. A suite of only unit tests gives false confidence about real behaviour.

Common Mistakes

  • Using real external services (payment APIs, email providers) in integration tests — use sandbox environments or contract tests.
  • Not isolating test data — tests that share database state interfere with each other and produce random failures.
  • Making integration tests so broad they take minutes to run — they should be slower than unit tests but not by orders of magnitude.
  • Not running integration tests in CI — they catch the bugs that matter most.

Code Examples

💡 Note
Integration tests hit real infrastructure (database, queue) — use a test database and fakes for external services.
✗ Vulnerable
// Mock that doesn't match real behaviour:
$mockRepo = $this->createMock(UserRepository::class);
$mockRepo->method('findByEmail')->willReturn($user); // Always returns a user
// Real DB: findByEmail throws on DB connection failure
// Integration test catches what the mock hides
✓ Fixed
class OrderApiTest extends TestCase {
    use RefreshDatabase; // reset DB per test

    public function test_place_order_stores_and_emails(): void {
        Mail::fake();
        $user = User::factory()->create();

        $response = $this->actingAs($user)
            ->postJson('/api/orders', ['sku' => 'WIDGET-1', 'qty' => 2]);

        $response->assertStatus(201);
        $this->assertDatabaseHas('orders', ['user_id' => $user->id]);
        Mail::assertSent(OrderConfirmation::class);
    }
}

Added 15 Mar 2026
Edited 22 Mar 2026
Views 69
Rate this term
No ratings yet
🤖 AI Guestbook educational data only
| |
Last 30 days
0 pings T 0 pings W 1 ping T 0 pings F 0 pings S 0 pings S 0 pings M 0 pings T 0 pings W 0 pings T 2 pings F 2 pings S 5 pings S 1 ping M 1 ping T 2 pings W 0 pings T 0 pings F 1 ping S 0 pings S 0 pings M 0 pings T 1 ping W 0 pings T 0 pings F 1 ping S 0 pings S 1 ping M 0 pings T 0 pings W
No pings yet today
No pings yesterday
Scrapy 10 Perplexity 9 Amazonbot 7 Google 7 Ahrefs 4 SEMrush 4 Bing 4 Unknown AI 3 ChatGPT 3 Claude 2 Majestic 1 Meta AI 1 PetalBot 1
crawler 51 crawler_json 5
DEV INTEL Tools & Severity
🟡 Medium ⚙ Fix effort: Medium
⚡ Quick Fix
Run integration tests against a real database in a Docker container in CI — use transactions with rollback to keep tests isolated and fast
📦 Applies To
PHP 5.0+ web cli queue-worker
🔗 Prerequisites
🔍 Detection Hints
No integration test suite; only unit tests; business logic untested against real DB schema
Auto-detectable: ✗ No phpunit pest docker
⚠ Related Problems
🤖 AI Agent
Confidence: Low False Positives: High ✗ Manual fix Fix: High Context: File Tests: Update


✓ schema.org compliant