Skip to content

Commit be3ee17

Browse files
author
Daniel Mellum
committed
Update local testing to run in docker containers .
1 parent af2a4d0 commit be3ee17

File tree

10 files changed

+137
-38
lines changed

10 files changed

+137
-38
lines changed

.circleci/php7/Dockerfile

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,4 +21,10 @@ RUN apk --no-cache add
2121

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

24-
ENTRYPOINT ["/entrypoint.sh"]
24+
WORKDIR /
25+
26+
COPY entrypoint.sh /entrypoint.sh
27+
RUN chmod +x /entrypoint.sh
28+
29+
30+
ENTRYPOINT ["entrypoint.sh"]

.circleci/php7/entrypoint.sh

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,5 @@
11
#!/bin/bash
22
export DEBIAN_FRONTEND=noninteractive
3-
43
bash <(cat /etc/os-release; echo 'echo ${VERSION/*, /}')
54
php -v
6-
nginx -v
7-
8-
echo "Entrypoint/Boot actions completed..."
5+
echo "Entrypoint/Boot actions completed..."

.circleci/php8/Dockerfile

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,13 @@ RUN wget https://github.com/jwilder/dockerize/releases/download/$DOCKERIZE_VERSI
1919

2020
RUN apk --no-cache add
2121

22-
RUN curl -sS https://getcomposer.org/installer | php8 -- --install-dir=/usr/local/bin --filename=composer
22+
RUN ln -s /usr/bin/php8 /usr/bin/php
2323

24-
ENTRYPOINT ["/entrypoint.sh"]
24+
RUN curl -sS https://getcomposer.org/installer | php -- --install-dir=/usr/local/bin --filename=composer
25+
26+
WORKDIR /
27+
28+
COPY entrypoint.sh /entrypoint.sh
29+
RUN chmod +x /entrypoint.sh
30+
31+
ENTRYPOINT ["entrypoint.sh"]

.circleci/php8/entrypoint.sh

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,5 @@
11
#!/bin/bash
22
export DEBIAN_FRONTEND=noninteractive
3-
43
bash <(cat /etc/os-release; echo 'echo ${VERSION/*, /}')
54
php -v
6-
nginx -v
7-
8-
echo "Entrypoint/Boot actions completed..."
5+
echo "Entrypoint/Boot actions completed..."

.env.testing

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,8 @@
1-
DB_DATABASE=testing
2-
MDB_DATABASE=testing
1+
DB_CONNECTION=mysql
2+
DB_HOST=mariadb
3+
DB_PORT=3306
4+
DB_DATABASE=logtodb
5+
DB_USERNAME=root
6+
MDB_DATABASE=logtodb
7+
MDB_HOST=mongo
8+
MDB_PORT=27017

buildDockerImages.sh

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
#!/usr/bin/env bash
2+
echo "Building PHP7 image..." &&
3+
cd .circleci/php7 && docker build . -t danielme/laravel-circleci-php7:latest &&
4+
echo "Building PHP8 image..." &&
5+
cd ../../.circleci/php8 && docker build . -t danielme/laravel-circleci-php8:latest

docker-compose.yaml

Lines changed: 75 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,86 @@
11
---
22
version: "2.4"
33
services:
4+
45
mariadb:
5-
image: mariadb:latest
6-
container_name: mariadb_phpunit
7-
network_mode: bridge
6+
image: mariadb:10.5
7+
container_name: laravel-log-to-db-mariadb
8+
networks:
9+
- laravel-log-to-db-testbench
810
ports:
911
- "3366:3306"
1012
environment:
11-
- MYSQL_DATABASE=testing
12-
- MYSQL_USER=testing
13-
- MYSQL_ROOT_PASSWORD=norestforthetest
14-
- MYSQL_PASSWORD=norestforthetest
13+
MYSQL_DATABASE: 'logtodb'
14+
MYSQL_ALLOW_EMPTY_PASSWORD: 'yes'
1515

