Skip to content

Commit 0ebfaa0

Browse files
author
Eugene Terentev
committed
PHP 7.1
1 parent a4aaa56 commit 0ebfaa0

28 files changed

+190
-275
lines changed

.env.dist

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ DB_USERNAME = ysk_dbu
1414
DB_PASSWORD = ysk_pass
1515
DB_TABLE_PREFIX =
1616

17-
TEST_DB_DSN = mysql:host=localhost;port=3306;dbname=yii2-starter-kit-test
17+
TEST_DB_DSN = mysql:host=db;port=3306;dbname=yii2-starter-kit-test
1818
TEST_DB_USERNAME = root
1919
TEST_DB_PASSWORD = root
2020

.travis.yml

+17-30
Original file line numberDiff line numberDiff line change
@@ -1,44 +1,31 @@
1-
language: php
1+
sudo: true
2+
dist: trusty
23

3-
php:
4-
- 7.0
5-
6-
# faster builds on new travis setup not using sudo
7-
sudo: false
4+
env:
5+
- COMPOSE_FILE=docker/travis.yml
86

97
services:
10-
- mysql
8+
- docker
119

1210
# cache vendor dirs
1311
cache:
1412
directories:
15-
- $HOME/.composer/cache
1613
- vendor
1714

18-
install:
19-
- travis_retry phpenv config-rm xdebug.ini
20-
- travis_retry composer self-update && composer --version
21-
- travis_retry composer install --dev --prefer-source --no-interaction
22-
23-
# setup application:
24-
- |
25-
cp .env.dist .env
26-
sed -i s/yii2-starter-kit\.dev/localhost:8080/ .env
15+
before_install:
16+
- docker-compose up --force-recreate -d
2717

28-
- |
29-
cd tests/codeception/backend && codecept build
30-
cd ../common && codecept build
31-
cd ../console && codecept build
32-
cd ../frontend && codecept build
33-
cd ../../../
18+
install:
19+
- cp .env.dist .env
20+
- sed -i s/yii2-starter-kit-test/yii2-starter-kit/ .env
21+
- docker-compose exec -T app composer install --dev --prefer-source --no-interaction
22+
- docker-compose exec -T app ./vendor/bin/codecept build
23+
- sleep 10 # waiting for mysql to start accepting connections
3424

3525
before_script:
36-
- mysql -e 'CREATE DATABASE `yii2-starter-kit`;';
37-
- php tests/codeception/bin/yii app/setup --interactive=0
38-
- php tests/codeception/bin/yii app/truncate --interactive=0
26+
- docker-compose exec -T app php console/yii app/setup --interactive=0
27+
- docker-compose exec -T app php console/yii app/truncate --interactive=0
3928

4029
script:
41-
- |
42-
php -S localhost:8080 > /dev/null 2>&1 &
43-
cd tests
44-
./../vendor/bin/codecept run --debug
30+
- docker-compose exec -T app php -S 127.0.0.1:8080 > /dev/null 2>&1 &
31+
- docker-compose exec -T app ./vendor/bin/codecept run --debug

backend/web/index-test.php

+9-1
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,14 @@
1717
require(__DIR__ . '/../../common/config/bootstrap.php');
1818
require(__DIR__ . '/../config/bootstrap.php');
1919

20-
$config = require(__DIR__ . '/../../tests/config/backend/acceptance.php');
20+
$config = yii\helpers\ArrayHelper::merge(
21+
require(__DIR__ . '/../../common/config/base.php'),
22+
require(__DIR__ . '/../../common/config/web.php'),
23+
require(__DIR__ . '/../config/base.php'),
24+
require(__DIR__ . '/../config/web.php'),
25+
require(__DIR__ . '/../../tests/config/base.php'),
26+
require(__DIR__ . '/../../tests/config/common/acceptance.php'),
27+
require(__DIR__ . '/../../tests/config/backend/acceptance.php')
28+
);
2129

