Skip to content

Commit 143b30e

Browse files
authored
Merge branch 'master' into patch-1
2 parents 6630b35 + efe4092 commit 143b30e

File tree

5 files changed

+76
-28
lines changed

5 files changed

+76
-28
lines changed

.circleci/config.yml

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
version: 2.1
2+
3+
jobs:
4+
test:
5+
docker:
6+
- image: danielme/laravel-cli:latest
7+
- image: circleci/mongo:latest
8+
- image: circleci/mysql:5.7
9+
environment:
10+
MYSQL_ALLOW_EMPTY_PASSWORD: 'yes'
11+
MYSQL_ROOT_PASSWORD: ''
12+
13+
working_directory: ~/app
14+
steps:
15+
- checkout
16+
- run:
17+
name: Wait for Database Connection
18+
command: dockerize -wait tcp://localhost:3306 -timeout 1m
19+
- run: mysql -h 127.0.0.1 -u root -e "create database testing"
20+
21+
- restore_cache:
22+
keys:
23+
- composer-v1-{{ checksum "composer.json" }}
24+
25+
- run: composer install --no-interaction
26+
- run: composer require jenssegers/mongodb --dev
27+
- run: composer require pcov/clobber --dev
28+
29+
- save_cache:
30+
key: composer-v1-{{ checksum "composer.json" }}
31+
paths:
32+
- vendor
33+
34+
- run:
35+
name: Run phpunit
36+
command: XDEBUG_MODE=coverage vendor/bin/phpunit --coverage-clover=coverage.xml
37+
38+
- run:
39+
name: Upload coverage report
40+
command: curl -s https://codecov.io/bash > ./codecov.sh && chmod +x ./codecov.sh && ./codecov.sh
41+
workflows:
42+
test:
43+
jobs:
44+
- test

.travis.yml

Lines changed: 0 additions & 17 deletions
This file was deleted.

readme.md

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,13 @@
33
[![PHP from Packagist](https://img.shields.io/packagist/php-v/danielme85/laravel-log-to-db.svg?style=flat-square)](https://packagist.org/packages/danielme85/laravel-log-to-db)
44
[![GitHub release](https://img.shields.io/github/release/danielme85/laravel-log-to-db.svg?style=flat-square)](https://packagist.org/packages/danielme85/laravel-log-to-db)
55
[![GitHub tag](https://img.shields.io/github/tag/danielme85/laravel-log-to-db.svg?style=flat-square)](https://github.com/danielme85/laravel-log-to-db)
6-
[![Travis (.org)](https://img.shields.io/travis/danielme85/laravel-log-to-db.svg?style=flat-square)](https://travis-ci.org/danielme85/laravel-log-to-db)
6+
[![CircleCi](https://img.shields.io/circleci/build/github/danielme85/laravel-log-to-db?style=flat-square)](https://app.circleci.com/pipelines/github/danielme85/laravel-log-to-db)
77
[![Codecov](https://img.shields.io/codecov/c/github/danielme85/laravel-log-to-db.svg?style=flat-square)](https://codecov.io/gh/danielme85/laravel-log-to-db)
8-
[![CodeFactor](https://www.codefactor.io/repository/github/danielme85/laravel-log-to-db/badge)](https://www.codefactor.io/repository/github/danielme85/laravel-log-to-db)
8+
[![CodeFactor](https://img.shields.io/codefactor/grade/github/danielme85/laravel-log-to-db?style=flat-square)](https://www.codefactor.io/repository/github/danielme85/laravel-log-to-db)
99

1010
Custom Laravel 5.6+ Log channel handler that can store log events to SQL or MongoDB databases.
1111
Uses Laravel native logging functionality.
1212

13-
1413
* [Installation](#installation)
1514
* [Configuration](#configuration)
1615
* [Usage](#usage)

src/LogToDB.php

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,6 @@ class LogToDB
4545
* LogToDB constructor.
4646
*
4747
* @param array $loggingConfig config values;.
48-
* @throws DBLogException
4948
*/
5049
function __construct($loggingConfig = [])
5150
{
@@ -71,11 +70,6 @@ function __construct($loggingConfig = [])
7170
if (isset($dbconfig[$this->connection])) {
7271
$this->database = $dbconfig[$this->connection];
7372
}
74-
75-
if (empty($this->database)) {
76-
throw new DBLogException("Required configs missing: The LogToDB class needs a database correctly setup in the configs: databases.php and logtodb.php");
77-
}
78-
7973
}
8074

8175
/**
@@ -126,7 +120,7 @@ public function getModel()
126120
//Use custom model
127121
if (!empty($this->model)) {
128122
return new $this->model;
129-
} else if ($this->database['driver'] === 'mongodb') {
123+
} else if (isset($this->database['driver']) && $this->database['driver'] === 'mongodb') {
130124
//MongoDB has its own Model
131125
$mongo = new DBLogMongoDB();
132126
$mongo->bind($this->connection, $this->collection);

tests/LogToDbTest.php

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ protected function getEnvironmentSetUp($app)
4646
'host' => env('DB_HOST', '127.0.0.1'),
4747
'port' => env('DB_PORT', 3306),
4848
'database' => env('DB_DATABASE', 'testing'),
49-
'username' => env('DB_USER', 'travis'),
49+
'username' => env('DB_USER', 'root'),
5050
'password' => env('DB_PASSWORD', ''),
5151
'charset' => 'utf8',
5252
'collation' => 'utf8_unicode_ci',
@@ -126,6 +126,24 @@ protected function getPackageProviders($app)
126126
];
127127
}
128128

129+
/**
130+
* Test the vendor:publish command for the migration file.
131+
*
132+
* @group publish
133+
*/
134+
public function testVendorPublish()
135+
{
136+
$this->artisan('vendor:publish', [
137+
'--tag' => 'migrations',
138+
'--provider' => 'danielme85\LaravelLogToDB\ServiceProvider'
139+
])->assertExitCode(0);
140+
141+
$this->artisan('vendor:publish', [
142+
'--tag' => 'config',
143+
'--provider' => 'danielme85\LaravelLogToDB\ServiceProvider'
144+
])->assertExitCode(0);
145+
}
146+
129147
/**
130148
* Basic test to see if class can be instanced.
131149
*
@@ -338,6 +356,16 @@ public function testSaveNewLogEventJob()
338356
$this->assertNotEmpty($logToDb->model()->where('message', '=', 'job-test')->get());
339357
}
340358

359+
/**
360+
* Test exception on save new log job.
361+
* @group job
362+
*/
363+
public function testExceptionOnSaveNewLogEvent()
364+
{
365+
$this->expectException(DBLogException::class);
366+
$job = new SaveNewLogEvent(false, []);
367+
$job->handle();
368+
}
341369

342370
/**
343371
* Test model interaction

0 commit comments

Comments
 (0)