Skip to content

Commit a0c605f

Browse files
committed
Docker: Fix PHP tests
This creates another mysql_testing database during db service setup Replace server with env tags in phpunit.xml in order to force override certain parameters when tests are run. See: sebastianbergmann/phpunit#2353 for more information. Rename primary developer Docker database from bookstack-test to bookstack-dev. bookstack-test is used as the mysql_testing database
1 parent ba2033a commit a0c605f

File tree

6 files changed

+29
-9
lines changed

6 files changed

+29
-9
lines changed

app/Config/database.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,10 +81,11 @@
8181
'mysql_testing' => [
8282
'driver' => 'mysql',
8383
'url' => env('TEST_DATABASE_URL'),
84-
'host' => '127.0.0.1',
84+
'host' => $mysql_host,
8585
'database' => 'bookstack-test',
8686
'username' => env('MYSQL_USER', 'bookstack-test'),
8787
'password' => env('MYSQL_PASSWORD', 'bookstack-test'),
88+
'port' => $mysql_port,
8889
'charset' => 'utf8mb4',
8990
'collation' => 'utf8mb4_unicode_ci',
9091
'prefix' => '',

dev/docker/entrypoint.app.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ else
1010
composer install
1111
wait-for-it db:3306 -t 45
1212
php artisan migrate --database=mysql
13+
php artisan migrate --database=mysql_testing
1314
chown -R www-data:www-data storage
1415
exec apache2-foreground
1516
fi

dev/docker/init.db/01.sql

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
# create test database
2+
CREATE DATABASE IF NOT EXISTS `bookstack-test`;
3+
4+
# grant rights
5+
GRANT ALL PRIVILEGES ON `bookstack-test`.* TO 'bookstack-test'@'%';

docker-compose.yml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,13 @@ services:
1010
db:
1111
image: mysql:8
1212
environment:
13-
MYSQL_DATABASE: bookstack-test
13+
MYSQL_DATABASE: bookstack-dev
1414
MYSQL_USER: bookstack-test
1515
MYSQL_PASSWORD: bookstack-test
1616
MYSQL_RANDOM_ROOT_PASSWORD: 'true'
1717
command: --default-authentication-plugin=mysql_native_password
1818
volumes:
19+
- ./dev/docker/init.db:/docker-entrypoint-initdb.d
1920
- db:/var/lib/mysql
2021
app:
2122
build:
@@ -25,7 +26,7 @@ services:
2526
DB_CONNECTION: mysql
2627
DB_HOST: db
2728
DB_PORT: 3306
28-
DB_DATABASE: bookstack-test
29+
DB_DATABASE: bookstack-dev
2930
DB_USERNAME: bookstack-test
3031
DB_PASSWORD: bookstack-test
3132
MAIL_DRIVER: smtp

phpunit.xml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
</whitelist>
2020
</filter>
2121
<php>
22-
<server name="APP_ENV" value="testing"/>
22+
<env name="APP_ENV" value="testing" force="true"/>
2323
<server name="APP_DEBUG" value="false"/>
2424
<server name="APP_LANG" value="en"/>
2525
<server name="APP_THEME" value="none"/>
@@ -29,7 +29,7 @@
2929
<server name="CACHE_DRIVER" value="array"/>
3030
<server name="SESSION_DRIVER" value="array"/>
3131
<server name="QUEUE_CONNECTION" value="sync"/>
32-
<server name="DB_CONNECTION" value="mysql_testing"/>
32+
<env name="DB_CONNECTION" value="mysql_testing" force="true"/>
3333
<server name="BCRYPT_ROUNDS" value="4"/>
3434
<server name="MAIL_DRIVER" value="array"/>
3535
<server name="LOG_CHANNEL" value="single"/>
@@ -56,5 +56,6 @@
5656
<server name="LOG_FAILED_LOGIN_MESSAGE" value=""/>
5757
<server name="LOG_FAILED_LOGIN_CHANNEL" value="testing"/>
5858
<server name="WKHTMLTOPDF" value="false"/>
59+
<ini name="memory_limit" value="1024M"/>
5960
</php>
6061
</phpunit>

readme.md

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -96,18 +96,29 @@ If all the conditions are met, you can proceed with the following steps:
9696
1. **Copy `.env.example` to `.env`**, change `APP_KEY` to a random 32 char string and set `APP_ENV` to `local`.
9797
2. Make sure **port 8080 is unused** *or else* change `DEV_PORT` to a free port on your host.
9898
3. **Run `chgrp -R docker storage`**. The development container will chown the `storage` directory to the `www-data` user inside the container so BookStack can write to it. You need to change the group to your host's `docker` group here to not lose access to the `storage` directory.
99-
4. **Run `echo -e "\n\nDOCKER_UID=$(id -u)" >> .env && echo "DOCKER_GID=$(id -g)" >> .env`** to add your UID/GID to the `.env` file. This is then used to set permissions inside the docker. This is necessary if you are working on Linux.
100-
5. **Run `docker-compose up`** and wait until the image is built and all database migrations have been done.
101-
6. You can now login with `admin@admin.com` and `password` as password on `localhost:8080` (or another port if specified).
99+
4. **Run `docker-compose up`** and wait until the image is built and all database migrations have been done.
100+
5. You can now login with `admin@admin.com` and `password` as password on `localhost:8080` (or another port if specified).
102101

103102
If needed, You'll be able to run any artisan commands via docker-compose like so:
104103

105-
```shell script
104+
```shell script
106105
docker-compose run app php artisan list
107106
```
108107

109108
The docker-compose setup runs an instance of [MailHog](https://github.com/mailhog/MailHog) and sets environment variables to redirect any BookStack-sent emails to MailHog. You can view this mail via the MailHog web interface on `localhost:8025`. You can change the port MailHog is accessible on by setting a `DEV_MAIL_PORT` environment variable.
110109

110+
#### Running tests
111+
112+
After starting the general development Docker, seed the testing database:
113+
```shell script
114+
# this is to be done only once
115+
docker-compose run app php artisan db:seed --class=DummyContentSeeder --database=mysql_testing
116+
```
117+
118+
Once the database has been seeded, you can run the tests by:
119+
```shell script
120+
docker-compose run app php vendor/bin/phpunit
121+
```
111122
## 🌎 Translations
112123

113124
Translations for text within BookStack is managed through the [BookStack project on Crowdin](https://crowdin.com/project/bookstack). Some strings have colon-prefixed variables in such as `:userName`. Leave these values as they are as they will be replaced at run-time. Crowdin is the preferred way to provide translations, otherwise the raw translations files can be found within the `resources/lang` path.

0 commit comments

Comments
 (0)