Pular para o conteúdo
← Voltar para projetos

Greenlight

A test framework for PHP 8.4+ with typed attributes, parallel execution, flat memory use, and lifecycle-safe test doubles.

#Greenlight

CI Coverage OpenSSF Scorecard PHP License

A parallel-first test framework for PHP 8.4 and later.

Greenlight runs test classes in parallel by default and has zero runtime dependencies. Greenlight discovers tests in the configured paths and sends class assignments to a pool of worker processes.

Read the documentation

Greenlight runs its own test suite with bin/greenlight run.

Greenlight running its own test suite in parallel

#Capabilities

  • Parallel test execution with a dynamic schedule
  • Run-scoped integration fixtures with per-channel resources
  • Resource limits for shared databases and services
  • Leak detection, crash recovery, timeouts, and process isolation
  • Strict mocks, stubs, and spies with automatic verification
  • Typed expectations with clear differences
  • Stable CI shards and machine-readable reports
  • Test attachments for values, text, bytes, and files
  • Coverage through pcov or Xdebug
  • Plain PHP test classes and PHP configuration
  • First-party Symfony, Laravel, Hyperf, PSR-11, PSR-15, Tempest, and PHPStan adapters
  • Automated PHPUnit test conversion with a bundled Rector rule

#Example test

<?php

declare(strict_types=1);

namespace App\Tests;

use Greenlight\Attribute\DataRow;
use Greenlight\Attribute\Test;
use Greenlight\Expect\Expect;

final class PriceTest
{
    #[Test]
    #[DataRow(['9.99', 2, '19.98'], label: 'two units')]
    #[DataRow(['0.50', 3, '1.50'], label: 'three small units')]
    public function multipliesLineTotals(string $unit, int $quantity, string $expected): void
    {
        $total = Price::fromString($unit)->times($quantity);

        Expect::value($total->format())->toBe($expected);
    }

    #[Test]
    public function rejectsNegativeQuantities(): void
    {
        Expect::calling(static function (): void {
            Price::fromString('9.99')->times(-1);
        })->toThrow(\InvalidArgumentException::class, matching: '/quantity/');
    }
}

Price represents application code in this example. See the start guide for a complete application and test.

Tests use typed PHP classes. Attributes identify tests, before and after methods, data sets, retries, timeouts, skip conditions, groups, resource requirements, and isolation.

Constructor injection supplies fixtures, doubles, and services from plugins.

#Start

Install Greenlight as a development dependency:

composer require --dev greenlight/greenlight

Create greenlight.php in the project root:

<?php

declare(strict_types=1);

use Greenlight\Config\GreenlightConfig;

return GreenlightConfig::create()
    ->paths(['tests'])
    ->workers(count: 'auto');

Run the suite:

vendor/bin/greenlight run

See the start guide for a complete example.

#Execution model

Greenlight discovers each test class once and creates an execution plan. Workers request assignments when they have capacity.

The orchestrator controls resource limits, worker replacement, event checks, and result delivery to reporters. The CLI stores test durations to improve the order of later runs.

With one configured or detected worker, the CLI runs tests in its own process. This mode has no worker-process isolation or hard timeout enforcement.

Greenlight normally schedules complete test classes. It schedules each #[Isolated] test separately. Add #[AllowParallel] to split an independent large class into one assignment for each selected test or data set.

Greenlight assigns scheduling units in execution-plan order as resource capacity permits. Worker placement and completion order depend on the run. Reporters receive events as they arrive.

Use a channel to give each worker a separate external resource. Use #[RequiresResource] to limit concurrent access to a shared resource.

See worker lifecycle and scheduling for the complete model.

#Documentation

#Requirements and limits

Greenlight requires PHP 8.4 or later. The parallel runner uses core stream sockets and proc_open.

Coverage requires pcov or Xdebug. Greenlight does not run PHPUnit suites directly.

#License

MIT. See LICENSE.

Nova versão disponível.