mirror of
https://github.com/elyby/accounts.git
synced 2025-05-31 14:11:46 +05:30
Тестовое окружение отделено от основного, упрощены билды для контейнеров MariaDB и RabbitMQ, написаны скрипты для быстрого прогона тестов
This commit is contained in:
@@ -1,58 +0,0 @@
|
||||
This directory contains various tests for the advanced applications.
|
||||
|
||||
Tests in `codeception` directory are developed with [Codeception PHP Testing Framework](http://codeception.com/).
|
||||
|
||||
After creating and setting up the advanced application, follow these steps to prepare for the tests:
|
||||
|
||||
1. Install Codeception if it's not yet installed:
|
||||
|
||||
```
|
||||
composer global require "codeception/codeception=2.0.*" "codeception/specify=*" "codeception/verify=*"
|
||||
```
|
||||
|
||||
If you've never used Composer for global packages run `composer global status`. It should output:
|
||||
|
||||
```
|
||||
Changed current directory to <directory>
|
||||
```
|
||||
|
||||
Then add `<directory>/vendor/bin` to you `PATH` environment variable. Now you're able to use `codecept` from command
|
||||
line globally.
|
||||
|
||||
2. Install faker extension by running the following from template root directory where `composer.json` is:
|
||||
|
||||
```
|
||||
composer require --dev yiisoft/yii2-faker:*
|
||||
```
|
||||
|
||||
3. Create `yii2_advanced_tests` database then update it by applying migrations:
|
||||
|
||||
```
|
||||
codeception/bin/yii migrate
|
||||
```
|
||||
|
||||
4. In order to be able to run acceptance tests you need to start a webserver. The simplest way is to use PHP built in
|
||||
webserver. In the root directory where `common`, `frontend` etc. are execute the following:
|
||||
|
||||
```
|
||||
php -S localhost:8080
|
||||
```
|
||||
|
||||
5. Now you can run the tests with the following commands, assuming you are in the `tests/codeception` directory:
|
||||
|
||||
```
|
||||
# frontend tests
|
||||
cd frontend
|
||||
codecept build
|
||||
codecept run
|
||||
|
||||
# backend tests
|
||||
|
||||
cd backend
|
||||
codecept build
|
||||
codecept run
|
||||
|
||||
# etc.
|
||||
```
|
||||
|
||||
If you already have run `codecept build` for each application, you can skip that step and run all tests by a single `codecept run`.
|
@@ -21,6 +21,4 @@ $_SERVER['SERVER_NAME'] = parse_url(\Codeception\Configuration::config()['confi
|
||||
$_SERVER['SERVER_PORT'] = parse_url(\Codeception\Configuration::config()['config']['test_entry_url'], PHP_URL_PORT) ?: '80';
|
||||
|
||||
Yii::setAlias('@tests', dirname(dirname(__DIR__)));
|
||||
|
||||
// disable deep cloning of properties inside specify block
|
||||
\Codeception\Specify\Config::setDeepClone(false);
|
||||
|
@@ -12,11 +12,11 @@ modules:
|
||||
Yii2:
|
||||
configFile: '../config/api/functional.php'
|
||||
Redis:
|
||||
host: redis
|
||||
host: testredis
|
||||
port: 6379
|
||||
database: 1
|
||||
database: 0
|
||||
AMQP:
|
||||
host: rabbitmq
|
||||
host: testrabbit
|
||||
port: 5672
|
||||
username: 'ely-accounts-tester'
|
||||
password: 'tester-password'
|
||||
|
@@ -1,7 +1,4 @@
|
||||
<?php
|
||||
/**
|
||||
* Application configuration shared by all applications and test types
|
||||
*/
|
||||
return [
|
||||
'language' => 'en-US',
|
||||
'controllerMap' => [
|
||||
@@ -14,7 +11,9 @@ return [
|
||||
],
|
||||
'components' => [
|
||||
'db' => [
|
||||
'dsn' => 'mysql:host=db;dbname=ely_accounts_test',
|
||||
'dsn' => 'mysql:host=testdb;dbname=ely_accounts_test',
|
||||
'username' => 'ely_accounts_tester',
|
||||
'password' => 'ely_accounts_tester_password',
|
||||
],
|
||||
'mailer' => [
|
||||
'useFileTransport' => true,
|
||||
@@ -23,9 +22,10 @@ return [
|
||||
'showScriptName' => true,
|
||||
],
|
||||
'redis' => [
|
||||
'database' => 1,
|
||||
'hostname' => 'testredis',
|
||||
],
|
||||
'amqp' => [
|
||||
'host' => 'testrabbit',
|
||||
'user' => 'ely-accounts-tester',
|
||||
'password' => 'tester-password',
|
||||
'vhost' => '/account.ely.by/tests',
|
||||
|
@@ -14,3 +14,4 @@ $_SERVER['SERVER_NAME'] = 'localhost';
|
||||
$_SERVER['SERVER_PORT'] = '80';
|
||||
|
||||
Yii::setAlias('@tests', dirname(dirname(__DIR__)));
|
||||
\Codeception\Specify\Config::setDeepClone(false);
|
||||
|
30
tests/docker-compose.yml
Normal file
30
tests/docker-compose.yml
Normal file
@@ -0,0 +1,30 @@
|
||||
version: '2'
|
||||
services:
|
||||
testphp:
|
||||
build: ./..
|
||||
links:
|
||||
- testdb
|
||||
- testredis
|
||||
- testrabbit
|
||||
volumes:
|
||||
- ./../:/var/www/html/
|
||||
env_file: ./../.env
|
||||
|
||||
testdb:
|
||||
build: ./../docker/mariadb
|
||||
environment:
|
||||
MYSQL_ROOT_PASSWORD: ""
|
||||
MYSQL_ALLOW_EMPTY_PASSWORD: "yes"
|
||||
MYSQL_DATABASE: "ely_accounts_test"
|
||||
MYSQL_USER: "ely_accounts_tester"
|
||||
MYSQL_PASSWORD: "ely_accounts_tester_password"
|
||||
|
||||
testredis:
|
||||
image: redis:3.0
|
||||
|
||||
testrabbit:
|
||||
build: ./../docker/rabbitmq
|
||||
environment:
|
||||
RABBITMQ_DEFAULT_USER: "ely-accounts-tester"
|
||||
RABBITMQ_DEFAULT_PASS: "tester-password"
|
||||
RABBITMQ_DEFAULT_VHOST: "/account.ely.by/tests"
|
8
tests/php.sh
Executable file
8
tests/php.sh
Executable file
@@ -0,0 +1,8 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
cd "$(dirname "$0")"
|
||||
|
||||
./../vendor/bin/codecept build
|
||||
|
||||
./../docker/wait-for-it.sh testdb:3306 testrabbit:5672 -- \
|
||||
php codeception/bin/yii migrate/up --interactive=0 && ./../vendor/bin/codecept run
|
6
tests/run-tests.sh
Executable file
6
tests/run-tests.sh
Executable file
@@ -0,0 +1,6 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
cd "$(dirname "$0")"
|
||||
|
||||
docker-compose run --rm testphp ./tests/php.sh
|
||||
docker-compose stop # docker не останавливает зависимые контейнеры после завершения работы главного процесса
|
Reference in New Issue
Block a user