2230
(new yii\web\Application($config))->run();

common/helpers.php

-13
Original file line numberDiff line numberDiff line change
@@ -36,19 +36,6 @@ function redirect($url, $statusCode = 302)
3636
return Yii::$app->controller->redirect($url, $statusCode);
3737
}
3838

39-
/**
40-
* @param $form \yii\widgets\ActiveForm
41-
* @param $model
42-
* @param $attribute
43-
* @param array $inputOptions
44-
* @param array $fieldOptions
45-
* @return string
46-
*/
47-
function activeTextinput($form, $model, $attribute, $inputOptions = [], $fieldOptions = [])
48-
{
49-
return $form->field($model, $attribute, $fieldOptions)->textInput($inputOptions);
50-
}
51-
5239
/**
5340
* @param string $key
5441
* @param mixed $default

composer.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
"source": "https://github.com/trntv/yii2-starter-kit"
2525
},
2626
"require": {
27-
"php": ">=7.0.0",
27+
"php": ">=7.1.0",
2828
"ext-intl": "*",
2929
"yiisoft/yii2": "^2.0.13",
3030
"yiisoft/yii2-bootstrap": "^2.0.0",

console/config/console.php

+4-4
Original file line numberDiff line numberDiff line change
@@ -5,18 +5,18 @@
55
'controllerNamespace' => 'console\controllers',
66
'controllerMap' => [
77
'command-bus' => [
8-
'class' => 'trntv\bus\console\BackgroundBusController',
8+
'class' => trntv\bus\console\BackgroundBusController::class,
99
],
1010
'message' => [
11-
'class' => 'console\controllers\ExtendedMessageController'
11+
'class' => console\controllers\ExtendedMessageController::class
1212
],
1313
'migrate' => [
14-
'class' => 'yii\console\controllers\MigrateController',
14+
'class' => yii\console\controllers\MigrateController::class,
1515
'migrationPath' => '@common/migrations/db',
1616
'migrationTable' => '{{%system_db_migration}}'
1717
],
1818
'rbac-migrate' => [
19-
'class' => 'console\controllers\RbacMigrateController',
19+
'class' => console\controllers\RbacMigrateController::class,
2020
'migrationPath' => '@common/migrations/rbac/',
2121
'migrationTable' => '{{%system_rbac_migration}}',
2222
'templateFile' => '@common/rbac/views/migration.php'

console/controllers/AppController.php

+43-47
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,6 @@
1212
*/
1313
class AppController extends Controller
1414
{
15-
private static $dbName;
16-
private static $db;
1715
public $writablePaths = [
1816
'@common/runtime',
1917
'@frontend/runtime',
@@ -33,33 +31,17 @@ class AppController extends Controller
3331
];
3432

3533
/**
36-
* AppController constructor.
37-
* @param string $id
38-
* @param Module $module
39-
* @param array $config
34+
* Sets given keys to .env file
4035
*/
41-
public function __construct($id, Module $module, array $config = [])
36+
public function actionSetKeys()
4237
{
43-
self::$db = \Yii::$app->db;
44-
self::$dbName = $this->getDsnAttribute(self::$db->dsn, 'dbname');
45-
parent::__construct($id, $module, $config);
38+
$this->setKeys($this->generateKeysPaths);
4639
}
4740

4841
/**
49-
* Parses DNS string to find name of database
50-
* @param $name string, string to find
51-
* @param $dsn string, DNS string
52-
* @return null|string
42+
* @throws \yii\base\InvalidRouteException
43+
* @throws \yii\console\Exception
5344
*/
54-
private function getDsnAttribute($dsn, $name = 'dbname')
55-
{
56-
if (preg_match('/' . $name . '=([^;]*)/', $dsn, $match)) {
57-
return $match[1];
58-
} else {
59-
return null;
60-
}
61-
}
62-
6345
public function actionSetup()
6446
{
6547
$this->runAction('set-writable', ['interactive' => $this->interactive]);
@@ -71,45 +53,63 @@ public function actionSetup()
7153

7254
/**
7355
* Truncates all tables in the database.
56+
* @throws \yii\db\Exception
7457
*/
7558
public function actionTruncate()
7659
{
77-
if ($this->confirm('This will truncate all tables of current database [' . self::$dbName . '].')) {
78-
self::$db->createCommand('SET FOREIGN_KEY_CHECKS=0')->execute();
79-
$command = self::$db->createCommand("SHOW FULL TABLES WHERE TABLE_TYPE LIKE '%TABLE'");
60+
$dbName = Yii::$app->db->createCommand('SELECT DATABASE()')->queryScalar();
61+
if ($this->confirm('This will truncate all tables of current database [' . $dbName . '].')) {
62+
Yii::$app->db->createCommand('SET FOREIGN_KEY_CHECKS=0')->execute();
63+
$command = Yii::$app->db->createCommand("SHOW FULL TABLES WHERE TABLE_TYPE LIKE '%TABLE'");
8064
$res = $command->queryAll();
8165
foreach ($res as $row) {
82-
$rowName = 'Tables_in_' . self::$dbName;
66+
$rowName = sprintf('Tables_in_%s', $dbName);
8367
$this->stdout('Truncating table ' . $row[$rowName] . PHP_EOL, Console::FG_RED);
84-
self::$db->createCommand()->truncateTable($row[$rowName])->execute();
68+
Yii::$app->db->createCommand()->truncateTable($row[$rowName])->execute();
8569
}
86-
self::$db->createCommand('SET FOREIGN_KEY_CHECKS=1')->execute();
70+
Yii::$app->db->createCommand('SET FOREIGN_KEY_CHECKS=1')->execute();
8771
}
8872
}
8973

9074
/**
9175
* Drops all tables in the database.
76+
* @throws \yii\db\Exception
9277
*/
9378
public function actionDrop()
9479
{
95-
if ($this->confirm('This will drop all tables of current database [' . self::$dbName . '].')) {
96-
self::$db->createCommand("SET foreign_key_checks = 0")->execute();
97-
$tables = self::$db->schema->getTableNames();
80+
$dbName = Yii::$app->db->createCommand('SELECT DATABASE()')->queryScalar();
81+
if ($this->confirm('This will drop all tables of current database [' . $dbName . '].')) {
82+
Yii::$app->db->createCommand("SET foreign_key_checks = 0")->execute();
83+
$tables = Yii::$app->db->schema->getTableNames();
9884
foreach ($tables as $table) {
9985
$this->stdout('Dropping table ' . $table . PHP_EOL, Console::FG_RED);
100-
self::$db->createCommand()->dropTable($table)->execute();
86+
Yii::$app->db->createCommand()->dropTable($table)->execute();
10187
}
102-
self::$db->createCommand("SET foreign_key_checks = 1")->execute();
88+
Yii::$app->db->createCommand("SET foreign_key_checks = 1")->execute();
10389
}
10490
}
10591

10692

93+
/**
94+
* Adds write permissions
95+
*/
10796
public function actionSetWritable()
10897
{
10998
$this->setWritable($this->writablePaths);
11099
}
111100

112-
public function setWritable($paths)
101+
/**
102+
* Adds execute permissions
103+
*/
104+
public function actionSetExecutable()
105+
{
106+
$this->setExecutable($this->executablePaths);
107+
}
108+
109+
/**
110+
* @param $paths
111+
*/
112+
private function setWritable($paths)
113113
{
114114
foreach ($paths as $writable) {
115115
$writable = Yii::getAlias($writable);
@@ -118,12 +118,10 @@ public function setWritable($paths)
118118
}
119119
}
120120

121-
public function actionSetExecutable()
122-
{
123-
$this->setExecutable($this->executablePaths);
124-
}
125-
126-
public function setExecutable($paths)
121+
/**
122+
* @param $paths
123+
*/
124+
private function setExecutable($paths)
127125
{
128126
foreach ($paths as $executable) {
129127
$executable = Yii::getAlias($executable);
@@ -132,12 +130,10 @@ public function setExecutable($paths)
132130
}
133131
}
134132

135-
public function actionSetKeys()
136-
{
137-
$this->setKeys($this->generateKeysPaths);
138-
}
139-
140-
public function setKeys($paths)
133+
/**
134+
* @param $paths
135+
*/
136+
private function setKeys($paths)
141137
{
142138
foreach ($paths as $file) {
143139
$file = Yii::getAlias($file);

docker-compose.yml

+1-2
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ services:
2929
- 1080:1080
3030

3131
db:
32-
image: mysql:5.7
32+
image: mysql:8
3333
volumes:
3434
- /var/lib/mysql
3535
ports:
@@ -39,4 +39,3 @@ services:
3939
MYSQL_DATABASE: yii2-starter-kit
4040
MYSQL_USER: ysk_dbu
4141
MYSQL_PASSWORD: ysk_pass
42-
command: ["--character-set-server=utf8mb4", "--collation-server=utf8mb4_unicode_ci"]

docker/travis.yml

+28
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
version: "3"
2+
3+
services:
4+
app:
5+
build: php
6+
working_dir: /app
7+
volumes:
8+
- ../:/app
9+
depends_on:
10+
- db
11+
12+
nginx:
13+
image: nginx:1.12-alpine
14+
ports:
15+
- 80:80
16+
volumes:
17+
- ../:/app
18+
- ./nginx/vhost.conf:/etc/nginx/conf.d/vhost.conf
19+
depends_on:
20+
- app
21+
22+
db:
23+
image: mysql:8
24+
environment:
25+
MYSQL_ROOT_PASSWORD: root
26+
MYSQL_DATABASE: yii2-starter-kit
27+
MYSQL_USER: ysk_dbu
28+
MYSQL_PASSWORD: ysk_pass

docs/console.md

-13
Original file line numberDiff line numberDiff line change
@@ -23,16 +23,3 @@ Provides migrate functionality for RBAC.
2323
``php console/yii rbac-migrate/up``
2424

2525
``php console/yii rbac-migrate/down all``
26-
27-
### Compress assets
28-
You need to have yuicompressor and uglifyjs installed.
29-
30-
```php console/yii asset/compress frontend/config/assets/compress.php frontend/config/assets/_bundles.php```
31-
32-
then uncomment these lines in the ``frontend/config/web.php``
33-
```
34-
// Compressed assets
35-
//$config['components']['assetManager'] = [
36-
// 'bundles' => require(__DIR__ . '/assets/_bundles.php')
37-
//];
38-
```

docs/testing.md

+3-7
Original file line numberDiff line numberDiff line change
@@ -13,17 +13,13 @@ docker-compose exec db mysql -uroot -proot -e "CREATE DATABASE \`yii2-starter-ki
1313
3. Adjust `.env` file to set `TEST_DB_DSN`, `TEST_DB_USER` and `TEST_DB_PASSWORD` params
1414
4. Setup application:
1515
```
16-
docker-compose exec app php tests/codeception/bin/yii app/setup --interactive=0
16+
docker-compose exec app php tests/bin/yii app/setup --interactive=0
1717
```
18-
5. Truncate tables before run, so we have fresh database without records.
19-
```
20-
docker-compose exec app php tests/codeception/bin/yii app/truncate
21-
```
22-
6. Start web server (do not close bash session):
18+
5. Start web server for acceptance tests (do not close bash session):
2319
```
2420
docker-compose exec app php -S localhost:8080
2521
```
26-
7. Run tests in separate window:
22+
6. Run tests in separate window:
2723
```
2824
docker-compose exec app vendor/bin/codecept run
2925
```

frontend/config/assets/.gitignore

-1
This file was deleted.

0 commit comments

Comments
 (0)