Skip to content

Commit

Permalink
test: add a full e2e test to log a message
Browse files Browse the repository at this point in the history
  • Loading branch information
xel1045 committed Mar 9, 2023
1 parent ec60e6b commit d0311ae
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 1 deletion.
2 changes: 2 additions & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@
"monolog/monolog": "^2.0|^3.3"
},
"require-dev": {
"ext-sockets": "*",
"ext-zlib": "*",
"exolnet/phpcs-config": "^2.0",
"laravel/pint": "^1.2",
"mockery/mockery": "^1.4",
Expand Down
2 changes: 1 addition & 1 deletion src/GraylogServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public function register()
'handler' => GraylogHandler::class,
'handler_with' => [
'transport' => 'udp',
'host' => 'localhost',
'host' => '127.0.0.1',
'port' => 12201,
'path' => '/gelf',
'extra' => [
Expand Down
24 changes: 24 additions & 0 deletions tests/Feature/GraylogDriverTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -63,4 +63,28 @@ public function testUseGraylogHandler(): void

$this->assertInstanceOf(GraylogHandler::class, $handlers[0] ?? null);
}

/**
* @return void
* @test
*/
public function testLogging(): void
{
$socket = socket_create(AF_INET, SOCK_DGRAM, 0);
socket_bind($socket, '127.0.0.1', 12201);

$this->channel->info('Test message');

socket_recvfrom($socket, $buffer, 1024, 0, $remoteIp, $remotePort);

$json = json_decode(gzuncompress($buffer), true);

$this->assertEquals('1.0', $json['version']);
$this->assertEquals('Test message', $json['short_message']);
$this->assertEquals(6, $json['level']);
$this->assertEquals('laravel', $json['_app']);
$this->assertEquals('INFO', $json['_level_name']);
$this->assertEquals('testing', $json['_env']);
$this->assertEquals('Symfony', $json['_user_agent']);
}
}

0 comments on commit d0311ae

Please sign in to comment.