Skip to content

Commit ac57d9c

Browse files
committed
🎉 🍾 First public commit
1 parent 93637c2 commit ac57d9c

File tree

5 files changed

+150
-5
lines changed

5 files changed

+150
-5
lines changed

.travis.yml

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,13 @@
11
language: php
22
php:
33
- 7.1
4-
- 7.2
54
- 7.3
5+
services:
6+
- mysql
7+
- mongodb
68
before_script:
9+
- pecl install mongod
10+
- mysql -e 'CREATE DATABASE testing;'
711
- composer install --no-interaction
812
script:
913
- vendor/bin/phpunit

phpunit.xml

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<phpunit backupGlobals="false"
3+
backupStaticAttributes="false"
4+
colors="true"
5+
convertErrorsToExceptions="true"
6+
convertNoticesToExceptions="true"
7+
convertWarningsToExceptions="true"
8+
processIsolation="false"
9+
stopOnFailure="false">
10+
<testsuites>
11+
<testsuite name="Test Suite danielme85/laravel-log-to-db">
12+
<directory suffix=".php">./tests/</directory>
13+
</testsuite>
14+
</testsuites>
15+
</phpunit>

src/LogToDB.php

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -139,8 +139,6 @@ public function newFromMonolog(array $record) : self
139139
}
140140
$log->unix_time = time();
141141

142-
d($this);
143-
144142
$log->save();
145143

146144
return $this;

src/ServiceProvider.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,12 +24,12 @@ class ServiceProvider extends Provider {
2424
*/
2525
public function boot()
2626
{
27+
$this->loadMigrationsFrom(__DIR__.'/migrations');
2728
$this->mergeConfigFrom(__DIR__.'/config/logtodb.php', 'logtodb');
28-
/*
2929
$this->publishes([
3030
__DIR__.'/config/larastats.php' => config_path('larastats.php'),
3131
]);
32-
*/
32+
3333
}
3434

3535
/**

tests/LogToDbTest.php

Lines changed: 128 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,128 @@
1+
<?php
2+
3+
use danielme85\LaravelLogToDB\LogToDB;
4+
use Illuminate\Support\Facades\Log;
5+
6+
class LogToDbTest extends Orchestra\Testbench\TestCase
7+
{
8+
/**
9+
* Setup the test environment.
10+
*/
11+
protected function setUp(): void
12+
{
13+
parent::setUp();
14+
15+
$this->artisan('migrate', ['--database' => 'mysql']);
16+
17+
$this->beforeApplicationDestroyed(function () {
18+
$this->artisan('migrate:rollback', ['--database' => 'mysql']);
19+
});
20+
}
21+
/**
22+
* Define environment setup.
23+
*
24+
* @param \Illuminate\Foundation\Application $app
25+
*
26+
* @return void
27+
*/
28+
protected function getEnvironmentSetUp($app)
29+
{
30+
$app['config']->set('database.default', 'mysql');
31+
$app['config']->set('database.connections',
32+
['mysql' => [
33+
'driver' => 'mysql',
34+
'host' => '127.0.0.1',
35+
'port' => 3306,
36+
'database' => 'testing',
37+
'username' => 'travis',
38+
'password' => '',
39+
'charset' => 'utf8',
40+
'collation' => 'utf8_unicode_ci',
41+
],
42+
'mongodb' => [
43+
'driver' => 'mongodb',
44+
'host' => '127.0.0.1',
45+
'port' => 27017,
46+
'database' => 'testing',
47+
'username' => '',
48+
'password' => '',
49+
'options' => [
50+
//'database' => 'admin' // sets the authentication database required by mongo 3
51+
]
52+
],]
53+
);
54+
55+
$app['config']->set('logging.default', 'stack');
56+
$app['config']->set('logging.channels', [
57+
'stack' => [
58+
'driver' => 'stack',
59+
'channels' => ['database', 'mongodb', 'single'],
60+
],
61+
'database' => [
62+
'driver' => 'custom',
63+
'via' => danielme85\LaravelLogToDB\LogToDbHandler::class,
64+
'level' => 'debug',
65+
'connection' => 'default',
66+
'collection' => 'log'
67+
],
68+
'mongodb' => [
69+
'driver' => 'custom',
70+
'via' => danielme85\LaravelLogToDB\LogToDbHandler::class,
71+
'level' => 'debug',
72+
'connection' => 'mongodb',
73+
'collection' => 'log'
74+
]
75+
]);
76+
}
77+
78+
/**
79+
* Get package providers. At a minimum this is the package being tested, but also
80+
* would include packages upon which our package depends, e.g. Cartalyst/Sentry
81+
* In a normal app environment these would be added to the 'providers' array in
82+
* the config/app.php file.
83+
*
84+
* @param \Illuminate\Foundation\Application $app
85+
*
86+
* @return array
87+
*/
88+
protected function getPackageProviders($app)
89+
{
90+
return [
91+
'danielme85\LaravelLogToDB\ServiceProvider',
92+
'Jenssegers\Mongodb\MongodbServiceProvider',
93+
];
94+
}
95+
96+
public function testClassInit() {
97+
$test = new LogToDB();
98+
$this->assertInstanceOf('danielme85\LaravelLogToDB\LogToDB', $test);
99+
}
100+
101+
public function testLogLevels() {
102+
Log::debug("This is an test DEBUG log event");
103+
Log::info("This is an test INFO log event");
104+
Log::notice("This is an test NOTICE log event");
105+
Log::warning("This is an test WARNING log event");
106+
Log::error("This is an test ERROR log event");
107+
Log::critical("This is an test CRITICAL log event");
108+
Log::alert("This is an test ALERT log event");
109+
Log::emergency("This is an test EMERGENCY log event");
110+
111+
//Check mysql
112+
$logReader = LogToDB::model()::all()->toArray();
113+
$logReaderMongoDB = LogToDB::model('mongodb')::all()->toArray();
114+
$this->assertNotEmpty($logReader);
115+
$this->assertNotEmpty($logReaderMongoDB);
116+
$this->assertCount(8, $logReader);
117+
$this->assertCount(8, $logReaderMongoDB);
118+
119+
}
120+
121+
public function testCleanup() {
122+
LogToDB::model()::truncate();
123+
LogToDB::model('mongodb')::truncate();
124+
125+
$this->assertEmpty(LogToDB::model()::all()->toArray());
126+
$this->assertEmpty(LogToDB::model('mongodb')::all()->toArray());
127+
}
128+
}

0 commit comments

Comments
 (0)