1
0
Fork 0
mirror of https://github.com/archtechx/tenancy.git synced 2026-02-04 19:24:02 +00:00
This commit is contained in:
Samuel Štancl 2019-07-05 15:02:20 +02:00
parent 13cdc03103
commit 73c818f975
7 changed files with 88 additions and 17 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 app 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 app 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

43
docker-compose.yml Normal file
View file

@ -0,0 +1,43 @@
version: '3'
services:
test:
build:
context: .
networks:
- testnet
depends_on:
- mysql
- postgres
- redis
volumes:
- .:/var/www/html
environment:
DOCKER: 1
DB_PASSWORD: "password"
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: ""
POSTGRES_USER: user
POSTGRES_DB: main
redis:
image: redis:alpine
networks:
- testnet
networks:
testnet:
driver: bridge

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,7 @@ abstract class TestCase extends \Orchestra\Testbench\TestCase
$app['config']->set([
'database.redis.client' => 'phpredis',
'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 +68,8 @@ abstract class TestCase extends \Orchestra\Testbench\TestCase
'suffix' => '.sqlite',
],
'database.connections.sqlite.database' => ':memory:',
'database.connections.mysql.host' => env('TENANCY_TESTING_MYSQL_HOST', '127.0.0.1'),
'database.connections.pgsql.host' => env('TENANCY_TESTING_PGSQL_HOST', '127.0.0.1'),
'tenancy.filesystem.disks' => [
'local',
'public',
@ -114,11 +117,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