mirror of
https://github.com/archtechx/tenancy.git
synced 2025-12-12 12:24:04 +00:00
Dockerize phpunit (#66)
This commit is contained in:
parent
13cdc03103
commit
dc30354699
9 changed files with 93 additions and 20 deletions
|
|
@ -1,3 +0,0 @@
|
||||||
DB_DATABASE=travis_tenancy
|
|
||||||
DB_USERNAME=foo
|
|
||||||
DB_PASSWORD=bar
|
|
||||||
16
.travis.yml
16
.travis.yml
|
|
@ -7,22 +7,22 @@ php:
|
||||||
- '7.2'
|
- '7.2'
|
||||||
|
|
||||||
services:
|
services:
|
||||||
- mysql
|
- docker
|
||||||
- redis-server
|
|
||||||
|
|
||||||
before_install:
|
before_install:
|
||||||
- echo "extension = redis.so" >> ~/.phpenv/versions/$(phpenv version-name)/etc/php.ini
|
- docker-compose up -d
|
||||||
|
|
||||||
install:
|
install:
|
||||||
- travis_retry composer require "laravel/framework:$LARAVEL_VERSION" "orchestra/testbench:$TESTBENCH_VERSION"
|
- travis_retry docker-compose exec test composer require --no-interaction "laravel/framework:$LARAVEL_VERSION" "orchestra/testbench:$TESTBENCH_VERSION"
|
||||||
- travis_retry composer install --no-interaction
|
|
||||||
|
|
||||||
before_script:
|
before_script:
|
||||||
- mysql -e 'CREATE DATABASE travis_tenancy;'
|
- export DB_USERNAME=root DB_PASSWORD="" DB_DATABASE=tenancy CODECOV_TOKEN="24382d15-84e7-4a55-bea4-c4df96a24a9b"
|
||||||
- export DB_USERNAME=root DB_PASSWORD="" DB_DATABASE=travis_tenancy CODECOV_TOKEN="24382d15-84e7-4a55-bea4-c4df96a24a9b"
|
|
||||||
- cat vendor/laravel/framework/src/Illuminate/Foundation/Application.php| grep 'const VERSION'
|
- 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:
|
after_success:
|
||||||
- bash <(curl -s https://codecov.io/bash)
|
- bash <(curl -s https://codecov.io/bash)
|
||||||
|
|
|
||||||
25
Dockerfile
Normal file
25
Dockerfile
Normal 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
|
||||||
|
|
@ -10,14 +10,14 @@
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
"require": {
|
"require": {
|
||||||
"illuminate/support": "5.7.*||5.8.*",
|
"illuminate/support": "5.8.*||5.7.*",
|
||||||
"webpatser/laravel-uuid": "^3.0",
|
"webpatser/laravel-uuid": "^3.0",
|
||||||
"predis/predis": "^1.1"
|
"predis/predis": "^1.1"
|
||||||
},
|
},
|
||||||
"require-dev": {
|
"require-dev": {
|
||||||
"vlucas/phpdotenv": "^2.2||^3.3",
|
"vlucas/phpdotenv": "^2.2||^3.3",
|
||||||
"psy/psysh": "@stable",
|
"psy/psysh": "@stable",
|
||||||
"laravel/framework": "5.7.*||5.8.*",
|
"laravel/framework": "5.8.*||5.7.*",
|
||||||
"orchestra/testbench": "~3.7||~3.8",
|
"orchestra/testbench": "~3.7||~3.8",
|
||||||
"league/flysystem-aws-s3-v3": "~1.0"
|
"league/flysystem-aws-s3-v3": "~1.0"
|
||||||
},
|
},
|
||||||
|
|
|
||||||
45
docker-compose.yml
Normal file
45
docker-compose.yml
Normal 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
|
||||||
|
|
@ -5,7 +5,6 @@ namespace Stancl\Tenancy\Traits;
|
||||||
use Stancl\Tenancy\CacheManager;
|
use Stancl\Tenancy\CacheManager;
|
||||||
use Illuminate\Support\Facades\Redis;
|
use Illuminate\Support\Facades\Redis;
|
||||||
use Illuminate\Support\Facades\Storage;
|
use Illuminate\Support\Facades\Storage;
|
||||||
use Symfony\Component\Debug\Exception\FatalThrowableError;
|
|
||||||
use Stancl\Tenancy\Exceptions\PhpRedisNotInstalledException;
|
use Stancl\Tenancy\Exceptions\PhpRedisNotInstalledException;
|
||||||
|
|
||||||
trait BootstrapsTenancy
|
trait BootstrapsTenancy
|
||||||
|
|
|
||||||
5
test
Executable file
5
test
Executable file
|
|
@ -0,0 +1,5 @@
|
||||||
|
#!/bin/bash
|
||||||
|
|
||||||
|
# for development
|
||||||
|
docker-compose up -d
|
||||||
|
docker-compose exec test vendor/bin/phpunit "$@"
|
||||||
|
|
@ -40,7 +40,7 @@ class TenantDatabaseManagerTest extends TestCase
|
||||||
/** @test */
|
/** @test */
|
||||||
public function mysql_database_can_be_created_and_deleted()
|
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.');
|
$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 */
|
/** @test */
|
||||||
public function mysql_database_can_be_created_and_deleted_using_queued_commands()
|
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.');
|
$this->markTestSkipped('As to not bloat your MySQL instance with test databases, this test is not run by default.');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -53,6 +53,8 @@ abstract class TestCase extends \Orchestra\Testbench\TestCase
|
||||||
|
|
||||||
$app['config']->set([
|
$app['config']->set([
|
||||||
'database.redis.client' => 'phpredis',
|
'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' => [
|
'database.redis.tenancy' => [
|
||||||
'host' => env('TENANCY_TEST_REDIS_HOST', '127.0.0.1'),
|
'host' => env('TENANCY_TEST_REDIS_HOST', '127.0.0.1'),
|
||||||
'password' => env('TENANCY_TEST_REDIS_PASSWORD', null),
|
'password' => env('TENANCY_TEST_REDIS_PASSWORD', null),
|
||||||
|
|
@ -67,6 +69,8 @@ abstract class TestCase extends \Orchestra\Testbench\TestCase
|
||||||
'suffix' => '.sqlite',
|
'suffix' => '.sqlite',
|
||||||
],
|
],
|
||||||
'database.connections.sqlite.database' => ':memory:',
|
'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' => [
|
'tenancy.filesystem.disks' => [
|
||||||
'local',
|
'local',
|
||||||
'public',
|
'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);
|
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
|
return env('CONTINUOUS_INTEGRATION') || env('DOCKER');
|
||||||
// set one of these environment vars on their computer.
|
|
||||||
return env('CI') && env('TRAVIS') && env('CONTINUOUS_INTEGRATION');
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function assertArrayIsSubset($subset, $array, string $message = ''): void
|
public function assertArrayIsSubset($subset, $array, string $message = ''): void
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue