2025-12-23 00:00:45 +00:00
|
|
|
<?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();
|
|
|
|
|
|
2025-12-23 00:12:38 +00:00
|
|
|
$original = getenv('TEMPLATE_DRIVER');
|
2025-12-23 00:00:45 +00:00
|
|
|
// Mock env to trigger failure
|
|
|
|
|
putenv('TEMPLATE_DRIVER=invalid');
|
2025-12-23 00:12:38 +00:00
|
|
|
try {
|
|
|
|
|
$this->expectException(\RuntimeException::class);
|
|
|
|
|
$this->expectExceptionMessage('Unsupported template driver: invalid');
|
|
|
|
|
$provider->register($builder, $config);
|
|
|
|
|
} finally {
|
|
|
|
|
// Reset env
|
|
|
|
|
if ($original === false) {
|
|
|
|
|
putenv('TEMPLATE_DRIVER');
|
|
|
|
|
} else {
|
|
|
|
|
putenv("TEMPLATE_DRIVER=$original");
|
|
|
|
|
}
|
|
|
|
|
}
|
2025-12-23 00:00:45 +00:00
|
|
|
}
|
|
|
|
|
}
|