<?php

/*
|--------------------------------------------------------------------------
| Test Case
|--------------------------------------------------------------------------
|
| The closure you provide to your test functions is always bound to a specific PHPUnit test
| case class. By default, that class is "PHPUnit\Framework\TestCase". Of course, you may
| need to change it using the "pest()" function to bind a different classes or traits.
|
*/

use Kirby\Cms\App;
use Kirby\Filesystem\F;

pest()->extend(Tests\TestCase::class)->in('Feature');

/*
|--------------------------------------------------------------------------
| Functions
|--------------------------------------------------------------------------
|
| While Pest is very powerful out-of-the-box, you may have some testing code specific to your
| project that you don't want to repeat in every file. Here you can also expose helpers as
| global functions to help you to reduce the number of lines of code in your test files.
|
*/

function App(array $roots = [], array $options = [], string $domain = 'example.com', string $uri = ''): App
{
    App::$enableWhoops = false;

    return new App([
        'roots' => array_merge([
            'index' => '/dev/null',
            'base' => $base = dirname(__DIR__).'/tests/Fixtures',
            'site' => $site = $base.'/site',
            'content' => $site.'/content',
        ], $roots),
        'server' => [
            'SERVER_NAME' => $domain,
            'REQUEST_URI' => $uri,
        ],
        'options' => array_merge([
            'beebmx.kirby-sign' => require dirname(__DIR__).'/extensions/options.php',
        ], $options),
        'pageMethods' => require dirname(__DIR__).'/extensions/pageMethods.php',
        'commands' => require dirname(__DIR__).'/extensions/commands.php',
    ]);
}

function getPathFor(string $path): string
{
    return dirname(__DIR__).'/tests/Fixtures/'.$path;
}

function copyEnv(string $env = '.env.example', ?string $path = null): void
{
    F::copy(getPathFor($env), getPathFor($path.'.env'));
}

function deleteEnv(string $env = '.env', ?string $path = null): void
{
    F::remove(
        getPathFor($path.$env)
    );
}
