OSDN Git Service

Initial commit
[invent/invent.git] / README.md
1 <p align="center">
2     <a href="https://github.com/yiisoft" target="_blank">
3         <img src="https://avatars0.githubusercontent.com/u/993323" height="100px">
4     </a>
5     <h1 align="center">Yii 2 Basic Project Template</h1>
6     <br>
7 </p>
8
9 Yii 2 Basic Project Template is a skeleton [Yii 2](http://www.yiiframework.com/) application best for
10 rapidly creating small projects.
11
12 The template contains the basic features including user login/logout and a contact page.
13 It includes all commonly used configurations that would allow you to focus on adding new
14 features to your application.
15
16 [![Latest Stable Version](https://img.shields.io/packagist/v/yiisoft/yii2-app-basic.svg)](https://packagist.org/packages/yiisoft/yii2-app-basic)
17 [![Total Downloads](https://img.shields.io/packagist/dt/yiisoft/yii2-app-basic.svg)](https://packagist.org/packages/yiisoft/yii2-app-basic)
18 [![Build Status](https://travis-ci.com/yiisoft/yii2-app-basic.svg?branch=master)](https://travis-ci.com/yiisoft/yii2-app-basic)
19
20 DIRECTORY STRUCTURE
21 -------------------
22
23       assets/             contains assets definition
24       commands/           contains console commands (controllers)
25       config/             contains application configurations
26       controllers/        contains Web controller classes
27       mail/               contains view files for e-mails
28       models/             contains model classes
29       runtime/            contains files generated during runtime
30       tests/              contains various tests for the basic application
31       vendor/             contains dependent 3rd-party packages
32       views/              contains view files for the Web application
33       web/                contains the entry script and Web resources
34
35
36
37 REQUIREMENTS
38 ------------
39
40 The minimum requirement by this project template that your Web server supports PHP 5.6.0.
41
42
43 INSTALLATION
44 ------------
45
46 ### Install via Composer
47
48 If you do not have [Composer](http://getcomposer.org/), you may install it by following the instructions
49 at [getcomposer.org](http://getcomposer.org/doc/00-intro.md#installation-nix).
50
51 You can then install this project template using the following command:
52
53 ~~~
54 composer create-project --prefer-dist yiisoft/yii2-app-basic basic
55 ~~~
56
57 Now you should be able to access the application through the following URL, assuming `basic` is the directory
58 directly under the Web root.
59
60 ~~~
61 http://localhost/basic/web/
62 ~~~
63
64 ### Install from an Archive File
65
66 Extract the archive file downloaded from [yiiframework.com](http://www.yiiframework.com/download/) to
67 a directory named `basic` that is directly under the Web root.
68
69 Set cookie validation key in `config/web.php` file to some random secret string:
70
71 ```php
72 'request' => [
73     // !!! insert a secret key in the following (if it is empty) - this is required by cookie validation
74     'cookieValidationKey' => '<secret random string goes here>',
75 ],
76 ```
77
78 You can then access the application through the following URL:
79
80 ~~~
81 http://localhost/basic/web/
82 ~~~
83
84
85 ### Install with Docker
86
87 Update your vendor packages
88
89     docker-compose run --rm php composer update --prefer-dist
90     
91 Run the installation triggers (creating cookie validation code)
92
93     docker-compose run --rm php composer install    
94     
95 Start the container
96
97     docker-compose up -d
98     
99 You can then access the application through the following URL:
100
101     http://127.0.0.1:8000
102
103 **NOTES:** 
104 - Minimum required Docker engine version `17.04` for development (see [Performance tuning for volume mounts](https://docs.docker.com/docker-for-mac/osxfs-caching/))
105 - The default configuration uses a host-volume in your home directory `.docker-composer` for composer caches
106
107
108 CONFIGURATION
109 -------------
110
111 ### Database
112
113 Edit the file `config/db.php` with real data, for example:
114
115 ```php
116 return [
117     'class' => 'yii\db\Connection',
118     'dsn' => 'mysql:host=localhost;dbname=yii2basic',
119     'username' => 'root',
120     'password' => '1234',
121     'charset' => 'utf8',
122 ];
123 ```
124
125 **NOTES:**
126 - Yii won't create the database for you, this has to be done manually before you can access it.
127 - Check and edit the other files in the `config/` directory to customize your application as required.
128 - Refer to the README in the `tests` directory for information specific to basic application tests.
129
130
131 TESTING
132 -------
133
134 Tests are located in `tests` directory. They are developed with [Codeception PHP Testing Framework](http://codeception.com/).
135 By default there are 3 test suites:
136
137 - `unit`
138 - `functional`
139 - `acceptance`
140
141 Tests can be executed by running
142
143 ```
144 vendor/bin/codecept run
145 ```
146
147 The command above will execute unit and functional tests. Unit tests are testing the system components, while functional
148 tests are for testing user interaction. Acceptance tests are disabled by default as they require additional setup since
149 they perform testing in real browser. 
150
151
152 ### Running  acceptance tests
153
154 To execute acceptance tests do the following:  
155
156 1. Rename `tests/acceptance.suite.yml.example` to `tests/acceptance.suite.yml` to enable suite configuration
157
158 2. Replace `codeception/base` package in `composer.json` with `codeception/codeception` to install full featured
159    version of Codeception
160
161 3. Update dependencies with Composer 
162
163     ```
164     composer update  
165     ```
166
167 4. Download [Selenium Server](http://www.seleniumhq.org/download/) and launch it:
168
169     ```
170     java -jar ~/selenium-server-standalone-x.xx.x.jar
171     ```
172
173     In case of using Selenium Server 3.0 with Firefox browser since v48 or Google Chrome since v53 you must download [GeckoDriver](https://github.com/mozilla/geckodriver/releases) or [ChromeDriver](https://sites.google.com/a/chromium.org/chromedriver/downloads) and launch Selenium with it:
174
175     ```
176     # for Firefox
177     java -jar -Dwebdriver.gecko.driver=~/geckodriver ~/selenium-server-standalone-3.xx.x.jar
178     
179     # for Google Chrome
180     java -jar -Dwebdriver.chrome.driver=~/chromedriver ~/selenium-server-standalone-3.xx.x.jar
181     ``` 
182     
183     As an alternative way you can use already configured Docker container with older versions of Selenium and Firefox:
184     
185     ```
186     docker run --net=host selenium/standalone-firefox:2.53.0
187     ```
188
189 5. (Optional) Create `yii2_basic_tests` database and update it by applying migrations if you have them.
190
191    ```
192    tests/bin/yii migrate
193    ```
194
195    The database configuration can be found at `config/test_db.php`.
196
197
198 6. Start web server:
199
200     ```
201     tests/bin/yii serve
202     ```
203
204 7. Now you can run all available tests
205
206    ```
207    # run all available tests
208    vendor/bin/codecept run
209
210    # run acceptance tests
211    vendor/bin/codecept run acceptance
212
213    # run only unit and functional tests
214    vendor/bin/codecept run unit,functional
215    ```
216
217 ### Code coverage support
218
219 By default, code coverage is disabled in `codeception.yml` configuration file, you should uncomment needed rows to be able
220 to collect code coverage. You can run your tests and collect coverage with the following command:
221
222 ```
223 #collect coverage for all tests
224 vendor/bin/codecept run -- --coverage-html --coverage-xml
225
226 #collect coverage only for unit tests
227 vendor/bin/codecept run unit -- --coverage-html --coverage-xml
228
229 #collect coverage for unit and functional tests
230 vendor/bin/codecept run functional,unit -- --coverage-html --coverage-xml
231 ```
232
233 You can see code coverage output under the `tests/_output` directory.