Skip to content

Commit dd45dc7

Browse files
authored
Merge pull request #56 from danielme85/v4
V4
2 parents 10a0dd4 + f8ad4e6 commit dd45dc7

File tree

4 files changed

+38
-44
lines changed

4 files changed

+38
-44
lines changed

phpunit.xml

Lines changed: 14 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,16 @@
11
<?xml version="1.0" encoding="UTF-8"?>
2-
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" backupGlobals="false" backupStaticAttributes="false"
3-
colors="true" convertErrorsToExceptions="true" convertNoticesToExceptions="true"
4-
convertWarningsToExceptions="true" processIsolation="false" stopOnFailure="false"
5-
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/9.3/phpunit.xsd">
6-
<coverage>
7-
<include>
8-
<directory suffix=".php">./src</directory>
9-
</include>
10-
<exclude>
11-
<directory>./vendor</directory>
12-
</exclude>
13-
</coverage>
14-
<testsuites>
15-
<testsuite name="Test Suite danielme85/laravel-log-to-db">
16-
<directory suffix=".php">./tests/</directory>
17-
</testsuite>
18-
</testsuites>
2+
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" backupGlobals="false" colors="true" processIsolation="false" stopOnFailure="false" xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/10.0/phpunit.xsd" cacheDirectory=".phpunit.cache" backupStaticProperties="false">
3+
<coverage>
4+
<include>
5+
<directory suffix=".php">./src</directory>
6+
</include>
7+
<exclude>
8+
<directory>./vendor</directory>
9+
</exclude>
10+
</coverage>
11+
<testsuites>
12+
<testsuite name="Test Suite danielme85/laravel-log-to-db">
13+
<directory suffix=".php">./tests/</directory>
14+
</testsuite>
15+
</testsuites>
1916
</phpunit>

