diff --git a/.travis.yml b/.travis.yml index e7e847ee5..e7da93c1d 100644 --- a/.travis.yml +++ b/.travis.yml @@ -5,6 +5,7 @@ php: - 5.5 - 5.6 - 7.0 + - 7.1 # - hhvm # faster builds on new travis setup not using sudo @@ -17,13 +18,10 @@ cache: install: - travis_retry composer self-update && composer --version - - travis_retry composer global require "fxp/composer-asset-plugin:~1.1.1" + - travis_retry composer global require "fxp/composer-asset-plugin:^1.2.0" - travis_retry composer update --dev --prefer-dist --no-interaction -# setup application: - - | - sed -i "s/'cookieValidationKey' => ''/'cookieValidationKey' => 'testkey'/" config/web.php script: - | php -S localhost:8080 -t web > /dev/null 2>&1 & - vendor/bin/codecept run \ No newline at end of file + vendor/bin/codecept run diff --git a/README.md b/README.md index 3bc44a785..bf66dabf0 100644 --- a/README.md +++ b/README.md @@ -45,7 +45,7 @@ at [getcomposer.org](http://getcomposer.org/doc/00-intro.md#installation-nix). You can then install this project template using the following command: -~~~ +~~~shell php composer.phar global require "fxp/composer-asset-plugin:^1.2.0" php composer.phar create-project --prefer-dist --stability=dev yiisoft/yii2-app-basic basic ~~~ @@ -63,7 +63,7 @@ http://localhost/basic/web/ Extract the archive file downloaded from [yiiframework.com](http://www.yiiframework.com/download/) to a directory named `basic` that is directly under the Web root. -Set cookie validation key in `config/web.php` file to some random secret string: +Set cookie validation key in `config/web-local.php` file to some random secret string: ```php 'request' => [ @@ -82,9 +82,27 @@ http://localhost/basic/web/ CONFIGURATION ------------- +### Local config files + +Usually each application has some configuration that should not be shared between different installations +and should not be stored in [version control system](https://en.wikipedia.org/wiki/Version_control), for +example personal keys or configuration specific for a particular server. In `config` directory you can find +a set of config files prefixed by `-local.php` - these files are designed for storing such a configuration. +These local configs are added to `.gitignore` and never will be pushed to source code repository, so you can safely +use it for override some general config. For example `config/web-local.php` will override some settings +from `config/web.php` (see [ArrayHelper::merge()](http://www.yiiframework.com/doc-2.0/guide-helper-array.html#merging-arrays) +for more details). Then `config/web.php` contains general configuration of web application shared with +all installations and `config/web-local.php` contains configuration specific only for local installation. + +In `config/templates` directory you can find templates for local config files. On first run `composer install` +these files will be copied to `config` directory. You can edit these templates to adjust default content of +local config files, but **you should not store any private data in templates** - these should be put into +`config/*-local.php` files after installation. + + ### Database -Edit the file `config/db.php` with real data, for example: +Edit the file `config/db-local.php` with real data, for example: ```php return [ @@ -96,10 +114,7 @@ return [ ]; ``` -**NOTES:** -- Yii won't create the database for you, this has to be done manually before you can access it. -- Check and edit the other files in the `config/` directory to customize your application as required. -- Refer to the README in the `tests` directory for information specific to basic application tests. +Yii won't create the database for you, this has to be done manually before you can access it. @@ -115,33 +130,33 @@ By default there are 3 test suites: Tests can be executed by running -``` +```shell vendor/bin/codecept run -``` +``` The command above will execute unit and functional tests. Unit tests are testing the system components, while functional tests are for testing user interaction. Acceptance tests are disabled by default as they require additional setup since -they perform testing in real browser. +they perform testing in real browser. ### Running acceptance tests -To execute acceptance tests do the following: +To execute acceptance tests do the following: 1. Rename `tests/acceptance.suite.yml.example` to `tests/acceptance.suite.yml` to enable suite configuration 2. Replace `codeception/base` package in `composer.json` with `codeception/codeception` to install full featured version of Codeception -3. Update dependencies with Composer +3. Update dependencies with Composer - ``` - composer update + ```shell + composer update ``` 4. Download [Selenium Server](http://www.seleniumhq.org/download/) and launch it: - ``` + ```shell java -jar ~/selenium-server-standalone-x.xx.x.jar ``` @@ -163,22 +178,22 @@ To execute acceptance tests do the following: 5. (Optional) Create `yii2_basic_tests` database and update it by applying migrations if you have them. - ``` + ```shell tests/bin/yii migrate ``` - The database configuration can be found at `config/test_db.php`. + The database configuration can be found at `config/testdb-local.php`. 6. Start web server: - ``` + ```shell tests/bin/yii serve ``` 7. Now you can run all available tests - ``` + ```shell # run all available tests vendor/bin/codecept run @@ -194,14 +209,14 @@ To execute acceptance tests do the following: By default, code coverage is disabled in `codeception.yml` configuration file, you should uncomment needed rows to be able to collect code coverage. You can run your tests and collect coverage with the following command: -``` -#collect coverage for all tests +```shell +# collect coverage for all tests vendor/bin/codecept run -- --coverage-html --coverage-xml -#collect coverage only for unit tests +# collect coverage only for unit tests vendor/bin/codecept run unit -- --coverage-html --coverage-xml -#collect coverage for unit and functional tests +# collect coverage for unit and functional tests vendor/bin/codecept run functional,unit -- --coverage-html --coverage-xml ``` diff --git a/composer.json b/composer.json index e31abe055..107e811ef 100644 --- a/composer.json +++ b/composer.json @@ -16,6 +16,7 @@ "require": { "php": ">=5.4.0", "yiisoft/yii2": "~2.0.5", + "yiisoft/yii2-composer": "~2.0.5", "yiisoft/yii2-bootstrap": "~2.0.0", "yiisoft/yii2-swiftmailer": "~2.0.0" }, @@ -32,6 +33,12 @@ "process-timeout": 1800 }, "scripts": { + "post-install-cmd": [ + "yii\\composer\\Installer::postInstall" + ], + "post-update-cmd": [ + "yii\\composer\\Installer::postInstall" + ], "post-create-project-cmd": [ "yii\\composer\\Installer::postCreateProject" ] @@ -44,9 +51,20 @@ "web/assets": "0777", "yii": "0755" } + ] + }, + "yii\\composer\\Installer::postInstall": { + "copyFiles": [ + { + "config/templates/console-local.php": "config/console-local.php", + "config/templates/web-local.php": "config/web-local.php", + "config/templates/db-local.php": "config/db-local.php", + "config/templates/testdb-local.php": "config/testdb-local.php", + "config/templates/test-local.php": "config/test-local.php" + } ], "generateCookieValidationKey": [ - "config/web.php" + "config/web-local.php" ] }, "asset-installer-paths": { diff --git a/config/.gitignore b/config/.gitignore new file mode 100644 index 000000000..34c7d59a1 --- /dev/null +++ b/config/.gitignore @@ -0,0 +1 @@ +/*-local.php diff --git a/config/console.php b/config/console.php index 3945d9eb2..ea7729c94 100644 --- a/config/console.php +++ b/config/console.php @@ -1,7 +1,7 @@ 'basic-console', diff --git a/config/templates/console-local.php b/config/templates/console-local.php new file mode 100644 index 000000000..1c56d8ad9 --- /dev/null +++ b/config/templates/console-local.php @@ -0,0 +1,7 @@ + 'yii\db\Connection', 'dsn' => 'mysql:host=localhost;dbname=yii2basic', diff --git a/config/templates/test-local.php b/config/templates/test-local.php new file mode 100644 index 000000000..6b95795ca --- /dev/null +++ b/config/templates/test-local.php @@ -0,0 +1,7 @@ + 'yii\db\Connection', + // test database! Important not to run tests on production or development databases + 'dsn' => 'mysql:host=localhost;dbname=yii2_basic_tests', + 'username' => 'root', + 'password' => '', + 'charset' => 'utf8', +]; diff --git a/config/templates/web-local.php b/config/templates/web-local.php new file mode 100644 index 000000000..31cf38950 --- /dev/null +++ b/config/templates/web-local.php @@ -0,0 +1,13 @@ + [ + 'request' => [ + // !!! insert a secret key in the following (if it is empty) - this is required by cookie validation + 'cookieValidationKey' => '', + ], + ], +]; diff --git a/config/test.php b/config/test.php index a92c2fcde..9ff3d897e 100644 --- a/config/test.php +++ b/config/test.php @@ -1,13 +1,13 @@ 'basic-tests', - 'basePath' => dirname(__DIR__), + 'basePath' => dirname(__DIR__), 'language' => 'en-US', 'components' => [ 'db' => $dbParams, @@ -22,7 +22,7 @@ ], 'user' => [ 'identityClass' => 'app\models\User', - ], + ], 'request' => [ 'cookieValidationKey' => 'test', 'enableCsrfValidation' => false, @@ -32,7 +32,9 @@ 'domain' => 'localhost', ], */ - ], + ], ], 'params' => $params, ]; + +return yii\helpers\ArrayHelper::merge($config, require(__DIR__ . '/test-local.php')); diff --git a/config/test_db.php b/config/test_db.php deleted file mode 100644 index c951052e3..000000000 --- a/config/test_db.php +++ /dev/null @@ -1,6 +0,0 @@ - dirname(__DIR__), 'bootstrap' => ['log'], 'components' => [ - 'request' => [ - // !!! insert a secret key in the following (if it is empty) - this is required by cookie validation - 'cookieValidationKey' => '', - ], 'cache' => [ 'class' => 'yii\caching\FileCache', ], @@ -37,7 +33,7 @@ ], ], ], - 'db' => require(__DIR__ . '/db.php'), + 'db' => require(__DIR__ . '/db-local.php'), /* 'urlManager' => [ 'enablePrettyUrl' => true, diff --git a/tests/bin/yii b/tests/bin/yii index 1e4f2cc1d..d2b2ea12b 100755 --- a/tests/bin/yii +++ b/tests/bin/yii @@ -16,9 +16,10 @@ require(__DIR__ . '/../../vendor/yiisoft/yii2/Yii.php'); $config = yii\helpers\ArrayHelper::merge( require(__DIR__ . '/../../config/console.php'), + require(__DIR__ . '/../../config/console-local.php'), [ 'components' => [ - 'db' => require(__DIR__ . '/../../config/test_db.php') + 'db' => require(__DIR__ . '/../../config/testdb-local.php') ] ] ); diff --git a/web/index.php b/web/index.php index d1e070a39..c0988ed17 100644 --- a/web/index.php +++ b/web/index.php @@ -7,6 +7,9 @@ require(__DIR__ . '/../vendor/autoload.php'); require(__DIR__ . '/../vendor/yiisoft/yii2/Yii.php'); -$config = require(__DIR__ . '/../config/web.php'); +$config = yii\helpers\ArrayHelper::merge( + require(__DIR__ . '/../config/web.php'), + require(__DIR__ . '/../config/web-local.php') +); (new yii\web\Application($config))->run(); diff --git a/yii b/yii index fc7090f77..e509646b7 100755 --- a/yii +++ b/yii @@ -14,7 +14,10 @@ defined('YII_ENV') or define('YII_ENV', 'dev'); require(__DIR__ . '/vendor/autoload.php'); require(__DIR__ . '/vendor/yiisoft/yii2/Yii.php'); -$config = require(__DIR__ . '/config/console.php'); +$config = yii\helpers\ArrayHelper::merge( + require(__DIR__ . '/config/console.php'), + require(__DIR__ . '/config/console-local.php') +); $application = new yii\console\Application($config); $exitCode = $application->run();