<?php

namespace Tests;

use Illuminate\Foundation\Testing\TestCase as BaseTestCase;

abstract class TestCase extends BaseTestCase
{
    protected function setUp(): void
    {
        // Redirect compiled view storage to a test-specific directory BEFORE
        // parent::setUp() boots the app so the env var is read during config load.
        // This prevents the Windows file-locking conflict with the Laragon web server
        // over the same compiled Blade view temp files (rename "Access is denied").
        $testViewsPath = dirname(__DIR__) . DIRECTORY_SEPARATOR . 'storage'
            . DIRECTORY_SEPARATOR . 'framework'
            . DIRECTORY_SEPARATOR . 'views-testing';

        if (!is_dir($testViewsPath)) {
            mkdir($testViewsPath, 0777, true);
        }

        putenv('VIEW_COMPILED_PATH=' . $testViewsPath);
        $_ENV['VIEW_COMPILED_PATH']    = $testViewsPath;
        $_SERVER['VIEW_COMPILED_PATH'] = $testViewsPath;

        parent::setUp();

        // Belt-and-suspenders: override after boot in case config was already cached
        config(['view.compiled' => $testViewsPath]);
    }
}