readme.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,8 @@ Uses Laravel native logging functionality trough [Monolog](https://github.com/Se
2121
* [Local Testing With Docker](#local-testing-with-docker)
2222

2323

24-
> :warning: This project should be backwards compatible down to and including Laravel 5.6 and php 7.1.
25-
> <br>However testing of current version and main branch is currently only with php 8.1 and Laravel 9.
24+
> :warning: For Laravel version 10 and beyond, please use version 4 or later of this package.
25+
> <br> For Laravel version 5.6 to 9, please use version 3.x.x.
2626
2727
## Installation
2828
Use the composer require or add to composer.json.

tests/CustomEloquentModel.php

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
<?php
22

3-
namespace danielme85\LaravelLogToDB\Tests;
4-
53
use danielme85\LaravelLogToDB\Models\LogToDbCreateObject;
64
use Illuminate\Database\Eloquent\Model;
75

@@ -17,12 +15,4 @@ class CustomEloquentModel extends Model
1715
protected $connection = 'mysql';
1816
protected $table = 'log';
1917

20-
protected static function boot()
21-
{
22-
parent::boot();
23-
24-
static::created(function ($log) {
25-
throw new \ErrorException($log->message);
26-
});
27-
}
2818
}

tests/LogToDbTest.php

Lines changed: 22 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,20 @@
11
<?php
22

33
use danielme85\LaravelLogToDB\LogToDB;
4+
use danielme85\LaravelLogToDB\LogToDbHandler;
45
use danielme85\LaravelLogToDB\Models\DBLogException;
6+
use danielme85\LaravelLogToDB\Processors\PhpVersionProcessor;
7+
use Dotenv\Dotenv;
58
use Illuminate\Support\Facades\Log;
69
use Illuminate\Support\Facades\Queue;
710
use danielme85\LaravelLogToDB\Jobs\SaveNewLogEvent;
811
use Monolog\LogRecord;
12+
use Monolog\Processor\HostnameProcessor;
13+
use Monolog\Processor\MemoryUsageProcessor;
14+
use Orchestra\Testbench\TestCase;
15+
use Symfony\Component\HttpKernel\Exception\BadRequestHttpException;
916

10-
class LogToDbTest extends Orchestra\Testbench\TestCase
17+
class LogToDbTest extends TestCase
1118
{
1219
/**
1320
* Setup the test environment.
@@ -37,7 +44,7 @@ protected function defineDatabaseMigrations()
3744
*/
3845
protected function defineEnvironment($app)
3946
{
40-
$dotenv = Dotenv\Dotenv::createImmutable(__DIR__.'/../', '.env.testing');
47+
$dotenv = Dotenv::createImmutable(__DIR__.'/../', '.env.testing');
4148
$dotenv->load();
4249

4350
$app['config']->set('database.default', 'mysql');
@@ -73,33 +80,33 @@ protected function defineEnvironment($app)
7380
],
7481
'database' => [
7582
'driver' => 'custom',
76-
'via' => danielme85\LaravelLogToDB\LogToDbHandler::class,
83+
'via' => LogToDbHandler::class,
7784
'level' => 'debug',
7885
'connection' => 'default',
7986
'collection' => 'log',
8087
'max_records' => 10,
8188
'max_hours' => 1,
8289
'processors' => [
83-
Monolog\Processor\HostnameProcessor::class,
84-
Monolog\Processor\MemoryUsageProcessor::class,
85-
danielme85\LaravelLogToDB\Processors\PhpVersionProcessor::class
90+
HostnameProcessor::class,
91+
MemoryUsageProcessor::class,
92+
PhpVersionProcessor::class
8693
]
8794
],
8895
'mongodb' => [
8996
'driver' => 'custom',
90-
'via' => danielme85\LaravelLogToDB\LogToDbHandler::class,
97+
'via' => LogToDbHandler::class,
9198
'level' => 'debug',
9299
'connection' => 'mongodb',
93100
'collection' => 'log',
94101
'max_records' => 10,
95102
'max_hours' => 1,
96103
'processors' => [
97-
Monolog\Processor\HostnameProcessor::class
104+
HostnameProcessor::class
98105
]
99106
],
100107
'limited' => [
101108
'driver' => 'custom',
102-
'via' => danielme85\LaravelLogToDB\LogToDbHandler::class,
109+
'via' => LogToDbHandler::class,
103110
'level' => 'warning',
104111
'detailed' => false,
105112
'max_records' => false,
@@ -139,7 +146,7 @@ public function testClassInit()
139146
$this->assertInstanceOf(LogToDB::class, app('laravel-log-to-db'));
140147
$this->assertInstanceOf(LogToDB::class, new LogToDB());
141148

142-
//Class works, now let's cleanup possible failed test
149+
//Class works, now lets cleanup possible failed test
143150
LogToDB::model()->truncate();
144151
LogToDB::model('mongodb')->truncate();
145152
}
@@ -220,7 +227,7 @@ public function testLoggingToChannels()
220227
*/
221228
public function testException()
222229
{
223-
$e = new Symfony\Component\HttpKernel\Exception\BadRequestHttpException("This is a fake 500 error", null, 500, ['fake-header' => 'value']);
230+
$e = new BadRequestHttpException("This is a fake 500 error", null, 500, ['fake-header' => 'value']);
224231
Log::warning("Error", ['exception' => $e, 'more' => 'infohere']);
225232
$log = LogToDB::model()->where('message', 'Error')->first();
226233
$this->assertNotEmpty($log->context);
@@ -314,12 +321,12 @@ public function testSaveNewLogEventJob()
314321
$logToDb = new LogToDB();
315322
$record = new LogRecord(
316323
datetime: new \Monolog\DateTimeImmutable(true),
324+
channel: 'local',
325+
level: \Monolog\Level::Info,
317326
message: 'job-test',
318327
context: [],
319-
level: \Monolog\Level::Info,
320-
channel: 'local',
321328
extra: [],
322-
formatted: "[2019-10-04T17:26:38.446827+00:00] local.INFO: test [] []\n"
329+
formatted: "[2019-10-04T17:26:38.446827+00:00] local.INFO: test [] []\n",
323330
);
324331

325332
$job = new SaveNewLogEvent($logToDb, $record);
@@ -451,7 +458,7 @@ public function testStandAloneModels()
451458
*/
452459
public function testCustomModel()
453460
{
454-
config()->set('logtodb.model', \danielme85\LaravelLogToDB\Tests\CustomEloquentModel::class);
461+
config()->set('logtodb.model', CustomEloquentModel::class);
455462
Log::info('This is on a custom model class');
456463
$this->assertStringContainsString('This is on a custom model class', LogToDB::model()->latest('id')->first()->message);
457464
}

0 commit comments

Comments
 (0)