1616
mongo:
17-
image: mongo
18-
container_name: mongodb_phpunit
19-
restart: always
20-
network_mode: bridge
17+
image: mongo:latest
18+
container_name: laravel-log-to-db-mongodb
19+
networks:
20+
- laravel-log-to-db-testbench
2121
ports:
2222
- "27888:27017"
23+
24+
php7:
25+
image: danielme/laravel-circleci-php7:latest
26+
container_name: laravel-log-to-db-php7_testbench
27+
depends_on:
28+
- "mariadb"
29+
- "mongo"
30+
networks:
31+
- laravel-log-to-db-testbench
32+
volumes:
33+
- .:/var/testing
34+
environment:
35+
- DB_CONNECTION=mysql
36+
- DB_HOST=mariadb
37+
- DB_PORT=3306
38+
- DB_DATABASE=logtodb
39+
- DB_USERNAME=root
40+
- MDB_DATABASE=logtodb
41+
- MDB_HOST=mongo
42+
- MDB_PORT=27017
43+
44+
#entrypoint: "tail -f /dev/null"
45+
46+
entrypoint: bash -c "
47+
cd /var/testing &&
48+
composer install --no-interaction &&
49+
composer require jenssegers/mongodb --dev &&
50+
dockerize -wait tcp://mariadb:3306 -timeout 1m &&
51+
./vendor/bin/testbench package:test
52+
"
53+
54+
php8:
55+
image: danielme/laravel-circleci-php8:latest
56+
container_name: laravel-log-to-db-php8_testbench
57+
depends_on:
58+
- "mariadb"
59+
- "mongo"
60+
networks:
61+
- laravel-log-to-db-testbench
62+
volumes:
63+
- .:/var/testing
64+
environment:
65+
- DB_CONNECTION=mysql
66+
- DB_HOST=mariadb
67+
- DB_PORT=3306
68+
- DB_DATABASE=logtodb
69+
- DB_USERNAME=root
70+
- MDB_DATABASE=logtodb
71+
- MDB_HOST=mongo
72+
- MDB_PORT=27017
73+
74+
#entrypoint: "tail -f /dev/null"
75+
76+
entrypoint: bash -c "
77+
cd /var/testing &&
78+
composer install --no-interaction &&
79+
composer require jenssegers/mongodb --dev &&
80+
dockerize -wait tcp://mariadb:3306 -timeout 1m &&
81+
./vendor/bin/testbench package:test
82+
"
83+
84+
networks:
85+
laravel-log-to-db-testbench:
86+
driver: bridge

runLocalTestInDocker.sh

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

testbench.yaml

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
env:
2-
- DB_HOST=0.0.0.0
3-
- DB_PORT=3366
4-
- DB_DATABASE=testing
5-
- DB_USER=root
6-
- DB_PASSWORD=norestforthetest
7-
- MDB_DATABASE=testing
8-
- MDB_PORT=27888
2+
- DB_CONNECTION=mysql
3+
- DB_HOST=mariadb
4+
- DB_PORT=3306
5+
- DB_DATABASE=logtodb
6+
- DB_USERNAME=root
7+
- MDB_DATABASE=logtodb
8+
- MDB_HOST=mongo
9+
- MDB_PORT=27017
910

1011
providers:
11-
- danielme85\LaravelLogToDB\ServiceProvider
12+
- danielme85\LaravelLogToDB\ServiceProvider

tests/LogToDbTest.php

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,20 @@ protected function setUp(): void
1515
{
1616
parent::setUp();
1717
$this->loadMigrationsFrom(__DIR__.'/../src/migrations');
18-
$this->artisan('migrate', [
19-
'--database' => 'mysql'
20-
]);
18+
}
19+
20+
/**
21+
* Define database migrations.
22+
*
23+
* @return void
24+
*/
25+
protected function defineDatabaseMigrations()
26+
{
27+
$this->artisan('migrate', ['--database' => 'mysql'])->run();
28+
29+
//$this->beforeApplicationDestroyed(function () {
30+
// $this->artisan('migrate:rollback', ['--database' => 'testbench'])->run();
31+
//});
2132
}
2233

2334
/**
@@ -27,7 +38,7 @@ protected function setUp(): void
2738
*
2839
* @return void
2940
*/
30-
protected function getEnvironmentSetUp($app)
41+
protected function defineEnvironment($app)
3142
{
3243
$dotenv = Dotenv\Dotenv::createImmutable(__DIR__.'/../', '.env.testing');
3344
$dotenv->load();
@@ -39,7 +50,7 @@ protected function getEnvironmentSetUp($app)
3950
'host' => env('DB_HOST', '127.0.0.1'),
4051
'port' => env('DB_PORT', 3306),
4152
'database' => env('DB_DATABASE', 'testing'),
42-
'username' => env('DB_USER', 'root'),
53+
'username' => env('DB_USERNAME', 'root'),
4354
'password' => env('DB_PASSWORD', ''),
4455
'charset' => 'utf8',
4556
'collation' => 'utf8_unicode_ci',
@@ -236,7 +247,7 @@ public function testException()
236247
$this->expectException(DBLogException::class);
237248
throw new DBLogException('Dont log this');
238249
}
239-
250+
240251
/**
241252
* Test exception when expected format is wrong.
242253
*

0 commit comments

Comments
 (0)