Files
bad-ip-blocker/tests/TestCase.php
T
2026-11-11 23:19:20 +01:00

49 lines
1.2 KiB
PHP

<?php
namespace Mattitja\BadIpBlocker\Tests;
use Illuminate\Support\Facades\File;
use Mattitja\BadIpBlocker\BadIpBlockerServiceProvider;
use Mattitja\BadIpBlocker\Facades\BadIpBlocker;
use Orchestra\Testbench\TestCase as Orchestra;
abstract class TestCase extends Orchestra
{
protected string $storageDir;
protected function getPackageProviders($app): array
{
return [BadIpBlockerServiceProvider::class];
}
protected function getPackageAliases($app): array
{
return ['BadIpBlocker' => BadIpBlocker::class];
}
protected function defineEnvironment($app): void
{
$this->storageDir = sys_get_temp_dir().'/bad-ip-blocker-tests-'.bin2hex(random_bytes(4));
$app['config']->set('bad-ip-blocker.storage_path', $this->storageDir.'/bad-ips.json');
$app['config']->set('cache.default', 'array');
}
protected function defineRoutes($router): void
{
$router->get('/', fn () => 'ok');
}
protected function tearDown(): void
{
File::deleteDirectory($this->storageDir);
parent::tearDown();
}
protected function getFrom(string $uri, string $ip)
{
return $this->withServerVariables(['REMOTE_ADDR' => $ip])->get($uri);
}
}