Skip to content

Commit 3c3eb31

Browse files
danielme85Manriel
andauthored
Compability updates and bugfix (#60)
* update for new Mongodb version 4. * remove circleci, update dockerfile to create php 8.2 container. * Circualr log writes fix (#59) * Circualr log writes fix * update testing, composer, and phpunit config * try github action again. * use different env for local vs github action testing. * ignore phpunit cache folder Thanks for your help @Manriel ! --------- Co-authored-by: Roman Shershnev <Manriel@users.noreply.github.com>
1 parent e07c2ab commit 3c3eb31

19 files changed

+204
-115
lines changed

.circleci/config.yml

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

.github/workflows/unittest.yml

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
# GitHub Action for Laravel with MySQL and Redis
2+
name: Testing Laravel with MySQL
3+
on: [pull_request]
4+
jobs:
5+
laravel:
6+
name: Laravel (PHP ${{ matrix.php-versions }})
7+
runs-on: ubuntu-latest
8+
env:
9+
DB_DATABASE: logtodb
10+
DB_USERNAME: root
11+
DB_PASSWORD: root
12+
BROADCAST_DRIVER: log
13+
CACHE_DRIVER: file
14+
QUEUE_CONNECTION: file
15+
SESSION_DRIVER: file
16+
17+
# Docs: https://docs.github.com/en/actions/using-containerized-services
18+
services:
19+
mysql:
20+
image: mysql:latest
21+
env:
22+
MYSQL_ALLOW_EMPTY_PASSWORD: false
23+
MYSQL_ROOT_PASSWORD: root
24+
MYSQL_DATABASE: logtodb
25+
ports:
26+
- 3306/tcp
27+
options: --health-cmd="mysqladmin ping" --health-interval=10s --health-timeout=5s --health-retries=3
28+
29+
strategy:
30+
fail-fast: false
31+
matrix:
32+
php-versions: ['8.2']
33+
steps:
34+
- name: Checkout
35+
uses: actions/checkout@v3
36+
37+
- name: Start MongoDB
38+
uses: supercharge/mongodb-github-action@1.10.0
39+
with:
40+
mongodb-version: 7.0
41+
42+
# Docs: https://github.com/shivammathur/setup-php
43+
- name: Setup PHP
44+
uses: shivammathur/setup-php@v2
45+
with:
46+
php-version: ${{ matrix.php-versions }}
47+
extensions: mbstring, dom, fileinfo, mysql, mongodb
48+
coverage: xdebug
49+
50+
# Local MySQL service in GitHub hosted environments is disabled by default.
51+
# If you are using it instead of service containers, make sure you start it.
52+
# - name: Start mysql service
53+
# run: sudo systemctl start mysql.service
54+
55+
- name: Install Composer dependencies
56+
run: composer install --no-progress
57+
58+
- name: Test with phpunit
59+
run: vendor/bin/phpunit --coverage-clover ./coverage.xml
60+
env:
61+
DB_PORT: ${{ job.services.mysql.ports['3306'] }}
62+
63+
- name: Upload to Codecov
64+
uses: codecov/codecov-action@v2
65+
with:
66+
token: ${{ secrets.CODE_COV_TOKEN }}
67+
files: ./coverage.xml
68+
verbose: true

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,4 +15,5 @@ coverage.xml
1515
.phpstorm.meta.php
1616
_ide_helper.php
1717
_ide_helper_models.php.php
18-
.phpunit.result.cache
18+
.phpunit.result.cache
19+
.phpunit.cache

.phpunit.cache/test-results

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{"version":1,"defects":{"LogToDbTest::testClassInit":8,"LogToDbTest::testLogLevels":8,"LogToDbTest::testContext":8,"LogToDbTest::testProcessors":8,"LogToDbTest::testLoggingToChannels":8,"LogToDbTest::testException":8,"LogToDbTest::testExceptionWrongFormat":8,"LogToDbTest::testExceptionIgnore":8,"LogToDbTest::testQueue":8,"LogToDbTest::testSaveNewLogEventJob":8,"LogToDbTest::testModelInteraction":8,"LogToDbTest::testStandAloneModels":8,"LogToDbTest::testCustomModel":8,"LogToDbTest::testRemoves":8,"LogToDbTest::testCleanerUpper":8,"LogToDbTest::testFinalCleanup":8},"times":{"FailureTest::testEmergencyFailure":0.062,"LogToDbTest::testClassInit":0.022,"LogToDbTest::testLogLevels":0.026,"LogToDbTest::testContext":0.011,"LogToDbTest::testProcessors":0.009,"LogToDbTest::testLoggingToChannels":0.009,"LogToDbTest::testException":0.016,"LogToDbTest::testExceptionWrongFormat":0.009,"LogToDbTest::testExceptionIgnore":0.006,"LogToDbTest::testQueue":0.015,"LogToDbTest::testSaveNewLogEventJob":0.007,"LogToDbTest::testModelInteraction":0.055,"LogToDbTest::testStandAloneModels":0.011,"LogToDbTest::testCustomModel":0.008,"LogToDbTest::testRemoves":2.09,"LogToDbTest::testCleanerUpper":0.055,"LogToDbTest::testFinalCleanup":0.012}}

buildDockerImages.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
#!/bin/bash
22
echo "Building PHP8 image..." &&
3-
cd ./docker/php8 && docker buildx build --platform linux/amd64,linux/arm64 --push . -t ghcr.io/danielme85/lltdb-testbench:latest
3+
cd ./docker/php8 && docker buildx build --push . -t ghcr.io/danielme85/lltdb-testbench:latest

composer.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,11 @@
1616
},
1717
"require-dev": {
1818
"ext-mongodb": "*",
19+
"phpunit/phpunit": "9.*",
1920
"orchestra/testbench": "^8.0",
2021
"mockery/mockery": "^1.5",
2122
"nunomaduro/collision": "^7.0",
22-
"jenssegers/mongodb": "dev-master"
23+
"mongodb/laravel-mongodb": "^4"
2324
},
2425
"suggest": {
2526
"jenssegers/mongodb": "Adds support for MongoDB in Laravel/Eloquent"
@@ -39,5 +40,5 @@
3940
}
4041
}
4142
},
42-
"minimum-stability": "stable"
43+
"minimum-stability": "dev"
4344
}

