From 6e4e2b26eef605e0737db7305f50ffdd2e15b3de Mon Sep 17 00:00:00 2001 From: ErickSkrauch Date: Fri, 2 Dec 2016 11:38:14 +0300 Subject: [PATCH 01/13] =?UTF-8?q?Nginx=20=D1=82=D0=B5=D0=BF=D0=B5=D1=80?= =?UTF-8?q?=D1=8C=20=D1=81=D0=BE=D0=B1=D0=B8=D1=80=D0=B0=D0=B5=D1=82=D1=81?= =?UTF-8?q?=D1=8F=20=D0=BE=D1=82=D0=B4=D0=B5=D0=BB=D1=8C=D0=BD=D0=BE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- docker-compose.dev.yml | 2 +- docker-compose.prod.yml | 2 +- docker/nginx/Dockerfile | 11 ---- docker/nginx/account.ely.by.conf.template | 78 ----------------------- docker/nginx/nginx.conf | 25 -------- docker/nginx/run.sh | 5 -- 6 files changed, 2 insertions(+), 121 deletions(-) delete mode 100644 docker/nginx/Dockerfile delete mode 100644 docker/nginx/account.ely.by.conf.template delete mode 100644 docker/nginx/nginx.conf delete mode 100644 docker/nginx/run.sh diff --git a/docker-compose.dev.yml b/docker-compose.dev.yml index 9dce11c..f93f1f7 100644 --- a/docker-compose.dev.yml +++ b/docker-compose.dev.yml @@ -13,7 +13,7 @@ services: env_file: .env web: - build: ./docker/nginx + image: registry.ely.by/elyby/accounts-nginx:latest volumes_from: - app links: diff --git a/docker-compose.prod.yml b/docker-compose.prod.yml index 1d59c03..d311e0b 100644 --- a/docker-compose.prod.yml +++ b/docker-compose.prod.yml @@ -9,7 +9,7 @@ services: env_file: .env web: - build: ./docker/nginx + image: registry.ely.by/elyby/accounts-nginx:1.0.2 volumes_from: - app links: diff --git a/docker/nginx/Dockerfile b/docker/nginx/Dockerfile deleted file mode 100644 index 3c47e59..0000000 --- a/docker/nginx/Dockerfile +++ /dev/null @@ -1,11 +0,0 @@ -FROM nginx:1.11-alpine - -COPY nginx.conf /etc/nginx/nginx.conf -COPY account.ely.by.conf.template /etc/nginx/conf.d/account.ely.by.conf.template -COPY run.sh /run.sh - -RUN rm /etc/nginx/conf.d/default.conf \ - && chmod a+x /run.sh - -ENTRYPOINT ["/run.sh"] -CMD ["nginx", "-g", "daemon off;"] diff --git a/docker/nginx/account.ely.by.conf.template b/docker/nginx/account.ely.by.conf.template deleted file mode 100644 index d5b2fbc..0000000 --- a/docker/nginx/account.ely.by.conf.template +++ /dev/null @@ -1,78 +0,0 @@ -server { - listen 80; - - root $root_path; - charset utf-8; - index index.html; - etag on; - - # Это можно раскоментить для целей отладки - # rewrite_log on; - # error_log /var/log/nginx/error.log debug; - - set $root_path '/var/www/html'; - set $frontend_path '${root_path}/frontend/dist'; - - set $request_url $request_uri; - set $host_with_uri '${host}${request_uri}'; - - if ($host_with_uri ~ '^${AUTHSERVER_HOST}/auth') { - set $request_url '/api/authserver${request_uri}'; - rewrite ^/auth /api/authserver$uri last; - } - - if ($host_with_uri ~ '^${AUTHSERVER_HOST}/session') { - set $request_url '/api/minecraft${request_uri}'; - rewrite ^/session /api/minecraft$uri last; - } - - if ($host_with_uri ~ '^${AUTHSERVER_HOST}/api/(user|profiles)') { - set $request_url '/api/mojang${request_uri}'; - rewrite ^/api/(user|profiles) /api/mojang$uri last; - } - - location / { - alias $frontend_path; - try_files $uri /index.html =404; - } - - location /api { - try_files $uri $uri /api/web/index.php$is_args$args; - } - - location ~* \.php$ { - fastcgi_pass php:9000; - include fastcgi_params; - - fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; - fastcgi_param SERVER_NAME $host; - fastcgi_param REQUEST_URI $request_url; - fastcgi_param REMOTE_ADDR $http_x_real_ip; - - try_files $uri =404; - } - - # html файлы идут отдельно, для них будет применяться E-Tag кэширование - location ~* \.html$ { - root $frontend_path; - access_log off; - } - - # Раздача статики для frontend с указанием max-кэша. Сброс будет по #hash после ребилда webpackом - location ~* ^.+\.(jpg|jpeg|gif|png|svg|js|json|css|zip|rar|eot|ttf|woff|woff2|ico)$ { - root $frontend_path; - expires max; - etag off; - access_log off; - } - - # Запросы к статике для email, их нужно запустить внутрь vendor - location ^~ /images/emails/assets { - rewrite ^/images/emails/assets/(.+)$ /vendor/ely/emails-renderer/dist/assets/$1 last; - } - - location ^~ /vendor/ely/emails-renderer/dist/assets { - alias '${root_path}/vendor/ely/email-renderer/dist/assets'; - try_files $uri =404; - } -} diff --git a/docker/nginx/nginx.conf b/docker/nginx/nginx.conf deleted file mode 100644 index 886547e..0000000 --- a/docker/nginx/nginx.conf +++ /dev/null @@ -1,25 +0,0 @@ -user nginx; -worker_processes 1; - -error_log /var/log/nginx/error.log warn; -pid /var/run/nginx.pid; - -events { - worker_connections 1024; -} - -http { - include /etc/nginx/mime.types; - default_type application/octet-stream; - - log_format main '$remote_addr - $remote_user [$time_local] "$request" ' - '$status $body_bytes_sent "$http_referer" ' - '"$http_user_agent" "$http_x_forwarded_for"'; - - access_log /var/log/nginx/access.log main; - - sendfile on; - keepalive_timeout 10; - - include /etc/nginx/conf.d/*.conf; -} diff --git a/docker/nginx/run.sh b/docker/nginx/run.sh deleted file mode 100644 index 7365afe..0000000 --- a/docker/nginx/run.sh +++ /dev/null @@ -1,5 +0,0 @@ -#!/usr/bin/env sh - -envsubst '$AUTHSERVER_HOST' < /etc/nginx/conf.d/account.ely.by.conf.template > /etc/nginx/conf.d/default.conf - -exec "$@" From 0a0cca0834636b5e1d7c034a34948c37abe1505e Mon Sep 17 00:00:00 2001 From: ErickSkrauch Date: Fri, 2 Dec 2016 11:38:35 +0300 Subject: [PATCH 02/13] =?UTF-8?q?=D0=94=D0=BE=D0=B1=D0=B0=D0=B2=D0=BB?= =?UTF-8?q?=D0=B5=D0=BD=20=D0=BA=D0=BE=D0=BC=D0=BF=D0=BE=D0=BD=D0=B5=D0=BD?= =?UTF-8?q?=D1=82=20=D0=B4=D0=BB=D1=8F=20=D0=BA=D1=8D=D1=88=D0=B8=D0=BE?= =?UTF-8?q?=D0=B2=D0=B0=D0=BD=D0=B8=D1=8F=20=D0=BE=D1=82=D0=B2=D0=B5=D1=82?= =?UTF-8?q?=D0=B0=20=D0=BD=D0=B0=20=D1=83=D1=80=D0=BE=D0=B2=D0=BD=D0=B5=20?= =?UTF-8?q?nginx?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- api/filters/NginxCache.php | 35 ++++++++++++ .../api/unit/filters/NginxCacheTest.php | 57 +++++++++++++++++++ 2 files changed, 92 insertions(+) create mode 100644 api/filters/NginxCache.php create mode 100644 tests/codeception/api/unit/filters/NginxCacheTest.php diff --git a/api/filters/NginxCache.php b/api/filters/NginxCache.php new file mode 100644 index 0000000..21669e1 --- /dev/null +++ b/api/filters/NginxCache.php @@ -0,0 +1,35 @@ + сколько кэшировать. + * + * Период можно задавать 2-умя путями: + * - если значение начинается с префикса @, оно задаёт абсолютное время в unix timestamp, + * до которого ответ может быть закэширован. + * - в ином случае значение интерпретируется как количество секунд, на которое необходимо + * закэшировать ответ + */ + public $rules; + + public function afterAction($action, $result) { + $rule = $this->rules[$action->id] ?? null; + if ($rule !== null) { + if (is_callable($rule)) { + $cacheTime = $rule($action); + } else { + $cacheTime = $rule; + } + + Yii::$app->response->headers->set('X-Accel-Expires', $cacheTime); + } + + return parent::afterAction($action, $result); + } + +} diff --git a/tests/codeception/api/unit/filters/NginxCacheTest.php b/tests/codeception/api/unit/filters/NginxCacheTest.php new file mode 100644 index 0000000..01f982d --- /dev/null +++ b/tests/codeception/api/unit/filters/NginxCacheTest.php @@ -0,0 +1,57 @@ +testAfterActionInternal(3600, 3600); + $this->testAfterActionInternal('@' . (time() + 30), '@' . (time() + 30)); + $this->testAfterActionInternal(function() { + return 3000; + }, 3000); + } + + private function testAfterActionInternal($ruleConfig, $expected) { + /** @var HeaderCollection|\PHPUnit_Framework_MockObject_MockObject $headers */ + $headers = $this->getMockBuilder(HeaderCollection::class) + ->setMethods(['set']) + ->getMock(); + + $headers->expects($this->once()) + ->method('set') + ->with('X-Accel-Expires', $expected); + + /** @var Request|\PHPUnit_Framework_MockObject_MockObject $request */ + $request = $this->getMockBuilder(Request::class) + ->setMethods(['getHeaders']) + ->getMock(); + + $request->expects($this->any()) + ->method('getHeaders') + ->willReturn($headers); + + Yii::$app->set('response', $request); + + /** @var Controller|\PHPUnit_Framework_MockObject_MockObject $controller */ + $controller = $this->getMockBuilder(Controller::class) + ->setConstructorArgs(['mock', Yii::$app]) + ->getMock(); + + $component = new NginxCache([ + 'rules' => [ + 'index' => $ruleConfig, + ], + ]); + + $component->afterAction(new Action('index', $controller), ''); + } + +} From ffd4a9000f7e46f4c51f268a2394037ed66710a2 Mon Sep 17 00:00:00 2001 From: ErickSkrauch Date: Fri, 2 Dec 2016 11:38:53 +0300 Subject: [PATCH 03/13] =?UTF-8?q?=D0=A0=D0=B5=D0=B0=D0=BB=D0=B8=D0=B7?= =?UTF-8?q?=D0=BE=D0=B2=D0=B0=D0=BD=D0=BE=20=D0=BA=D1=8D=D1=88=D0=B8=D1=80?= =?UTF-8?q?=D0=BE=D0=B2=D0=B0=D0=BD=D0=B8=D0=B5=20=D0=BE=D1=82=D0=B2=D0=B5?= =?UTF-8?q?=D1=82=D0=B0=20/api/options?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- api/controllers/OptionsController.php | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/api/controllers/OptionsController.php b/api/controllers/OptionsController.php index 4c230f9..c96762a 100644 --- a/api/controllers/OptionsController.php +++ b/api/controllers/OptionsController.php @@ -1,6 +1,7 @@ [ 'except' => ['index'], ], + 'nginxCache' => [ + 'class' => NginxCache::class, + 'rules' => [ + 'index' => 3600, // 1h + ], + ], ]); } From 6fc558c3c8dbda41605dc02b176400ab3a407419 Mon Sep 17 00:00:00 2001 From: ErickSkrauch Date: Sat, 3 Dec 2016 14:28:03 +0300 Subject: [PATCH 04/13] =?UTF-8?q?=D0=A3=D0=B4=D0=B0=D0=BB=D0=B5=D0=BD?= =?UTF-8?q?=D0=B0=20cron=20=D0=B7=D0=B0=D0=B4=D0=B0=D1=87=D0=B0=20=D0=B4?= =?UTF-8?q?=D0=BB=D1=8F=20=D0=BE=D1=87=D0=B8=D1=81=D1=82=D0=BA=D0=B8=20acc?= =?UTF-8?q?ess=5Ftokens=20[skip=20ci]?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- docker/cron/.gitkeep | 0 docker/cron/cleanup | 2 -- 2 files changed, 2 deletions(-) create mode 100644 docker/cron/.gitkeep delete mode 100644 docker/cron/cleanup diff --git a/docker/cron/.gitkeep b/docker/cron/.gitkeep new file mode 100644 index 0000000..e69de29 diff --git a/docker/cron/cleanup b/docker/cron/cleanup deleted file mode 100644 index 3401974..0000000 --- a/docker/cron/cleanup +++ /dev/null @@ -1,2 +0,0 @@ -# https://crontab.guru/every-hour -0 * * * * root /usr/local/bin/php /var/www/html/yii cleanup/access-tokens >/dev/null 2>&1 From 9274155cfc0f6b467967c7901e6011a132547429 Mon Sep 17 00:00:00 2001 From: ErickSkrauch Date: Sun, 4 Dec 2016 15:34:32 +0300 Subject: [PATCH 05/13] =?UTF-8?q?=D0=9E=D1=82=D0=B4=D0=B5=D0=BB=D0=B5?= =?UTF-8?q?=D0=BD=D1=8B=20=D0=BF=D0=B0=D1=80=D0=B0=D0=BC=D0=B5=D1=82=D1=80?= =?UTF-8?q?=D1=8B=20=D0=BA=D0=BE=D0=BD=D1=84=D0=B8=D0=B3=D1=83=D1=80=D0=B0?= =?UTF-8?q?=D1=86=D0=B8=D0=B8=20=D0=B4=D0=BB=D1=8F=20=D0=BF=D1=80=D0=B8?= =?UTF-8?q?=D0=BB=D0=BE=D0=B6=D0=B5=D0=BD=D0=B8=D1=8F=20=D0=BE=D1=82=20?= =?UTF-8?q?=D0=BF=D0=B0=D1=80=D0=B0=D0=BC=D0=B5=D1=82=D1=80=D0=BE=D0=B2=20?= =?UTF-8?q?=D0=BA=D0=BE=D0=BD=D1=84=D0=B8=D0=B3=D1=83=D1=80=D0=B0=D1=86?= =?UTF-8?q?=D0=B8=D0=B8=20=D0=BD=D0=B5=D0=BE=D0=B1=D1=85=D0=BE=D0=B4=D0=B8?= =?UTF-8?q?=D0=BC=D1=8B=D1=85=20=D0=BA=D0=BE=D0=BD=D1=82=D0=B5=D0=B9=D0=BD?= =?UTF-8?q?=D0=B5=D1=80=D0=BE=D0=B2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .env-dist | 50 ++++++++++++++++++---- common/config/config-prod.php | 17 -------- common/config/config.php | 38 ++++++++++------ tests/codeception/api/functional.suite.yml | 2 +- tests/codeception/config/config.php | 17 -------- tests/docker-compose.yml | 25 +++++++---- 6 files changed, 85 insertions(+), 64 deletions(-) diff --git a/.env-dist b/.env-dist index 683a034..33bd18c 100644 --- a/.env-dist +++ b/.env-dist @@ -1,20 +1,56 @@ -# Основные параметры +# Параметры приложения +## Env приложения YII_DEBUG=true YII_ENV=dev + +## Параметры, отвечающие за безопасность JWT_USER_SECRET= + +## Внешние сервисы RECAPTCHA_PUBLIC= RECAPTCHA_SECRET= +## SMTP параметры +SMTP_USER= +SMTP_PASS= +SMTP_PORT= + +## Параметры подключения к базе данных +DB_HOST=db +DB_DATABASE=ely_accounts +DB_USER=ely_accounts_user +DB_PASSWORD=ely_accounts_password + +## Параметры подключения к redis +REDIS_HOST=redis +REDIS_PORT=6379 +REDIS_DATABASE=0 +REDIS_PASSWORD= + +## Параметры подключения к redis +REDIS_HOST=redis +REDIS_PORT=6379 +REDIS_DATABASE=0 +REDIS_PASS= + +## Параметры подключения к rabbitmq +RABBITMQ_HOST=rabbitmq +RABBITMQ_PORT=5672 +RABBITMQ_USER=ely-accounts-app +RABBITMQ_PASS=ely-accounts-app-password +RABBITMQ_VHOST=/ely.by + +## Конфигурация для Dev. +XDEBUG_CONFIG=remote_host=10.254.254.254 +PHP_IDE_CONFIG=serverName=docker + + # Web VIRTUAL_HOST=account.ely.by,authserver.ely.by AUTHSERVER_HOST=authserver.ely.by # LETSENCRYPT_HOST=account.ely.by # LETSENCRYPT_EMAIL=erickskrauch@ely.by -# SMTP (только для production) -SMTP_USER= -SMTP_PASS= - # MySQL MYSQL_ALLOW_EMPTY_PASSWORD=yes MYSQL_ROOT_PASSWORD= @@ -26,7 +62,3 @@ MYSQL_PASSWORD=ely_accounts_password RABBITMQ_DEFAULT_USER=ely-accounts-app RABBITMQ_DEFAULT_PASS=ely-accounts-app-password RABBITMQ_DEFAULT_VHOST=/ely.by - -# Конфигурация для Dev. -XDEBUG_CONFIG=remote_host=10.254.254.254 -PHP_IDE_CONFIG=serverName=docker diff --git a/common/config/config-prod.php b/common/config/config-prod.php index 373f6ca..0160435 100644 --- a/common/config/config-prod.php +++ b/common/config/config-prod.php @@ -6,22 +6,5 @@ return [ 'schemaCacheDuration' => 3600, 'schemaCache' => 'cache', ], - 'mailer' => [ - 'useFileTransport' => false, - 'transport' => [ - 'class' => Swift_SmtpTransport::class, - 'host' => 'ely.by', - 'username' => getenv('SMTP_USER'), - 'password' => getenv('SMTP_PASS'), - 'port' => 587, - 'encryption' => 'tls', - 'streamOptions' => [ - 'ssl' => [ - 'allow_self_signed' => true, - 'verify_peer' => false, - ], - ], - ], - ], ], ]; diff --git a/common/config/config.php b/common/config/config.php index 262b2ec..ed68090 100644 --- a/common/config/config.php +++ b/common/config/config.php @@ -8,9 +8,9 @@ return [ ], 'db' => [ 'class' => yii\db\Connection::class, - 'dsn' => 'mysql:host=db;dbname=' . getenv('MYSQL_DATABASE'), - 'username' => getenv('MYSQL_USER'), - 'password' => getenv('MYSQL_PASSWORD'), + 'dsn' => 'mysql:host=' . (getenv('DB_HOST') ?: 'db') . ';dbname=' . getenv('DB_DATABASE'), + 'username' => getenv('DB_USER'), + 'password' => getenv('DB_PASSWORD'), 'charset' => 'utf8', 'schemaMap' => [ 'mysql' => common\db\mysql\Schema::class, @@ -19,24 +19,38 @@ return [ 'mailer' => [ 'class' => yii\swiftmailer\Mailer::class, 'viewPath' => '@common/mail', + 'transport' => [ + 'class' => Swift_SmtpTransport::class, + 'host' => 'ely.by', + 'username' => getenv('SMTP_USER'), + 'password' => getenv('SMTP_PASS'), + 'port' => getenv('SMTP_PORT') ?: 587, + 'encryption' => 'tls', + 'streamOptions' => [ + 'ssl' => [ + 'allow_self_signed' => true, + 'verify_peer' => false, + ], + ], + ], ], 'security' => [ 'passwordHashStrategy' => 'password_hash', ], 'redis' => [ 'class' => common\components\Redis\Connection::class, - 'hostname' => 'redis', - 'password' => null, - 'port' => 6379, - 'database' => 0, + 'hostname' => getenv('REDIS_HOST') ?: 'redis', + 'password' => getenv('REDIS_PASS') ?: null, + 'port' => getenv('REDIS_PORT') ?: 6379, + 'database' => getenv('REDIS_DATABASE') ?: 0, ], 'amqp' => [ 'class' => common\components\RabbitMQ\Component::class, - 'host' => 'rabbitmq', - 'port' => 5672, - 'user' => getenv('RABBITMQ_DEFAULT_USER'), - 'password' => getenv('RABBITMQ_DEFAULT_PASS'), - 'vhost' => getenv('RABBITMQ_DEFAULT_VHOST'), + 'host' => getenv('RABBITMQ_HOST') ?: 'rabbitmq', + 'port' => getenv('RABBITMQ_PORT') ?: 5672, + 'user' => getenv('RABBITMQ_USER'), + 'password' => getenv('RABBITMQ_PASS'), + 'vhost' => getenv('RABBITMQ_VHOST'), ], 'guzzle' => [ 'class' => GuzzleHttp\Client::class, diff --git a/tests/codeception/api/functional.suite.yml b/tests/codeception/api/functional.suite.yml index 232c933..5d52ea1 100644 --- a/tests/codeception/api/functional.suite.yml +++ b/tests/codeception/api/functional.suite.yml @@ -23,4 +23,4 @@ modules: username: 'ely-accounts-tester' password: 'tester-password' vhost: '/account.ely.by/tests' - queues: ['account-operations'] + queues: [] diff --git a/tests/codeception/config/config.php b/tests/codeception/config/config.php index 3fbe89e..2904804 100644 --- a/tests/codeception/config/config.php +++ b/tests/codeception/config/config.php @@ -10,26 +10,9 @@ return [ ], ], 'components' => [ - 'db' => [ - 'dsn' => 'mysql:host=testdb;dbname=ely_accounts_test', - 'username' => 'ely_accounts_tester', - 'password' => 'ely_accounts_tester_password', - ], - 'mailer' => [ - 'useFileTransport' => true, - ], 'urlManager' => [ 'showScriptName' => true, ], - 'redis' => [ - 'hostname' => 'testredis', - ], - 'amqp' => [ - 'host' => 'testrabbit', - 'user' => 'ely-accounts-tester', - 'password' => 'tester-password', - 'vhost' => '/account.ely.by/tests', - ], 'security' => [ // Для тестов нам не сильно важна безопасность, а вот время прохождения тестов значительно сокращается 'passwordHashCost' => 4, diff --git a/tests/docker-compose.yml b/tests/docker-compose.yml index 4c2d96d..a9e8054 100644 --- a/tests/docker-compose.yml +++ b/tests/docker-compose.yml @@ -11,16 +11,25 @@ services: - testredis - testrabbit volumes: - - ./codeception/_output:/var/www/html/tests/codeception/_output - - ./codeception/api/_output:/var/www/html/tests/codeception/api/_output - - ./codeception/common/_output:/var/www/html/tests/codeception/common/_output - - ./codeception/console/_output:/var/www/html/tests/codeception/console/_output + - ./..:/var/www/html environment: - - YII_DEBUG=true - - YII_ENV=test + YII_DEBUG: "true" + YII_ENV: "test" + # DB config + DB_HOST: "testdb" + DB_DATABASE: "ely_accounts_test" + DB_USER: "ely_accounts_tester" + DB_PASSWORD: "ely_accounts_tester_password" + # Redis config + REDIS_HOST: "testredis" + # RabbitMQ config + RABBITMQ_HOST: "testrabbit" + RABBITMQ_USER: "ely-accounts-tester" + RABBITMQ_PASS: "tester-password" + RABBITMQ_VHOST: "/account.ely.by/tests" # Это я потом, когда-нибудь, уберу - - XDEBUG_CONFIG=remote_host=10.254.254.254 - - PHP_IDE_CONFIG=serverName=docker + XDEBUG_CONFIG: "remote_host=10.254.254.254" + PHP_IDE_CONFIG: "serverName=docker" testdb: container_name: accountelyby_testdb From 7a8f9950ab6ade2bb207fb245157656ae23f86be Mon Sep 17 00:00:00 2001 From: SleepWalker Date: Sun, 4 Dec 2016 15:12:36 +0200 Subject: [PATCH 06/13] #242: reduce npm verbosity in containers and in CI --- .gitlab-ci.yml | 4 ++-- Dockerfile | 4 ++-- Dockerfile-dev | 4 ++-- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 8f832ae..d5aa9ca 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -28,8 +28,8 @@ test:frontend: - frontend/node_modules script: - cd frontend - - npm i --silent - - npm run test + - npm i --silent > /dev/null + - npm run test --silent build:production: image: docker:latest diff --git a/Dockerfile b/Dockerfile index 24a74dc..fe82640 100644 --- a/Dockerfile +++ b/Dockerfile @@ -32,7 +32,7 @@ COPY ./frontend/scripts /var/www/frontend/scripts COPY ./frontend/webpack-utils /var/www/frontend/webpack-utils RUN cd ../frontend \ - && npm install \ + && npm install --quiet --depth -1 \ && cd - # Удаляем ключи из production контейнера на всякий случай @@ -46,7 +46,7 @@ RUN mkdir -p api/runtime api/web/assets console/runtime \ # Билдим фронт && cd frontend \ && ln -s /var/www/frontend/node_modules $PWD/node_modules \ - && npm run build \ + && npm run build:quite --quiet \ && rm node_modules \ # Копируем билд наружу, чтобы его не затёрло volume в dev режиме && cp -r ./dist /var/www/dist \ diff --git a/Dockerfile-dev b/Dockerfile-dev index 67b7943..d5a905e 100644 --- a/Dockerfile-dev +++ b/Dockerfile-dev @@ -32,7 +32,7 @@ COPY ./frontend/scripts /var/www/frontend/scripts COPY ./frontend/webpack-utils /var/www/frontend/webpack-utils RUN cd ../frontend \ - && npm install \ + && npm install --quiet --depth -1 \ && cd - # Наконец переносим все сорцы внутрь контейнера @@ -43,7 +43,7 @@ RUN mkdir -p api/runtime api/web/assets console/runtime \ # Билдим фронт && cd frontend \ && ln -s /var/www/frontend/node_modules $PWD/node_modules \ - && npm run build \ + && npm run build:quite --quiet \ && rm node_modules \ # Копируем билд наружу, чтобы его не затёрло volume в dev режиме && cp -r ./dist /var/www/dist \ From 363b25e6da0b94d53b664cb05cdad390bc079c4f Mon Sep 17 00:00:00 2001 From: ErickSkrauch Date: Sun, 4 Dec 2016 15:49:45 +0300 Subject: [PATCH 07/13] =?UTF-8?q?=D0=9A=D0=BE=D0=BC=D0=BF=D0=BE=D0=BD?= =?UTF-8?q?=D0=B5=D0=BD=D1=82=20RabbitMQ=20=D0=B4=D0=BB=D1=8F=20=D1=82?= =?UTF-8?q?=D0=B5=D1=81=D1=82=D0=BE=D0=B2=20=D0=B7=D0=B0=D0=BC=D0=B5=D0=BD?= =?UTF-8?q?=D1=91=D0=BD=20=D0=BD=D0=B0=20=D0=B7=D0=B0=D0=B3=D0=BB=D1=83?= =?UTF-8?q?=D1=88=D0=BA=D1=83?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- tests/codeception/api/functional.suite.yml | 8 ----- .../common/_support/RabbitMQComponent.php | 33 +++++++++++++++++++ tests/codeception/config/config.php | 3 ++ tests/docker-compose.yml | 14 -------- 4 files changed, 36 insertions(+), 22 deletions(-) create mode 100644 tests/codeception/common/_support/RabbitMQComponent.php diff --git a/tests/codeception/api/functional.suite.yml b/tests/codeception/api/functional.suite.yml index 5d52ea1..01d3dc2 100644 --- a/tests/codeception/api/functional.suite.yml +++ b/tests/codeception/api/functional.suite.yml @@ -5,7 +5,6 @@ modules: - Yii2 - tests\codeception\common\_support\FixtureHelper - Redis - - AMQP - Asserts - REST: depends: Yii2 @@ -17,10 +16,3 @@ modules: host: testredis port: 6379 database: 0 - AMQP: - host: testrabbit - port: 5672 - username: 'ely-accounts-tester' - password: 'tester-password' - vhost: '/account.ely.by/tests' - queues: [] diff --git a/tests/codeception/common/_support/RabbitMQComponent.php b/tests/codeception/common/_support/RabbitMQComponent.php new file mode 100644 index 0000000..4c8fc3a --- /dev/null +++ b/tests/codeception/common/_support/RabbitMQComponent.php @@ -0,0 +1,33 @@ + 4, ], + 'amqp' => [ + 'class' => tests\codeception\common\_support\RabbitMQComponent::class, + ], ], ]; diff --git a/tests/docker-compose.yml b/tests/docker-compose.yml index a9e8054..66ea17f 100644 --- a/tests/docker-compose.yml +++ b/tests/docker-compose.yml @@ -9,7 +9,6 @@ services: depends_on: - testdb - testredis - - testrabbit volumes: - ./..:/var/www/html environment: @@ -22,11 +21,6 @@ services: DB_PASSWORD: "ely_accounts_tester_password" # Redis config REDIS_HOST: "testredis" - # RabbitMQ config - RABBITMQ_HOST: "testrabbit" - RABBITMQ_USER: "ely-accounts-tester" - RABBITMQ_PASS: "tester-password" - RABBITMQ_VHOST: "/account.ely.by/tests" # Это я потом, когда-нибудь, уберу XDEBUG_CONFIG: "remote_host=10.254.254.254" PHP_IDE_CONFIG: "serverName=docker" @@ -45,11 +39,3 @@ services: testredis: container_name: accountelyby_testredis image: redis:3.0-alpine - - testrabbit: - container_name: accountelyby_testrabbit - image: rabbitmq:3.6 - environment: - RABBITMQ_DEFAULT_USER: "ely-accounts-tester" - RABBITMQ_DEFAULT_PASS: "tester-password" - RABBITMQ_DEFAULT_VHOST: "/account.ely.by/tests" From a8c7118e38116b5ec89e2d843124446c78d9af70 Mon Sep 17 00:00:00 2001 From: ErickSkrauch Date: Sun, 4 Dec 2016 19:56:49 +0300 Subject: [PATCH 08/13] =?UTF-8?q?=D0=94=D0=BE=D0=B1=D0=B0=D0=B2=D0=BB?= =?UTF-8?q?=D0=B5=D0=BD=20Helper=20=D0=B4=D0=BB=D1=8F=20AMQP,=20=D0=BA?= =?UTF-8?q?=D0=BE=D1=82=D0=BE=D1=80=D1=8B=D0=B9=20=D1=81=D0=BE=D0=B1=D0=B8?= =?UTF-8?q?=D1=80=D0=B0=D0=B5=D1=82=20=D0=B2=D1=81=D0=B5=20=D0=BF=D0=BE?= =?UTF-8?q?=D1=81=D1=82=D1=83=D0=BF=D0=B0=D1=8E=D1=89=D0=B8=D0=B5=20=D1=81?= =?UTF-8?q?=D0=BE=D0=BE=D0=B1=D1=89=D0=B5=D0=BD=D0=B8=D1=8F=20=D0=B8=20?= =?UTF-8?q?=D0=BF=D1=80=D0=B5=D0=B4=D0=BE=D1=81=D1=82=D0=B0=D0=B2=D0=BB?= =?UTF-8?q?=D1=8F=D0=B5=D1=82=20=D0=BC=D0=B5=D1=82=D0=BE=D0=B4=D1=8B=20?= =?UTF-8?q?=D0=B4=D0=BB=D1=8F=20=D0=BF=D1=80=D0=BE=D0=B2=D0=B5=D1=80=D0=BA?= =?UTF-8?q?=D0=B8=20=D1=81=D0=BE=D0=B7=D0=B4=D0=B0=D0=BD=D0=BD=D1=8B=D1=85?= =?UTF-8?q?=20=D1=81=D0=BE=D0=BE=D0=B1=D1=89=D0=B5=D0=BD=D0=B8=D0=B9=20?= =?UTF-8?q?=D0=98=D1=81=D0=BF=D1=80=D0=B0=D0=B2=D0=BB=D0=B5=D0=BD=20=D0=B1?= =?UTF-8?q?=D0=B0=D0=B3=20=D0=B2=20=D1=84=D0=BE=D1=80=D0=BC=D0=B5=20Change?= =?UTF-8?q?UsernameForm=20=D0=98=D1=81=D0=BF=D1=80=D0=B0=D0=B2=D0=BB=D0=B5?= =?UTF-8?q?=D0=BD=20=D0=B1=D0=B0=D0=B3=20=D1=81=20=D0=BA=D0=BE=D0=BD=D1=84?= =?UTF-8?q?=D0=B8=D0=B3=D1=83=D1=80=D0=B0=D1=86=D0=B8=D0=B5=D0=B9=20=D1=82?= =?UTF-8?q?=D0=B5=D1=81=D1=82=D0=BE=D0=B2,=20=D0=BA=D0=BE=D1=82=D0=BE?= =?UTF-8?q?=D1=80=D1=8B=D0=B9=20=D0=BD=D0=B5=20=D0=BF=D0=BE=D0=B7=D0=B2?= =?UTF-8?q?=D0=BE=D0=BB=D1=8F=D0=BB=20=D0=BF=D1=80=D0=B0=D0=B2=D0=B8=D0=BB?= =?UTF-8?q?=D1=8C=D0=BD=D0=BE=20=D0=BF=D1=80=D0=BE=D0=B2=D0=BE=D0=B4=D0=B8?= =?UTF-8?q?=D1=82=D1=8C=20=D0=BF=D1=80=D0=BE=D0=B2=D0=B5=D1=80=D0=BA=D0=B8?= =?UTF-8?q?=20=D0=BD=D0=B0=20=D1=81=D1=83=D1=89=D0=B5=D1=81=D1=82=D0=B2?= =?UTF-8?q?=D0=BE=D0=B2=D0=B0=D0=BD=D0=B8=D0=B5\=D0=BD=D0=B5=D1=81=D1=83?= =?UTF-8?q?=D1=89=D0=B5=D1=81=D1=82=D0=B2=D0=BE=D0=B2=D0=B0=D0=BD=D0=B8?= =?UTF-8?q?=D0=B5=20=D0=BC=D0=BE=D0=B4=D0=B5=D0=BB=D0=B5=D0=B9=20=D0=94?= =?UTF-8?q?=D0=BE=D0=B1=D0=B0=D0=B2=D0=BB=D0=B5=D0=BD=D0=B0=20=D0=BF=D0=BE?= =?UTF-8?q?=D0=B4=D0=B4=D0=B5=D1=80=D0=B6=D0=BA=D0=B0=20=D0=BF=D0=B5=D1=80?= =?UTF-8?q?=D0=B5=D0=B4=D0=B0=D1=87=D0=B8=20=D1=85=D0=BE=D1=81=D1=82=D0=B0?= =?UTF-8?q?=20Redis=20=D1=87=D0=B5=D1=80=D0=B5=D0=B7=20env=20=D0=BF=D0=B5?= =?UTF-8?q?=D1=80=D0=B5=D0=BC=D0=B5=D0=BD=D0=BD=D1=8B=D0=B5=20=D0=B2=20?= =?UTF-8?q?=D1=82=D0=B5=D1=81=D1=82=D0=B0=D1=85?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- api/models/profile/ChangeUsernameForm.php | 10 +- tests/codeception/api/codeception.yml | 1 + tests/codeception/api/functional.suite.yml | 5 +- tests/codeception/api/unit.suite.yml | 2 + .../authentication/ConfirmEmailFormTest.php | 12 +- .../ChangeEmail/ConfirmNewEmailFormTest.php | 20 +++- .../models/profile/ChangeUsernameFormTest.php | 14 ++- .../common/_support/amqp/Helper.php | 106 ++++++++++++++++++ .../TestComponent.php} | 31 ++++- tests/codeception/common/codeception.yml | 1 + tests/codeception/common/unit.suite.yml | 1 + tests/codeception/config/config.php | 3 - tests/codeception/console/codeception.yml | 1 + tests/codeception/console/unit.suite.yml | 1 + 14 files changed, 188 insertions(+), 20 deletions(-) create mode 100644 tests/codeception/common/_support/amqp/Helper.php rename tests/codeception/common/_support/{RabbitMQComponent.php => amqp/TestComponent.php} (50%) diff --git a/api/models/profile/ChangeUsernameForm.php b/api/models/profile/ChangeUsernameForm.php index fb0a931..9e7dd53 100644 --- a/api/models/profile/ChangeUsernameForm.php +++ b/api/models/profile/ChangeUsernameForm.php @@ -28,15 +28,19 @@ class ChangeUsernameForm extends ApiForm { ]; } - public function change() { + public function change() : bool { if (!$this->validate()) { return false; } - $transaction = Yii::$app->db->beginTransaction(); $account = $this->getAccount(); - $oldNickname = $account->username; + if ($this->username === $account->username) { + return true; + } + + $transaction = Yii::$app->db->beginTransaction(); try { + $oldNickname = $account->username; $account->username = $this->username; if (!$account->save()) { throw new ErrorException('Cannot save account model with new username'); diff --git a/tests/codeception/api/codeception.yml b/tests/codeception/api/codeception.yml index 4318152..92cfc34 100644 --- a/tests/codeception/api/codeception.yml +++ b/tests/codeception/api/codeception.yml @@ -1,5 +1,6 @@ namespace: tests\codeception\api actor: Tester +params: [env] paths: tests: . log: _output diff --git a/tests/codeception/api/functional.suite.yml b/tests/codeception/api/functional.suite.yml index 01d3dc2..713312d 100644 --- a/tests/codeception/api/functional.suite.yml +++ b/tests/codeception/api/functional.suite.yml @@ -4,6 +4,7 @@ modules: - Filesystem - Yii2 - tests\codeception\common\_support\FixtureHelper + - tests\codeception\common\_support\amqp\Helper - Redis - Asserts - REST: @@ -11,8 +12,8 @@ modules: config: Yii2: configFile: '../config/api/functional.php' - cleanup: true + cleanup: false Redis: - host: testredis + host: "%REDIS_HOST%" port: 6379 database: 0 diff --git a/tests/codeception/api/unit.suite.yml b/tests/codeception/api/unit.suite.yml index 8ce2d31..3d31363 100644 --- a/tests/codeception/api/unit.suite.yml +++ b/tests/codeception/api/unit.suite.yml @@ -3,6 +3,8 @@ modules: enabled: - Yii2: part: [orm, email, fixtures] + - tests\codeception\common\_support\amqp\Helper config: Yii2: configFile: '../config/api/unit.php' + cleanup: false diff --git a/tests/codeception/api/unit/models/authentication/ConfirmEmailFormTest.php b/tests/codeception/api/unit/models/authentication/ConfirmEmailFormTest.php index 1fd318b..2bbd5d7 100644 --- a/tests/codeception/api/unit/models/authentication/ConfirmEmailFormTest.php +++ b/tests/codeception/api/unit/models/authentication/ConfirmEmailFormTest.php @@ -25,9 +25,15 @@ class ConfirmEmailFormTest extends TestCase { $this->assertInstanceOf(AccountSession::class, $result->getSession(), 'session was generated'); $activationExists = EmailActivation::find()->andWhere(['key' => $fixture['key']])->exists(); $this->assertFalse($activationExists, 'email activation key is not exist'); - /** @var Account $user */ - $user = Account::findOne($fixture['account_id']); - $this->assertEquals(Account::STATUS_ACTIVE, $user->status, 'user status changed to active'); + /** @var Account $account */ + $account = Account::findOne($fixture['account_id']); + $this->assertEquals(Account::STATUS_ACTIVE, $account->status, 'user status changed to active'); + + $message = $this->tester->grabLastSentAmqpMessage('events'); + $body = json_decode($message->getBody(), true); + $this->assertEquals($account->id, $body['accountId']); + $this->assertEquals($account->username, $body['newUsername']); + $this->assertNull($body['oldUsername']); } private function createModel($key) { diff --git a/tests/codeception/api/unit/models/profile/ChangeEmail/ConfirmNewEmailFormTest.php b/tests/codeception/api/unit/models/profile/ChangeEmail/ConfirmNewEmailFormTest.php index 68ab6c4..3ac9e26 100644 --- a/tests/codeception/api/unit/models/profile/ChangeEmail/ConfirmNewEmailFormTest.php +++ b/tests/codeception/api/unit/models/profile/ChangeEmail/ConfirmNewEmailFormTest.php @@ -18,9 +18,8 @@ class ConfirmNewEmailFormTest extends TestCase { } public function testChangeEmail() { - $accountId = $this->tester->grabFixture('accounts', 'account-with-change-email-finish-state')['id']; /** @var Account $account */ - $account = Account::findOne($accountId); + $account = Account::findOne($this->getAccountId()); $newEmailConfirmationFixture = $this->tester->grabFixture('emailActivations', 'newEmailConfirmation'); $model = new ConfirmNewEmailForm($account, [ 'key' => $newEmailConfirmationFixture['key'], @@ -32,6 +31,23 @@ class ConfirmNewEmailFormTest extends TestCase { ])); $data = unserialize($newEmailConfirmationFixture['_data']); $this->assertEquals($data['newEmail'], $account->email); + $this->tester->canSeeAmqpMessageIsCreated('events'); + } + + public function testCreateTask() { + /** @var Account $account */ + $account = Account::findOne($this->getAccountId()); + $model = new ConfirmNewEmailForm($account); + $model->createTask(1, 'test1@ely.by', 'test@ely.by'); + $message = $this->tester->grabLastSentAmqpMessage('events'); + $body = json_decode($message->getBody(), true); + $this->assertEquals(1, $body['accountId']); + $this->assertEquals('test1@ely.by', $body['newEmail']); + $this->assertEquals('test@ely.by', $body['oldEmail']); + } + + private function getAccountId() { + return $this->tester->grabFixture('accounts', 'account-with-change-email-finish-state')['id']; } } diff --git a/tests/codeception/api/unit/models/profile/ChangeUsernameFormTest.php b/tests/codeception/api/unit/models/profile/ChangeUsernameFormTest.php index a41dd75..158b17e 100644 --- a/tests/codeception/api/unit/models/profile/ChangeUsernameFormTest.php +++ b/tests/codeception/api/unit/models/profile/ChangeUsernameFormTest.php @@ -35,6 +35,7 @@ class ChangeUsernameFormTest extends TestCase { $this->assertTrue($model->change()); $this->assertEquals('my_new_nickname', Account::findOne($this->getAccountId())->username); $this->assertInstanceOf(UsernameHistory::class, UsernameHistory::findOne(['username' => 'my_new_nickname'])); + $this->tester->canSeeAmqpMessageIsCreated('events'); } public function testChangeWithoutChange() { @@ -49,7 +50,8 @@ class ChangeUsernameFormTest extends TestCase { 'AND', 'username' => $username, ['>=', 'applied_in', $callTime], - ]), 'no new UsernameHistory record, if we don\'t change nickname'); + ]), 'no new UsernameHistory record, if we don\'t change username'); + $this->tester->cantSeeAmqpMessageIsCreated('events'); } public function testChangeCase() { @@ -65,13 +67,17 @@ class ChangeUsernameFormTest extends TestCase { UsernameHistory::findOne(['username' => $newUsername]), 'username should change, if we change case of some letters' ); + $this->tester->canSeeAmqpMessageIsCreated('events'); } public function testCreateTask() { $model = new ChangeUsernameForm(); - $model->createEventTask('1', 'test1', 'test'); - // TODO: у меня пока нет идей о том, чтобы это как-то успешно протестировать, увы - // но по крайней мере можно убедиться, что оно не падает где-то на этом шаге + $model->createEventTask(1, 'test1', 'test'); + $message = $this->tester->grabLastSentAmqpMessage('events'); + $body = json_decode($message->getBody(), true); + $this->assertEquals(1, $body['accountId']); + $this->assertEquals('test1', $body['newUsername']); + $this->assertEquals('test', $body['oldUsername']); } private function getAccountId() { diff --git a/tests/codeception/common/_support/amqp/Helper.php b/tests/codeception/common/_support/amqp/Helper.php new file mode 100644 index 0000000..bea9e03 --- /dev/null +++ b/tests/codeception/common/_support/amqp/Helper.php @@ -0,0 +1,106 @@ +getYii2()->client; + $app = $connector->getApplication(); + $app->set('amqp', [ + 'class' => TestComponent::class, + ]); + + parent::_before($test); + } + + /** + * Checks that message is created. + * + * ```php + * seeAmqpMessageIsCreated(); + * + * // check that only 3 messages were created + * $I->seeAmqpMessageIsCreated(3); + * ``` + * + * @param string|null $exchange + * @param int|null $num + */ + public function seeAmqpMessageIsCreated($exchange = null, $num = null) { + if ($num === null) { + $this->assertNotEmpty($this->grabSentAmqpMessages($exchange), 'message were created'); + return; + } + + // TODO: заменить на assertCount() после релиза Codeception 2.2.7 + // https://github.com/Codeception/Codeception/pull/3802 + /** @noinspection PhpUnitTestsInspection */ + $this->assertEquals( + $num, + count($this->grabSentAmqpMessages($exchange)), + 'number of created messages is equal to ' . $num + ); + } + + /** + * Checks that no messages was created + * + * @param string|null $exchange + */ + public function dontSeeAmqpMessageIsCreated($exchange = null) { + $this->seeAmqpMessageIsCreated($exchange, 0); + } + + /** + * Returns last sent message + * + * @param string|null $exchange + * @return \PhpAmqpLib\Message\AMQPMessage + */ + public function grabLastSentAmqpMessage($exchange = null) { + $this->seeAmqpMessageIsCreated(); + $messages = $this->grabSentAmqpMessages($exchange); + + return end($messages); + } + + /** + * Returns array of all sent amqp messages. + * Each message is `\PhpAmqpLib\Message\AMQPMessage` instance. + * Useful to perform additional checks using `Asserts` module. + * + * @param string|null $exchange + * @return \PhpAmqpLib\Message\AMQPMessage[] + * @throws ModuleException + */ + public function grabSentAmqpMessages($exchange = null) { + $amqp = $this->grabComponent('amqp'); + if (!$amqp instanceof TestComponent) { + throw new ModuleException($this, 'AMQP module is not mocked, can\'t test messages'); + } + + return $amqp->getSentMessages($exchange); + } + + private function grabComponent(string $component) { + return $this->getYii2()->grabComponent($component); + } + + private function getYii2() : Yii2 { + $yii2 = $this->getModule('Yii2'); + if (!$yii2 instanceof Yii2) { + throw new ModuleException($this, 'Yii2 module must be configured'); + } + + return $yii2; + } + +} diff --git a/tests/codeception/common/_support/RabbitMQComponent.php b/tests/codeception/common/_support/amqp/TestComponent.php similarity index 50% rename from tests/codeception/common/_support/RabbitMQComponent.php rename to tests/codeception/common/_support/amqp/TestComponent.php index 4c8fc3a..9b8e159 100644 --- a/tests/codeception/common/_support/RabbitMQComponent.php +++ b/tests/codeception/common/_support/amqp/TestComponent.php @@ -1,10 +1,16 @@ sentMessages[$exchangeName][] = $this->prepareMessage($message); + } + + /** + * @param string|null $exchangeName + * @return \PhpAmqpLib\Message\AMQPMessage[] + */ + public function getSentMessages(string $exchangeName = null) : array { + if ($exchangeName !== null) { + return $this->sentMessages[$exchangeName] ?? []; + } else { + $messages = []; + foreach($this->sentMessages as $exchangeGroup) { + foreach ($exchangeGroup as $message) { + $messages[] = $message; + } + } + + return $messages; + } } } diff --git a/tests/codeception/common/codeception.yml b/tests/codeception/common/codeception.yml index f81585b..ff6249c 100644 --- a/tests/codeception/common/codeception.yml +++ b/tests/codeception/common/codeception.yml @@ -1,5 +1,6 @@ namespace: tests\codeception\common actor: Tester +params: [env] paths: tests: . log: _output diff --git a/tests/codeception/common/unit.suite.yml b/tests/codeception/common/unit.suite.yml index d072b09..98fb59d 100644 --- a/tests/codeception/common/unit.suite.yml +++ b/tests/codeception/common/unit.suite.yml @@ -6,3 +6,4 @@ modules: config: Yii2: configFile: '../config/common/unit.php' + cleanup: false diff --git a/tests/codeception/config/config.php b/tests/codeception/config/config.php index fe8a64c..2904804 100644 --- a/tests/codeception/config/config.php +++ b/tests/codeception/config/config.php @@ -17,8 +17,5 @@ return [ // Для тестов нам не сильно важна безопасность, а вот время прохождения тестов значительно сокращается 'passwordHashCost' => 4, ], - 'amqp' => [ - 'class' => tests\codeception\common\_support\RabbitMQComponent::class, - ], ], ]; diff --git a/tests/codeception/console/codeception.yml b/tests/codeception/console/codeception.yml index 14c972e..57e8496 100644 --- a/tests/codeception/console/codeception.yml +++ b/tests/codeception/console/codeception.yml @@ -1,5 +1,6 @@ namespace: tests\codeception\console actor: Tester +params: [env] paths: tests: . log: _output diff --git a/tests/codeception/console/unit.suite.yml b/tests/codeception/console/unit.suite.yml index 3ac6f10..bdcb10b 100644 --- a/tests/codeception/console/unit.suite.yml +++ b/tests/codeception/console/unit.suite.yml @@ -6,3 +6,4 @@ modules: config: Yii2: configFile: '../config/console/unit.php' + cleanup: false From 0d7ed89ca56f300262983fccc8e45c52039c7893 Mon Sep 17 00:00:00 2001 From: ErickSkrauch Date: Mon, 5 Dec 2016 19:22:24 +0300 Subject: [PATCH 09/13] =?UTF-8?q?=D0=9F=D1=80=D0=BE=D0=B1=D0=B0=20=D1=82?= =?UTF-8?q?=D0=B5=D1=81=D1=82=D0=B8=D1=80=D0=BE=D0=B2=D0=B0=D0=BD=D0=B8?= =?UTF-8?q?=D1=8F=20=D0=BF=D1=80=D0=B8=D0=BB=D0=BE=D0=B6=D0=B5=D0=BD=D0=B8?= =?UTF-8?q?=D1=8F=20=D1=87=D0=B5=D1=80=D0=B5=D0=B7=20gitlab-ci=20services?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .gitlab-ci.yml | 32 +++++++++++++++++++++++++------- Dockerfile-dev | 2 +- 2 files changed, 26 insertions(+), 8 deletions(-) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index d5aa9ca..f70e788 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -4,21 +4,39 @@ stages: - release variables: - CONTAINER_IMAGE: registry.ely.by/elyby/accounts + CONTAINER_IMAGE: "registry.ely.by/elyby/accounts" test:backend: - image: jonaskello/docker-and-compose:1.12.1-1.8.0 + image: docker:latest services: - - docker:1.12.1-dind + - mariadb:10.0 + - redis:3.0-alpine + variables: + # mariadb config + MYSQL_RANDOM_ROOT_PASSWORD: "true" + MYSQL_DATABASE: "ely_accounts_test" + MYSQL_USER: "ely_accounts_tester" + MYSQL_PASSWORD: "ely_accounts_tester_password" stage: test before_script: - docker login -u gitlab-ci -p $CI_BUILD_TOKEN registry.ely.by - echo "$SSH_PRIVATE_KEY" > id_rsa - - docker-compose -f tests/docker-compose.yml build --pull testphp - after_script: - - docker-compose -f tests/docker-compose.yml down -v script: - - docker-compose -f tests/docker-compose.yml run --rm testphp ./vendor/bin/codecept run -c tests + - export TEMP_DEV_IMAGE="${CONTAINER_IMAGE}:ci-${CI_BUILD_ID}" + - docker build --pull -f Dockerfile-dev -t $TEMP_DEV_IMAGE . + - > + docker run --rm + --add-host=mariadb:`getent hosts mariadb | awk '{ print $1 ; exit }'` + --add-host=redis:`getent hosts redis | awk '{ print $1 ; exit }'` + -e YII_DEBUG="true" + -e YII_ENV="test" + -e DB_HOST="mariadb" + -e DB_DATABASE="ely_accounts_test" + -e DB_USER="ely_accounts_tester" + -e DB_PASSWORD="ely_accounts_tester_password" + -e REDIS_HOST="redis" + $TEMP_DEV_IMAGE + php vendor/bin/codecept run -c tests test:frontend: image: node:5.12 diff --git a/Dockerfile-dev b/Dockerfile-dev index 133d64d..9d3ad4a 100644 --- a/Dockerfile-dev +++ b/Dockerfile-dev @@ -1,4 +1,4 @@ -FROM registry.ely.by/elyby/accounts-php:1.1.2-dev +FROM registry.ely.by/elyby/accounts-php:latest-dev # Вносим конфигурации для крона и воркеров COPY docker/cron/* /etc/cron.d/ From c3fb2d7b34679e3a2e35f2bbb80ee22a4002fed2 Mon Sep 17 00:00:00 2001 From: ErickSkrauch Date: Wed, 7 Dec 2016 00:53:38 +0300 Subject: [PATCH 10/13] =?UTF-8?q?=D0=98=D1=81=D0=BF=D1=80=D0=B0=D0=B2?= =?UTF-8?q?=D0=BB=D0=B5=D0=BD=20=D0=BC=D0=BE=D0=BA=20=D1=81=D0=BE=D0=B5?= =?UTF-8?q?=D0=B4=D0=B8=D0=BD=D0=B5=D0=BD=D0=B8=D1=8F=20=D1=81=20=D1=80?= =?UTF-8?q?=D1=8D=D0=B1=D0=B8=D1=82=D0=BE=D0=BC=20=D0=B4=D0=BB=D1=8F=20?= =?UTF-8?q?=D1=84=D1=83=D0=BD=D0=BA=D1=86=D0=B8=D0=BE=D0=BD=D0=B0=D0=BB?= =?UTF-8?q?=D1=8C=D0=BD=D1=8B=D1=85=20=D1=82=D0=B5=D1=81=D1=82=D0=BE=D0=B2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- tests/codeception/common/_support/amqp/Helper.php | 12 ------------ tests/codeception/config/config.php | 3 +++ 2 files changed, 3 insertions(+), 12 deletions(-) diff --git a/tests/codeception/common/_support/amqp/Helper.php b/tests/codeception/common/_support/amqp/Helper.php index bea9e03..7c6cd1b 100644 --- a/tests/codeception/common/_support/amqp/Helper.php +++ b/tests/codeception/common/_support/amqp/Helper.php @@ -4,21 +4,9 @@ namespace tests\codeception\common\_support\amqp; use Codeception\Exception\ModuleException; use Codeception\Module; use Codeception\Module\Yii2; -use Codeception\TestInterface; class Helper extends Module { - public function _before(TestInterface $test) { - /** @var \Codeception\Lib\Connector\Yii2 $connector */ - $connector = $this->getYii2()->client; - $app = $connector->getApplication(); - $app->set('amqp', [ - 'class' => TestComponent::class, - ]); - - parent::_before($test); - } - /** * Checks that message is created. * diff --git a/tests/codeception/config/config.php b/tests/codeception/config/config.php index 2904804..dedd16f 100644 --- a/tests/codeception/config/config.php +++ b/tests/codeception/config/config.php @@ -17,5 +17,8 @@ return [ // Для тестов нам не сильно важна безопасность, а вот время прохождения тестов значительно сокращается 'passwordHashCost' => 4, ], + 'amqp' => [ + 'class' => tests\codeception\common\_support\amqp\TestComponent::class, + ], ], ]; From 49a6d4a37d2ae67b8ba474d79709cfa38f1d2871 Mon Sep 17 00:00:00 2001 From: ErickSkrauch Date: Wed, 7 Dec 2016 01:34:51 +0300 Subject: [PATCH 11/13] =?UTF-8?q?=D0=9F=D1=80=D0=BE=D0=B1=D1=83=D0=B5?= =?UTF-8?q?=D0=BC=20=D0=B8=D1=81=D0=BF=D0=BE=D0=BB=D1=8C=D0=B7=D0=BE=D0=B2?= =?UTF-8?q?=D0=B0=D1=82=D1=8C=20aufs=20=D0=BF=D1=80=D0=B8=20=D0=B1=D0=B8?= =?UTF-8?q?=D0=BB=D0=B4=D0=B5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .gitlab-ci.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index f70e788..f6b5827 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -4,6 +4,7 @@ stages: - release variables: + DOCKER_DRIVER: aufs CONTAINER_IMAGE: "registry.ely.by/elyby/accounts" test:backend: From a1823db18955fbad542f9157c8568e193818549e Mon Sep 17 00:00:00 2001 From: ErickSkrauch Date: Wed, 7 Dec 2016 12:37:44 +0300 Subject: [PATCH 12/13] =?UTF-8?q?=D0=98=D1=81=D0=BF=D0=BE=D0=BB=D1=8C?= =?UTF-8?q?=D0=B7=D1=83=D0=B5=D0=BC=20PHP=207.1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Dockerfile | 2 +- Dockerfile-dev | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Dockerfile b/Dockerfile index 946aa35..d76207d 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,4 +1,4 @@ -FROM registry.ely.by/elyby/accounts-php:1.1.2 +FROM registry.ely.by/elyby/accounts-php:1.2.0 # Вносим конфигурации для крона и воркеров COPY docker/cron/* /etc/cron.d/ diff --git a/Dockerfile-dev b/Dockerfile-dev index 9d3ad4a..ef963fb 100644 --- a/Dockerfile-dev +++ b/Dockerfile-dev @@ -1,4 +1,4 @@ -FROM registry.ely.by/elyby/accounts-php:latest-dev +FROM registry.ely.by/elyby/accounts-php:1.2.0-dev # Вносим конфигурации для крона и воркеров COPY docker/cron/* /etc/cron.d/ From 6484ec2fdc0582ab41dd0d64a0474febcb1974b7 Mon Sep 17 00:00:00 2001 From: ErickSkrauch Date: Wed, 7 Dec 2016 12:38:21 +0300 Subject: [PATCH 13/13] =?UTF-8?q?=D0=98=D1=81=D0=BF=D0=BE=D0=BB=D1=8C?= =?UTF-8?q?=D0=B7=D1=83=D0=B5=D0=BC=20Yii2=202.0.10?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index ae78d32..d897196 100644 --- a/composer.json +++ b/composer.json @@ -15,7 +15,7 @@ "minimum-stability": "stable", "require": { "php": "^7.0.6", - "yiisoft/yii2": "2.0.9", + "yiisoft/yii2": "2.0.10", "yiisoft/yii2-swiftmailer": "*", "ramsey/uuid": "^3.5.0", "league/oauth2-server": "dev-improvements#b9277ccd664dcb80a766b73674d21de686cb9dda",