Phred/tests/Feature/M11FeaturesTest.php

81 lines
2.5 KiB
PHP
Raw Normal View History

<?php
declare(strict_types=1);
namespace Phred\Tests\Feature;
use GuzzleHttp\Psr7\Request;
use League\Flysystem\Filesystem;
use PHPUnit\Framework\TestCase;
use Psr\Http\Client\ClientInterface;
use Psr\Log\LoggerInterface;
final class M11FeaturesTest extends TestCase
{
private object $app;
protected function setUp(): void
{
$root = dirname(__DIR__, 2);
$this->app = require $root . '/bootstrap/app.php';
}
public function testLoggingServiceIsBoundAndFunctional(): void
{
$logger = $this->app->container()->get(LoggerInterface::class);
$this->assertInstanceOf(LoggerInterface::class, $logger);
$logFile = getcwd() . '/storage/logs/test.log';
if (file_exists($logFile)) {
unlink($logFile);
}
// Use a custom logger instance for the test to ensure it writes to our test file
$testLogger = new \Monolog\Logger('test');
$testLogger->pushHandler(new \Monolog\Handler\StreamHandler($logFile));
$testLogger->info('M11 Logging Test');
$this->assertFileExists($logFile);
$this->assertStringContainsString('M11 Logging Test', file_get_contents($logFile));
unlink($logFile);
}
public function testHttpClientIsBound(): void
{
$client = $this->app->container()->get(ClientInterface::class);
$this->assertInstanceOf(ClientInterface::class, $client);
}
public function testStorageServiceIsBoundAndFunctional(): void
{
$storage = $this->app->container()->get(Filesystem::class);
$this->assertInstanceOf(Filesystem::class, $storage);
$filename = 'm11_test.txt';
$content = 'M11 Storage Content';
$storage->write($filename, $content);
$this->assertTrue($storage->fileExists($filename));
$this->assertSame($content, $storage->read($filename));
$storage->delete($filename);
$this->assertFalse($storage->fileExists($filename));
}
public function testProviderDriverValidation(): void
{
// Test TemplateServiceProvider validation
$config = new \Phred\Support\DefaultConfig();
$builder = new \DI\ContainerBuilder();
$provider = new \Phred\Providers\Core\TemplateServiceProvider();
// Mock env to trigger failure
putenv('TEMPLATE_DRIVER=invalid');
$this->expectException(\RuntimeException::class);
$this->expectExceptionMessage('Unsupported template driver: invalid');
$provider->register($builder, $config);
// Reset env
putenv('TEMPLATE_DRIVER');
}
}