docker-compose.yaml

Lines changed: 21 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -2,52 +2,50 @@
22
version: "3.0"
33
services:
44

5-
mariadb:
5+
logto-mariadb:
66
image: mariadb:latest
7-
container_name: laravel-log-to-db-mariadb
7+
container_name: logto-mariadb
88
networks:
99
- laravel-log-to-db-testing
10-
ports:
11-
- "3366:3306"
1210
environment:
1311
MYSQL_DATABASE: 'logtodb'
1412
MYSQL_ROOT_PASSWORD: 'root'
1513
MYSQL_ALLOW_EMPTY_PASSWORD: 'yes'
1614

17-
mongo:
15+
logto-mongodb:
1816
image: mongo:latest
19-
container_name: laravel-log-to-db-mongodb
17+
container_name: logto-mongodb
2018
networks:
2119
- laravel-log-to-db-testing
22-
ports:
23-
- "27888:27017"
2420

2521
php8:
26-
image: ghcr.io/danielme85/lltdb-testbench
22+
build:
23+
dockerfile: ./docker/php8/Dockerfile
2724
container_name: laravel-log-to-db-php8
2825
tty: true
29-
depends_on:
30-
- "mariadb"
31-
- "mongo"
3226
networks:
3327
- laravel-log-to-db-testing
3428
volumes:
3529
- .:/var/testing
30+
depends_on:
31+
- logto-mariadb
32+
- logto-mongodb
3633
environment:
37-
- DB_CONNECTION=mysql
38-
- DB_HOST=mariadb
39-
- DB_PORT=3306
40-
- DB_DATABASE=logtodb
41-
- DB_USERNAME=root
42-
- DB_PASSWORD=root
43-
- MDB_DATABASE=logtodb
44-
- MDB_HOST=mongo
45-
- MDB_PORT=27017
34+
WAIT_HOSTS: logto-mariadb:3306, logto-mongodb:27017
35+
DB_CONNECTION: mysql
36+
DB_HOST: logto-mariadb
37+
DB_PORT: 3306
38+
DB_DATABASE: logtodb
39+
DB_USERNAME: root
40+
DB_PASSWORD: root
41+
MDB_DATABASE: logtodb
42+
MDB_HOST: logto-mongodb
43+
MDB_PORT: 27017
4644
entrypoint: bash -c "
45+
/wait &&
4746
cd /var/testing &&
4847
composer install --no-interaction &&
49-
dockerize -wait tcp://mariadb:3306 -timeout 1m &&
50-
./vendor/bin/testbench package:test
48+
./vendor/bin/phpunit
5149
"
5250
5351
networks:

