Skip to content
Pro Analyzer — Available with ShieldCI Pro

Test Coverage Analyzer

Analyzer IDCategorySeverityTime To Fix
test-coverage💻 Code QualityMedium30 minutes

What This Checks

Validates that critical application modules have corresponding test files. Recursively scans four key directories and checks each PHP class against your tests/ directory:

  • Missing tests/ directory entirely
  • Models (app/Models) without matching test files
  • Controllers (app/Http/Controllers) without matching test files, including nested subdirectories like Api/
  • Services (app/Services) without matching test files
  • Policies (app/Policies) without matching test files

Automatically skipped: Abstract/Base-prefixed classes, traits, enums, and interfaces are excluded from the count. Within app/Services, DTOs (*Payload, files under a DTOs/ subdirectory) and exception classes (*Exception, files under an Exceptions/ subdirectory) are also excluded — these utility types have no independently testable business logic.

Flexible test matching: Test files don't need to exactly mirror the class name. PascalCase boundary matching handles all common Laravel naming conventions:

PatternTest fileMatches class
ExactUserTest.phpUser.php
SuffixManagePostControllerTest.phpPostController.php
PrefixUserModelTest.phpUser.php
Reverse prefixEmailVerificationTest.phpEmailVerificationPromptController.php

The reverse-prefix rule accommodates Laravel Breeze's convention of naming tests after features rather than individual controller classes (e.g., a single EmailVerificationTest can cover EmailVerificationPromptController and EmailVerificationNotificationController).

Per-directory breakdown: Results include a per-layer summary so you can see exactly which areas need attention:

2 of 4 critical files have tests (50% coverage). Models: 1/2, Controllers: 1/1, Services: 0/1

Coverage Thresholds

CoverageResultIssue Severity
>= 75%Pass-
25–74%WarningLow
< 25%WarningMedium

Why It Matters

  • Unreliable Deployments: Untested code is more likely to contain bugs that reach production
  • Regression Prevention: Without tests, code changes can break existing functionality silently
  • Confidence in Deployments: Adequate test coverage enables faster, safer deployments
  • Code Documentation: Tests serve as living documentation of expected behavior

How to Fix

Quick Fix (5 minutes)

Create your first test:

bash
# Generate a test for a specific feature
php artisan make:test UserRegistrationTest

# Generate a unit test
php artisan make:test Models/UserTest --unit

Proper Fix (30 minutes)

1. Ensure critical modules have test coverage:

php
// tests/Feature/Http/Controllers/UserControllerTest.php
use Illuminate\Foundation\Testing\RefreshDatabase;

class UserControllerTest extends TestCase
{
    use RefreshDatabase;

    public function test_index_returns_users(): void
    {
        User::factory()->count(3)->create();

        $response = $this->getJson('/api/users');

        $response->assertOk()
            ->assertJsonCount(3, 'data');
    }
}

2. Add model tests:

php
// tests/Unit/Models/UserTest.php
use Illuminate\Database\Eloquent\Relations\HasMany;

class UserTest extends TestCase
{
    public function test_user_has_orders_relationship(): void
    {
        $user = User::factory()->create();

        $this->assertInstanceOf(HasMany::class, $user->orders());
    }
}

3. Run coverage report:

bash
php artisan test --coverage --min=80

References