Skip to content

TestLinkTest Coverage Traceability

Framework-agnostic test-to-code linking for PHP. Works with Pest and PHPUnit.

TestLink Logo

Quick Example ​

Production Code ​

Mark production methods with the tests that cover them:

php
<?php

namespace App\Services;

use TestFlowLabs\TestingAttributes\TestedBy;

class UserService
{
    #[TestedBy(UserServiceTest::class, 'test_creates_a_new_user')]
    #[TestedBy(UserServiceTest::class, 'test_validates_user_email')]
    public function create(array $data): User
    {
        // Implementation
    }
}

Test Code ​

Link your tests to production methods:

php
test('creates a new user', function () {
    $user = app(UserService::class)->create([
        'name' => 'John',
        'email' => 'john@example.com',
    ]);

    expect($user)->toBeInstanceOf(User::class);
})->linksAndCovers(UserService::class.'::create');

test('validates user email', function () {
    expect(fn () => app(UserService::class)->create([
        'email' => 'invalid',
    ]))->toThrow(ValidationException::class);
})->linksAndCovers(UserService::class.'::create');
php
use TestFlowLabs\TestingAttributes\LinksAndCovers;

class UserServiceTest extends TestCase
{
    #[LinksAndCovers(UserService::class, 'create')]
    public function test_creates_a_new_user(): void
    {
        $user = app(UserService::class)->create([
            'name' => 'John',
            'email' => 'john@example.com',
        ]);

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

    #[LinksAndCovers(UserService::class, 'create')]
    public function test_validates_user_email(): void
    {
        $this->expectException(ValidationException::class);

        app(UserService::class)->create([
            'email' => 'invalid',
        ]);
    }
}

CLI Commands ​

Use the standalone CLI that works with any framework:

bash
$ testlink validate

Validation Report:
  ✓ All links are valid!

  PHPUnit attribute links: 2
  Pest method chain links: 0
  Total links: 2
bash
$ testlink report

Coverage Links Report
─────────────────────

UserService::create
  → UserServiceTest::test_creates_a_new_user
  → UserServiceTest::test_validates_user_email

Summary:
  Methods: 1
  Tests: 2

Part of the TestFlowLabs Ecosystem ​

TestLink works seamlessly with other TestFlowLabs packages:

Together, these packages provide a complete testing workflow from behavior specification to implementation validation.

Released under the MIT License.