<?php

use Illuminate\Support\Facades\Cache;

test('redis cache driver can store and retrieve values', function () {
    Cache::store('redis')->put('test-key', 'test-value', 60);

    expect(Cache::store('redis')->get('test-key'))->toBe('test-value');

    Cache::store('redis')->forget('test-key');
});

test('redis queue connection is configured in env', function () {
    $env = collect(file(base_path('.env'), FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES))
        ->filter(fn ($line) => ! str_starts_with(trim($line), '#'))
        ->mapWithKeys(function ($line) {
            [$key, $value] = explode('=', $line, 2);

            return [trim($key) => trim($value)];
        });

    expect($env->get('QUEUE_CONNECTION'))->toBe('redis');
});

test('redis session driver is configured in env', function () {
    $env = collect(file(base_path('.env'), FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES))
        ->filter(fn ($line) => ! str_starts_with(trim($line), '#'))
        ->mapWithKeys(function ($line) {
            [$key, $value] = explode('=', $line, 2);

            return [trim($key) => trim($value)];
        });

    expect($env->get('SESSION_DRIVER'))->toBe('redis');
});
