Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 3 additions & 5 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ php:
- 5.5
- 5.6
- 7.0
- 7.1
# - hhvm

# faster builds on new travis setup not using sudo
Expand All @@ -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
vendor/bin/codecept run
61 changes: 38 additions & 23 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
~~~
Expand All @@ -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' => [
Expand All @@ -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 [
Expand All @@ -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.



Expand All @@ -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
```

Expand All @@ -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

Expand All @@ -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
```

Expand Down
20 changes: 19 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
},
Expand All @@ -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"
]
Expand All @@ -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": {
Expand Down
1 change: 1 addition & 0 deletions config/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/*-local.php
2 changes: 1 addition & 1 deletion config/console.php
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?php

$params = require(__DIR__ . '/params.php');
$db = require(__DIR__ . '/db.php');
$db = require(__DIR__ . '/db-local.php');

$config = [
'id' => 'basic-console',
Expand Down
7 changes: 7 additions & 0 deletions config/templates/console-local.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<?php

/**
* Configuration adjustments for local installation of console application.
*/
return [
];
3 changes: 3 additions & 0 deletions config/db.php → config/templates/db-local.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
<?php

/**
* Database connection credentials for local installation.
*/
return [
'class' => 'yii\db\Connection',
'dsn' => 'mysql:host=localhost;dbname=yii2basic',
Expand Down
7 changes: 7 additions & 0 deletions config/templates/test-local.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<?php

/**
* Configuration adjustments for local test environment.
*/
return [
];
13 changes: 13 additions & 0 deletions config/templates/testdb-local.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?php

/**
* Database connection credentials for tests on a local installation.
*/
return [
'class' => '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',
];
13 changes: 13 additions & 0 deletions config/templates/web-local.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?php

/**
* Configuration adjustments for local installation of web application.
*/
return [
'components' => [
'request' => [
// !!! insert a secret key in the following (if it is empty) - this is required by cookie validation
'cookieValidationKey' => '',
],
],
];
12 changes: 7 additions & 5 deletions config/test.php
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
<?php
$params = require(__DIR__ . '/params.php');
$dbParams = require(__DIR__ . '/test_db.php');
$dbParams = require(__DIR__ . '/testdb-local.php');

/**
* Application configuration shared by all test types
*/
return [
$config = [
'id' => 'basic-tests',
'basePath' => dirname(__DIR__),
'basePath' => dirname(__DIR__),
'language' => 'en-US',
'components' => [
'db' => $dbParams,
Expand All @@ -22,7 +22,7 @@
],
'user' => [
'identityClass' => 'app\models\User',
],
],
'request' => [
'cookieValidationKey' => 'test',
'enableCsrfValidation' => false,
Expand All @@ -32,7 +32,9 @@
'domain' => 'localhost',
],
*/
],
],
],
'params' => $params,
];

return yii\helpers\ArrayHelper::merge($config, require(__DIR__ . '/test-local.php'));
6 changes: 0 additions & 6 deletions config/test_db.php

This file was deleted.

6 changes: 1 addition & 5 deletions config/web.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,6 @@
'basePath' => 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',
],
Expand All @@ -37,7 +33,7 @@
],
],
],
'db' => require(__DIR__ . '/db.php'),
'db' => require(__DIR__ . '/db-local.php'),
/*
'urlManager' => [
'enablePrettyUrl' => true,
Expand Down
3 changes: 2 additions & 1 deletion tests/bin/yii
Original file line number Diff line number Diff line change
Expand Up @@ -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')
]
]
);
Expand Down
5 changes: 4 additions & 1 deletion web/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();
5 changes: 4 additions & 1 deletion yii
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down