63 lines
1.8 KiB
PHP
63 lines
1.8 KiB
PHP
<?php
|
|
declare(strict_types=1);
|
|
|
|
namespace Phred\Tests\Feature;
|
|
|
|
use PHPUnit\Framework\TestCase;
|
|
use Phred\Http\Kernel;
|
|
use Nyholm\Psr7\ServerRequest;
|
|
use Phred\Support\Storage\StorageManager;
|
|
use Psr\SimpleCache\CacheInterface;
|
|
use Psr\Http\Client\ClientInterface;
|
|
use GuzzleHttp\Psr7\Request;
|
|
|
|
class M12OpportunityRadarTest extends TestCase
|
|
{
|
|
private object $app;
|
|
|
|
protected function setUp(): void
|
|
{
|
|
$root = dirname(__DIR__, 2);
|
|
$this->app = require $root . '/bootstrap/app.php';
|
|
}
|
|
|
|
public function test_storage_url_generation(): void
|
|
{
|
|
$manager = $this->app->container()->get(StorageManager::class);
|
|
$this->assertInstanceOf(StorageManager::class, $manager);
|
|
|
|
// Test with public disk url
|
|
$url = $manager->url('avatars/user.jpg', 'public');
|
|
$this->assertStringContainsString('/storage/avatars/user.jpg', $url);
|
|
}
|
|
|
|
public function test_cache_service_is_bound(): void
|
|
{
|
|
$cache = $this->app->container()->get(CacheInterface::class);
|
|
$this->assertInstanceOf(CacheInterface::class, $cache);
|
|
|
|
$cache->set('radar_test', 'working', 10);
|
|
$this->assertEquals('working', $cache->get('radar_test'));
|
|
$cache->delete('radar_test');
|
|
}
|
|
|
|
public function test_http_client_profiling(): void
|
|
{
|
|
putenv('APP_DEBUG=true');
|
|
\Phred\Support\Config::clear();
|
|
\Phred\Http\Middleware\Middleware::recordTiming('Warmup', 0.0);
|
|
|
|
$kernel = new Kernel();
|
|
$client = $kernel->container()->get(ClientInterface::class);
|
|
|
|
try {
|
|
$client->sendRequest(new Request('GET', 'http://localhost:1'));
|
|
} catch (\Throwable) {
|
|
// expected to fail
|
|
}
|
|
|
|
$timings = \Phred\Http\Middleware\Middleware::getTimings();
|
|
$this->assertArrayHasKey('HTTP: localhost', $timings);
|
|
}
|
|
}
|