HEX
Server: LiteSpeed
System: Linux s3.sitechai.com 4.18.0-553.51.1.lve.1.el8.x86_64 #1 SMP Wed May 14 14:34:57 UTC 2025 x86_64
User: workzeni (2217)
PHP: 8.1.32
Disabled: mail, show_source, system, shell_exec, passthru, exec, eval, shell
Upload Files
File: //home/workzeni/agency-erp-05.workzenix.com/vendor/pestphp/pest/src/Plugins/Only.php
<?php

declare(strict_types=1);

namespace Pest\Plugins;

use Pest\Contracts\Plugins\Terminable;
use Pest\PendingCalls\TestCall;

/**
 * @internal
 */
final class Only implements Terminable
{
    /**
     * The temporary folder.
     */
    private const TEMPORARY_FOLDER = __DIR__
        .DIRECTORY_SEPARATOR
        .'..'
        .DIRECTORY_SEPARATOR
        .'..'
        .DIRECTORY_SEPARATOR
        .'.temp';

    /**
     * {@inheritDoc}
     */
    public function terminate(): void
    {
        if (Parallel::isWorker()) {
            return;
        }

        $lockFile = self::TEMPORARY_FOLDER.DIRECTORY_SEPARATOR.'only.lock';

        if (file_exists($lockFile)) {
            unlink($lockFile);
        }
    }

    /**
     * Creates the lock file.
     */
    public static function enable(TestCall $testCall, string $group = '__pest_only'): void
    {
        $testCall->group($group);

        if (Environment::name() === Environment::CI || Parallel::isWorker()) {
            return;
        }

        $lockFile = self::TEMPORARY_FOLDER.DIRECTORY_SEPARATOR.'only.lock';

        if (file_exists($lockFile) && $group === '__pest_only') {
            file_put_contents($lockFile, $group);

            return;
        }

        if (! file_exists($lockFile)) {
            touch($lockFile);

            file_put_contents($lockFile, $group);
        }
    }

    /**
     * Checks if "only" mode is enabled.
     */
    public static function isEnabled(): bool
    {
        $lockFile = self::TEMPORARY_FOLDER.DIRECTORY_SEPARATOR.'only.lock';

        return file_exists($lockFile);
    }

    /**
     * Returns the group name.
     */
    public static function group(): string
    {
        $lockFile = self::TEMPORARY_FOLDER.DIRECTORY_SEPARATOR.'only.lock';

        if (! file_exists($lockFile)) {
            return '__pest_only';
        }

        return file_get_contents($lockFile) ?: '__pest_only'; // @phpstan-ignore-line
    }
}