Skip to content

Commit 5a87639

Browse files
committed
Make testing easier with docker
1 parent 321885c commit 5a87639

File tree

5 files changed

+49
-4
lines changed

5 files changed

+49
-4
lines changed

README.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,15 @@ Embedded relations now return an `Illuminate\Database\Eloquent\Collection` rathe
103103
$books = $user->books()->sortBy('title');
104104
```
105105

106+
Testing
107+
-------
108+
109+
To run the test for this package, run:
110+
111+
```
112+
docker-compose up
113+
```
114+
106115
Configuration
107116
-------------
108117

docker-compose.yml

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
version: '3'
2+
3+
services:
4+
5+
php:
6+
build:
7+
context: .
8+
dockerfile: docker/Dockerfile
9+
volumes:
10+
- .:/code
11+
working_dir: /code
12+
command: php ./vendor/bin/phpunit
13+
depends_on:
14+
- mysql
15+
- mongodb
16+
17+
mysql:
18+
image: mysql
19+
environment:
20+
MYSQL_ROOT_PASSWORD:
21+
MYSQL_DATABASE: unittest
22+
MYSQL_ALLOW_EMPTY_PASSWORD: 'yes'
23+
logging:
24+
driver: none
25+
26+
mongodb:
27+
image: mongo
28+
logging:
29+
driver: none

docker/Dockerfile

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
FROM php:7.1-cli
2+
3+
RUN apt-get update && \
4+
apt-get install -y autoconf pkg-config libssl-dev && \
5+
pecl install mongodb && docker-php-ext-enable mongodb && \
6+
docker-php-ext-install -j$(nproc) pdo pdo_mysql

tests/ConnectionTest.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,12 +98,13 @@ public function testDriverName()
9898

9999
public function testAuth()
100100
{
101+
$host = Config::get('database.connections.mongodb.host');
101102
Config::set('database.connections.mongodb.username', 'foo');
102103
Config::set('database.connections.mongodb.password', 'bar');
103104
Config::set('database.connections.mongodb.options.database', 'custom');
104105

105106
$connection = DB::connection('mongodb');
106-
$this->assertEquals('mongodb://127.0.0.1/custom', (string) $connection->getMongoClient());
107+
$this->assertEquals('mongodb://' . $host . '/custom', (string) $connection->getMongoClient());
107108
}
108109

109110
public function testCustomHostAndPort()

tests/config/database.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,15 +7,15 @@
77
'mongodb' => [
88
'name' => 'mongodb',
99
'driver' => 'mongodb',
10-
'host' => '127.0.0.1',
10+
'host' => 'mongodb',
1111
'database' => 'unittest',
1212
],
1313

1414
'mysql' => [
1515
'driver' => 'mysql',
16-
'host' => '127.0.0.1',
16+
'host' => 'mysql',
1717
'database' => 'unittest',
18-
'username' => 'travis',
18+
'username' => 'root',
1919
'password' => '',
2020
'charset' => 'utf8',
2121
'collation' => 'utf8_unicode_ci',

0 commit comments

Comments
 (0)