1
0
Fork 0
mirror of https://github.com/archtechx/tenancy.git synced 2025-12-12 20:14:03 +00:00

Dockerize phpunit (#66)

This commit is contained in:
Samuel Štancl 2019-07-12 21:44:26 +02:00 committed by GitHub
parent 13cdc03103
commit dc30354699
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
9 changed files with 93 additions and 20 deletions

View file

@ -1,3 +0,0 @@
DB_DATABASE=travis_tenancy
DB_USERNAME=foo
DB_PASSWORD=bar

View file

@ -7,22 +7,22 @@ php:
- '7.2'
services:
- mysql
- redis-server
- docker
before_install:
- echo "extension = redis.so" >> ~/.phpenv/versions/$(phpenv version-name)/etc/php.ini
- docker-compose up -d
install:
- travis_retry composer require "laravel/framework:$LARAVEL_VERSION" "orchestra/testbench:$TESTBENCH_VERSION"
- travis_retry composer install --no-interaction
- travis_retry docker-compose exec test composer require --no-interaction "laravel/framework:$LARAVEL_VERSION" "orchestra/testbench:$TESTBENCH_VERSION"
before_script:
- mysql -e 'CREATE DATABASE travis_tenancy;'
- export DB_USERNAME=root DB_PASSWORD="" DB_DATABASE=travis_tenancy CODECOV_TOKEN="24382d15-84e7-4a55-bea4-c4df96a24a9b"
- export DB_USERNAME=root DB_PASSWORD="" DB_DATABASE=tenancy CODECOV_TOKEN="24382d15-84e7-4a55-bea4-c4df96a24a9b"
- cat vendor/laravel/framework/src/Illuminate/Foundation/Application.php| grep 'const VERSION'
script: vendor/bin/phpunit -v --coverage-clover=coverage.xml
script: docker-compose exec test vendor/bin/phpunit -v --coverage-clover=coverage.xml
after_script:
- docker-compose down
after_success:
- bash <(curl -s https://codecov.io/bash)

25
Dockerfile Normal file
View file

@ -0,0 +1,25 @@
FROM ubuntu:18.04
LABEL maintainer="Samuel Štancl"
ENV DEBIAN_FRONTEND=noninteractive
RUN apt-get update \
&& apt-get install -y curl zip unzip git sqlite3 \
php7.2-fpm php7.2-cli \
php7.2-pgsql php7.2-sqlite3 php7.2-gd \
php7.2-curl php7.2-memcached \
php7.2-imap php7.2-mysql php7.2-mbstring \
php7.2-xml php7.2-zip php7.2-bcmath php7.2-soap \
php7.2-intl php7.2-readline php7.2-xdebug \
php-msgpack php-igbinary \
&& php -r "readfile('http://getcomposer.org/installer');" | php -- --install-dir=/usr/bin/ --filename=composer \
&& mkdir /run/php
RUN apt-get install php7.2-redis
RUN apt-get -y autoremove \
&& apt-get clean \
&& rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/*
WORKDIR /var/www/html

View file

@ -10,14 +10,14 @@
}
],
"require": {
"illuminate/support": "5.7.*||5.8.*",
"illuminate/support": "5.8.*||5.7.*",
"webpatser/laravel-uuid": "^3.0",
"predis/predis": "^1.1"
},
"require-dev": {
"vlucas/phpdotenv": "^2.2||^3.3",
"psy/psysh": "@stable",
"laravel/framework": "5.7.*||5.8.*",
"laravel/framework": "5.8.*||5.7.*",
"orchestra/testbench": "~3.7||~3.8",
"league/flysystem-aws-s3-v3": "~1.0"
},

45
docker-compose.yml Normal file
View file

@ -0,0 +1,45 @@
version: '3'
services:
test:
build:
context: .
networks:
- testnet
depends_on:
- mysql
- postgres
- redis
volumes:
- .:/var/www/html
environment:
DOCKER: 1
DB_PASSWORD: password
DB_USERNAME: root
DB_DATABASE: main
TENANCY_TEST_REDIS_HOST: redis
TENANCY_TEST_MYSQL_HOST: mysql
TENANCY_TEST_PGSQL_HOST: postgres
stdin_open: true
tty: true
mysql:
image: mysql:5.7
environment:
MYSQL_ROOT_PASSWORD: password
MYSQL_DATABASE: main
MYSQL_USER: user
MYSQL_PASSWORD: password
networks:
- testnet
postgres:
image: postgres:11
environment:
POSTGRES_PASSWORD: password
POSTGRES_USER: user
POSTGRES_DB: main
redis:
image: redis:alpine
networks:
- testnet
networks:
testnet:
driver: bridge

View file

@ -5,7 +5,6 @@ namespace Stancl\Tenancy\Traits;
use Stancl\Tenancy\CacheManager;
use Illuminate\Support\Facades\Redis;
use Illuminate\Support\Facades\Storage;
use Symfony\Component\Debug\Exception\FatalThrowableError;
use Stancl\Tenancy\Exceptions\PhpRedisNotInstalledException;
trait BootstrapsTenancy

5
test Executable file
View file

@ -0,0 +1,5 @@
#!/bin/bash
# for development
docker-compose up -d
docker-compose exec test vendor/bin/phpunit "$@"

View file

@ -40,7 +40,7 @@ class TenantDatabaseManagerTest extends TestCase
/** @test */
public function mysql_database_can_be_created_and_deleted()
{
if (! $this->isTravis()) {
if (! $this->isContainerized()) {
$this->markTestSkipped('As to not bloat your MySQL instance with test databases, this test is not run by default.');
}
@ -57,7 +57,7 @@ class TenantDatabaseManagerTest extends TestCase
/** @test */
public function mysql_database_can_be_created_and_deleted_using_queued_commands()
{
if (! $this->isTravis()) {
if (! $this->isContainerized()) {
$this->markTestSkipped('As to not bloat your MySQL instance with test databases, this test is not run by default.');
}

View file

@ -53,6 +53,8 @@ abstract class TestCase extends \Orchestra\Testbench\TestCase
$app['config']->set([
'database.redis.client' => 'phpredis',
'database.redis.cache.host' => env('TENANCY_TEST_REDIS_HOST', '127.0.0.1'),
'database.redis.default.host' => env('TENANCY_TEST_REDIS_HOST', '127.0.0.1'),
'database.redis.tenancy' => [
'host' => env('TENANCY_TEST_REDIS_HOST', '127.0.0.1'),
'password' => env('TENANCY_TEST_REDIS_PASSWORD', null),
@ -67,6 +69,8 @@ abstract class TestCase extends \Orchestra\Testbench\TestCase
'suffix' => '.sqlite',
],
'database.connections.sqlite.database' => ':memory:',
'database.connections.mysql.host' => env('TENANCY_TEST_MYSQL_HOST', '127.0.0.1'),
'database.connections.pgsql.host' => env('TENANCY_TEST_PGSQL_HOST', '127.0.0.1'),
'tenancy.filesystem.disks' => [
'local',
'public',
@ -114,11 +118,9 @@ abstract class TestCase extends \Orchestra\Testbench\TestCase
return substr(str_shuffle(str_repeat($x = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ', ceil($length / strlen($x)))), 1, $length);
}
public function isTravis()
public function isContainerized()
{
// Multiple, just to make sure. Someone might accidentally
// set one of these environment vars on their computer.
return env('CI') && env('TRAVIS') && env('CONTINUOUS_INTEGRATION');
return env('CONTINUOUS_INTEGRATION') || env('DOCKER');
}
public function assertArrayIsSubset($subset, $array, string $message = ''): void