Skip to content

Commit 13f19c1

Browse files
committed
1.0.1
1 parent efb4d0d commit 13f19c1

6 files changed

Lines changed: 105 additions & 10 deletions

File tree

check-deployed-package/Dockerfile

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,25 @@ FROM php:8.3-cli
22

33
WORKDIR /app
44

5+
# Install system dependencies needed for PHP extensions and Composer
6+
RUN apt-get update && apt-get install -y \
7+
git \
8+
unzip \
9+
zip \
10+
libzip-dev \
11+
pkg-config \
12+
&& docker-php-ext-install zip \
13+
&& rm -rf /var/lib/apt/lists/*
14+
515
# Install Composer
616
COPY --from=composer:latest /usr/bin/composer /usr/bin/composer
717

818
# Copy composer.json for the test application
919
COPY check-deployed-package/composer.json /app/
1020
COPY check-deployed-package/check.php /app/
1121

12-
# Install the published logdash package from Packagist
13-
RUN composer require logdash/php-sdk
22+
# Install dependencies including the published logdash package from Packagist
1423
RUN composer install --no-dev --optimize-autoloader
1524

1625
# Run the application
17-
CMD ["php", "check.php"]
26+
CMD ["php", "check.php"]

check-deployed-package/check.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
declare(strict_types=1);
44

5-
require_once __DIR__ . '/../vendor/autoload.php';
5+
require_once __DIR__ . '/vendor/autoload.php';
66

77
use Logdash\Logdash;
88

check-deployed-package/composer.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@
33
"description": "Test application for Logdash PHP SDK deployed package",
44
"type": "project",
55
"require": {
6-
"php": ">=8.1"
6+
"php": ">=8.1",
7+
"logdash/php-sdk": "^1.0"
78
},
89
"autoload": {
910
"psr-4": {

src/LogDash.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@
99
use Logdash\Types\InitializationParams;
1010
use Logdash\Types\RequiredInitializationParams;
1111

12+
require_once __DIR__ . '/Types/LogLevel.php';
13+
require_once __DIR__ . '/Logger/InternalLogger.php';
1214
require_once __DIR__ . '/Metrics/CreateMetrics.php';
1315
require_once __DIR__ . '/Sync/CreateLogSync.php';
1416

src/Logger/Logger.php

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,19 @@ class Logger
1818
LogLevel::SILLY->value => [80, 80, 80],
1919
];
2020

21+
private readonly mixed $logMethod;
22+
private readonly mixed $prefix;
23+
private readonly mixed $onLog;
24+
2125
public function __construct(
22-
private readonly ?callable $logMethod = null,
23-
private readonly ?callable $prefix = null,
24-
private readonly ?callable $onLog = null
25-
) {}
26+
?callable $logMethod = null,
27+
?callable $prefix = null,
28+
?callable $onLog = null
29+
) {
30+
$this->logMethod = $logMethod;
31+
$this->prefix = $prefix;
32+
$this->onLog = $onLog;
33+
}
2634

2735
public function error(mixed ...$data): void
2836
{
@@ -39,7 +47,7 @@ public function info(mixed ...$data): void
3947
$this->log(LogLevel::INFO, implode(' ', $this->convertToStrings($data)));
4048
}
4149

42-
public function log(LogLevel|mixed ...$data): void
50+
public function log(mixed ...$data): void
4351
{
4452
if (count($data) === 0) {
4553
return;

tests/LogDashTest.php

Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
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

Comments
 (0)