fn_b/tests/Feature/IllustrationEnvironmentTest.php

40 lines
1.6 KiB
PHP

<?php
namespace Tests\Feature;
use App\Services\IllustrationPool;
use PHPUnit\Framework\Attributes\PreserveGlobalState;
use PHPUnit\Framework\Attributes\RunTestsInSeparateProcesses;
use Tests\TestCase;
#[RunTestsInSeparateProcesses]
#[PreserveGlobalState(false)]
class IllustrationEnvironmentTest extends TestCase
{
public function test_production_requires_enabled_flag_and_registered_https_origin(): void
{
$this->app['env'] = 'production';
config(['illustrations.enabled' => true, 'illustrations.base_url' => 'http://resource.loc:8612']);
$this->assertFalse(IllustrationPool::enabled());
config(['illustrations.base_url' => 'https://resource-v2.gemcook.net']);
$this->assertTrue(IllustrationPool::enabled());
config(['illustrations.enabled' => false]);
$this->assertFalse(IllustrationPool::enabled());
}
public function test_local_and_unregistered_environments_cannot_use_production_origin(): void
{
$this->app['env'] = 'local';
config(['illustrations.enabled' => true, 'illustrations.base_url' => 'https://resource-v2.gemcook.net']);
$this->assertFalse(IllustrationPool::enabled());
config(['illustrations.base_url' => 'http://resource.loc:8612']);
$this->assertTrue(IllustrationPool::enabled());
$this->app['env'] = 'staging';
$this->assertFalse(IllustrationPool::enabled());
config(['illustrations.base_url' => 'https://test.clashfreenode.com/resource-v2']);
$this->assertTrue(IllustrationPool::enabled());
$this->app['env'] = 'production';
$this->assertFalse(IllustrationPool::enabled());
}
}