|
| 1 | +<?php |
| 2 | + |
| 3 | +declare(strict_types=1); |
| 4 | + |
| 5 | +namespace Logdash\Tests; |
| 6 | + |
| 7 | +use Logdash\Logdash; |
| 8 | +use Logdash\LogLevel; |
| 9 | +use PHPUnit\Framework\TestCase; |
| 10 | + |
| 11 | +class LogdashTest extends TestCase |
| 12 | +{ |
| 13 | + public function testCreateWithoutApiKey(): void |
| 14 | + { |
| 15 | + $logdash = Logdash::create(); |
| 16 | + |
| 17 | + $this->assertInstanceOf(Logdash::class, $logdash); |
| 18 | + $this->assertNotNull($logdash->logger()); |
| 19 | + $this->assertNotNull($logdash->metrics()); |
| 20 | + } |
| 21 | + |
| 22 | + public function testCreateWithApiKey(): void |
| 23 | + { |
| 24 | + $logdash = Logdash::create([ |
| 25 | + 'apiKey' => 'test-api-key', |
| 26 | + 'host' => 'https://test.logdash.io', |
| 27 | + 'verbose' => true |
| 28 | + ]); |
| 29 | + |
| 30 | + $this->assertInstanceOf(Logdash::class, $logdash); |
| 31 | + $this->assertNotNull($logdash->logger()); |
| 32 | + $this->assertNotNull($logdash->metrics()); |
| 33 | + } |
| 34 | + |
| 35 | + public function testLoggerMethods(): void |
| 36 | + { |
| 37 | + $logdash = Logdash::create(); |
| 38 | + $logger = $logdash->logger(); |
| 39 | + |
| 40 | + // Test that all log methods can be called without throwing exceptions |
| 41 | + $logger->error('Test error'); |
| 42 | + $logger->warn('Test warning'); |
| 43 | + $logger->info('Test info'); |
| 44 | + $logger->debug('Test debug'); |
| 45 | + $logger->verbose('Test verbose'); |
| 46 | + $logger->silly('Test silly'); |
| 47 | + $logger->http('Test http'); |
| 48 | + |
| 49 | + $this->assertTrue(true); // If we get here, no exceptions were thrown |
| 50 | + } |
| 51 | + |
| 52 | + public function testMetricsMethods(): void |
| 53 | + { |
| 54 | + $logdash = Logdash::create(); |
| 55 | + $metrics = $logdash->metrics(); |
| 56 | + |
| 57 | + // Test that metric methods can be called without throwing exceptions |
| 58 | + $metrics->set('test_metric', 42.5); |
| 59 | + $metrics->mutate('test_counter', 1); |
| 60 | + $metrics->mutate('test_decrement', -1); |
| 61 | + |
| 62 | + $this->assertTrue(true); // If we get here, no exceptions were thrown |
| 63 | + } |
| 64 | + |
| 65 | + public function testLogLevelEnum(): void |
| 66 | + { |
| 67 | + $this->assertEquals('error', LogLevel::ERROR->value); |
| 68 | + $this->assertEquals('warning', LogLevel::WARN->value); |
| 69 | + $this->assertEquals('info', LogLevel::INFO->value); |
| 70 | + $this->assertEquals('http', LogLevel::HTTP->value); |
| 71 | + $this->assertEquals('verbose', LogLevel::VERBOSE->value); |
| 72 | + $this->assertEquals('debug', LogLevel::DEBUG->value); |
| 73 | + $this->assertEquals('silly', LogLevel::SILLY->value); |
| 74 | + } |
| 75 | +} |
0 commit comments