docker/php8/Dockerfile

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,17 @@ FROM ubuntu:jammy
33
LABEL Maintainer="Daniel Mellum <mellum@gmail.com>" \
44
Description="A simple docker image used in phpunit testing Laravel apps."
55

6-
ENV DOCKERIZE_VERSION v0.6.1
6+
ENV DOCKERIZE_VERSION v0.7.0
77
ENV TZ=America/New_York
88
ARG DEBIAN_FRONTEND=noninteractive
99

1010
WORKDIR /
1111

12+
RUN apt update && apt install -y lsb-release gnupg2 ca-certificates apt-transport-https software-properties-common
13+
RUN apt update && add-apt-repository ppa:ondrej/php
1214
RUN apt update && apt upgrade -y
13-
RUN apt install -y curl git openssl openssh-client mysql-client bash libzip-dev zip wget \
14-
php8.1 php8.1-dev php8.1-mysql php8.1-mongodb php8.1-curl php8.1-mbstring php8.1-pcov php8.1-cli
15+
RUN apt install -y curl git openssl openssh-client mysql-client bash libzip-dev zip wget
16+
RUN apt install -y php8.2 php8.2-dev php8.2-mysql php8.2-mongodb php8.2-curl php8.2-mbstring php8.2-pcov php8.2-cli
1517

1618
RUN pecl install pcov
1719
RUN pecl install mongodb
@@ -26,7 +28,10 @@ RUN wget https://github.com/jwilder/dockerize/releases/download/$DOCKERIZE_VERSI
2628

2729
RUN curl -sS https://getcomposer.org/installer | php -- --install-dir=/usr/local/bin --filename=composer
2830

31+
ADD https://github.com/ufoscout/docker-compose-wait/releases/download/2.2.1/wait /wait
32+
RUN chmod +x /wait
33+
2934
COPY entrypoint.sh /entrypoint.sh
3035
RUN chmod +x /entrypoint.sh
3136

32-
ENTRYPOINT ["/entrypoint.sh"]
37+
ENTRYPOINT ["/entrypoint.sh"]

phpunit.xml

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

phpunit.xml.bak

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

runLocalTestInDocker.sh

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
#!/bin/bash
2-
docker-compose up -d mariadb mongo &&
3-
docker-compose up php8 &&
4-
docker-compose down
2+
docker compose up -d logto-mariadb logto-mongodb &&
3+
docker compose up php8 &&
4+
docker compose down

src/Jobs/SaveNewLogEvent.php

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ class SaveNewLogEvent implements ShouldQueue
1919
* @param \Monolog\LogRecord $record
2020
* @return void
2121
*/
22-
public function __construct(protected $logToDb, protected LogRecord $record)
22+
public function __construct(protected object $logToDb, protected LogRecord $record)
2323
{
2424
}
2525

@@ -30,15 +30,6 @@ public function __construct(protected $logToDb, protected LogRecord $record)
3030
*/
3131
public function handle()
3232
{
33-
try {
34-
$model = $this->logToDb->getModel();
35-
$log = $model->generate(
36-
$this->record,
37-
$this->logToDb->getConfig('detailed')
38-
);
39-
$log->save();
40-
} catch (\Throwable $e) {
41-
throw new DBLogException($e->getMessage());
42-
}
33+
$this->logToDb->safeWrite($this->record);
4334
}
44-
}
35+
}

0 commit comments

Comments
 (0)