|
1 | 1 | <?php
|
2 | 2 |
|
3 | 3 | use danielme85\LaravelLogToDB\LogToDB;
|
| 4 | +use danielme85\LaravelLogToDB\LogToDbHandler; |
4 | 5 | use danielme85\LaravelLogToDB\Models\DBLogException;
|
| 6 | +use danielme85\LaravelLogToDB\Processors\PhpVersionProcessor; |
| 7 | +use Dotenv\Dotenv; |
5 | 8 | use Illuminate\Support\Facades\Log;
|
6 | 9 | use Illuminate\Support\Facades\Queue;
|
7 | 10 | use danielme85\LaravelLogToDB\Jobs\SaveNewLogEvent;
|
8 | 11 | 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; |
9 | 16 |
|
10 |
| -class LogToDbTest extends Orchestra\Testbench\TestCase |
| 17 | +class LogToDbTest extends TestCase |
11 | 18 | {
|
12 | 19 | /**
|
13 | 20 | * Setup the test environment.
|
@@ -37,7 +44,7 @@ protected function defineDatabaseMigrations()
|
37 | 44 | */
|
38 | 45 | protected function defineEnvironment($app)
|
39 | 46 | {
|
40 |
| - $dotenv = Dotenv\Dotenv::createImmutable(__DIR__.'/../', '.env.testing'); |
| 47 | + $dotenv = Dotenv::createImmutable(__DIR__.'/../', '.env.testing'); |
41 | 48 | $dotenv->load();
|
42 | 49 |
|
43 | 50 | $app['config']->set('database.default', 'mysql');
|
@@ -73,33 +80,33 @@ protected function defineEnvironment($app)
|
73 | 80 | ],
|
74 | 81 | 'database' => [
|
75 | 82 | 'driver' => 'custom',
|
76 |
| - 'via' => danielme85\LaravelLogToDB\LogToDbHandler::class, |
| 83 | + 'via' => LogToDbHandler::class, |
77 | 84 | 'level' => 'debug',
|
78 | 85 | 'connection' => 'default',
|
79 | 86 | 'collection' => 'log',
|
80 | 87 | 'max_records' => 10,
|
81 | 88 | 'max_hours' => 1,
|
82 | 89 | '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 |
86 | 93 | ]
|
87 | 94 | ],
|
88 | 95 | 'mongodb' => [
|
89 | 96 | 'driver' => 'custom',
|
90 |
| - 'via' => danielme85\LaravelLogToDB\LogToDbHandler::class, |
| 97 | + 'via' => LogToDbHandler::class, |
91 | 98 | 'level' => 'debug',
|
92 | 99 | 'connection' => 'mongodb',
|
93 | 100 | 'collection' => 'log',
|
94 | 101 | 'max_records' => 10,
|
95 | 102 | 'max_hours' => 1,
|
96 | 103 | 'processors' => [
|
97 |
| - Monolog\Processor\HostnameProcessor::class |
| 104 | + HostnameProcessor::class |
98 | 105 | ]
|
99 | 106 | ],
|
100 | 107 | 'limited' => [
|
101 | 108 | 'driver' => 'custom',
|
102 |
| - 'via' => danielme85\LaravelLogToDB\LogToDbHandler::class, |
| 109 | + 'via' => LogToDbHandler::class, |
103 | 110 | 'level' => 'warning',
|
104 | 111 | 'detailed' => false,
|
105 | 112 | 'max_records' => false,
|
@@ -139,7 +146,7 @@ public function testClassInit()
|
139 | 146 | $this->assertInstanceOf(LogToDB::class, app('laravel-log-to-db'));
|
140 | 147 | $this->assertInstanceOf(LogToDB::class, new LogToDB());
|
141 | 148 |
|
142 |
| - //Class works, now let's cleanup possible failed test |
| 149 | + //Class works, now lets cleanup possible failed test |
143 | 150 | LogToDB::model()->truncate();
|
144 | 151 | LogToDB::model('mongodb')->truncate();
|
145 | 152 | }
|
@@ -220,7 +227,7 @@ public function testLoggingToChannels()
|
220 | 227 | */
|
221 | 228 | public function testException()
|
222 | 229 | {
|
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']); |
224 | 231 | Log::warning("Error", ['exception' => $e, 'more' => 'infohere']);
|
225 | 232 | $log = LogToDB::model()->where('message', 'Error')->first();
|
226 | 233 | $this->assertNotEmpty($log->context);
|
@@ -314,12 +321,12 @@ public function testSaveNewLogEventJob()
|
314 | 321 | $logToDb = new LogToDB();
|
315 | 322 | $record = new LogRecord(
|
316 | 323 | datetime: new \Monolog\DateTimeImmutable(true),
|
| 324 | + channel: 'local', |
| 325 | + level: \Monolog\Level::Info, |
317 | 326 | message: 'job-test',
|
318 | 327 | context: [],
|
319 |
| - level: \Monolog\Level::Info, |
320 |
| - channel: 'local', |
321 | 328 | 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", |
323 | 330 | );
|
324 | 331 |
|
325 | 332 | $job = new SaveNewLogEvent($logToDb, $record);
|
@@ -451,7 +458,7 @@ public function testStandAloneModels()
|
451 | 458 | */
|
452 | 459 | public function testCustomModel()
|
453 | 460 | {
|
454 |
| - config()->set('logtodb.model', \danielme85\LaravelLogToDB\Tests\CustomEloquentModel::class); |
| 461 | + config()->set('logtodb.model', CustomEloquentModel::class); |
455 | 462 | Log::info('This is on a custom model class');
|
456 | 463 | $this->assertStringContainsString('This is on a custom model class', LogToDB::model()->latest('id')->first()->message);
|
457 | 464 | }
|
|
0 commit comments