HEX
Server: Apache
System: Linux webm013.cluster123.gra.hosting.ovh.net 6.18.42-ovh-vps-grsec-zfs+ #1 SMP PREEMPT_DYNAMIC Wed Aug 5 15:59:48 CEST 2026 x86_64
User: lesanew (165608)
PHP: 8.3.31
Disabled: _dyuweyrj4,_dyuweyrj4r,dl
Upload Files
File: /home/l/e/s/lesanew/anestetues2/vendor/roots/acorn/tests/Test/Concerns/SupportsGlobalStubs.php
<?php

namespace Roots\Acorn\Tests\Test\Concerns;

use Akamon\MockeryCallableMock\MockeryCallableMock;

trait SupportsGlobalStubs
{
    public static $globals;

    /**
     * Create stubs and spies for global functions.
     *
     * @param  string  $fn  The name of the global function
     * @param  null|callable  $callable  The real function to monitor
     */
    protected function stub(string $fn, ?callable $callable = null): MockeryCallableMock
    {
        $script = <<<'DECLARE_FUNCTION'
        if (! function_exists('%1$s')) {
            function %1$s (...$args) {
                return call_user_func_array(%2$s::$globals['%1$s'], $args);
            }
        }
        DECLARE_FUNCTION;

        eval(sprintf($script, $fn, __CLASS__));

        return self::$globals[$fn] = new MockeryCallableMock($callable);
    }

    /**
     * Create multiple stubs and spies for global functions.
     *
     * @param  iterable  $stubs
     * @return MockeryCallableMock[]
     */
    protected function stubs(iterable $callables): array
    {
        $stubs = [];

        foreach ($callables as $fn => $callable) {

            if (is_int($fn) && is_string($callable)) {
                $fn = $callable;
                $callable = null;
            }

            $stubs[$fn] = $this->stub($fn, $callable);
        }

        return $stubs;
    }

    /**
     * Clear all current global stubs.
     */
    protected function clearStubs(): void
    {
        self::$globals = [];
    }
}