You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

233 lines
7.2 KiB

8 months ago
  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. Yii 2 Basic Project Template is a skeleton [Yii 2](https://www.yiiframework.com/) application best for
  9. rapidly creating small projects.
  10. The template contains the basic features including user login/logout and a contact page.
  11. It includes all commonly used configurations that would allow you to focus on adding new
  12. features to your application.
  13. [![Latest Stable Version](https://img.shields.io/packagist/v/yiisoft/yii2-app-basic.svg)](https://packagist.org/packages/yiisoft/yii2-app-basic)
  14. [![Total Downloads](https://img.shields.io/packagist/dt/yiisoft/yii2-app-basic.svg)](https://packagist.org/packages/yiisoft/yii2-app-basic)
  15. [![build](https://github.com/yiisoft/yii2-app-basic/workflows/build/badge.svg)](https://github.com/yiisoft/yii2-app-basic/actions?query=workflow%3Abuild)
  16. DIRECTORY STRUCTURE
  17. -------------------
  18. assets/ contains assets definition
  19. commands/ contains console commands (controllers)
  20. config/ contains application configurations
  21. controllers/ contains Web controller classes
  22. mail/ contains view files for e-mails
  23. models/ contains model classes
  24. runtime/ contains files generated during runtime
  25. tests/ contains various tests for the basic application
  26. vendor/ contains dependent 3rd-party packages
  27. views/ contains view files for the Web application
  28. web/ contains the entry script and Web resources
  29. REQUIREMENTS
  30. ------------
  31. The minimum requirement by this project template that your Web server supports PHP 7.4.
  32. INSTALLATION
  33. ------------
  34. ### Install via Composer
  35. If you do not have [Composer](https://getcomposer.org/), you may install it by following the instructions
  36. at [getcomposer.org](https://getcomposer.org/doc/00-intro.md#installation-nix).
  37. You can then install this project template using the following command:
  38. ~~~
  39. composer create-project --prefer-dist yiisoft/yii2-app-basic basic
  40. ~~~
  41. Now you should be able to access the application through the following URL, assuming `basic` is the directory
  42. directly under the Web root.
  43. ~~~
  44. http://localhost/basic/web/
  45. ~~~
  46. ### Install from an Archive File
  47. Extract the archive file downloaded from [yiiframework.com](https://www.yiiframework.com/download/) to
  48. a directory named `basic` that is directly under the Web root.
  49. Set cookie validation key in `config/web.php` file to some random secret string:
  50. ```php
  51. 'request' => [
  52. // !!! insert a secret key in the following (if it is empty) - this is required by cookie validation
  53. 'cookieValidationKey' => '<secret random string goes here>',
  54. ],
  55. ```
  56. You can then access the application through the following URL:
  57. ~~~
  58. http://localhost/basic/web/
  59. ~~~
  60. ### Install with Docker
  61. Update your vendor packages
  62. docker-compose run --rm php composer update --prefer-dist
  63. Run the installation triggers (creating cookie validation code)
  64. docker-compose run --rm php composer install
  65. Start the container
  66. docker-compose up -d
  67. You can then access the application through the following URL:
  68. http://127.0.0.1:8000
  69. **NOTES:**
  70. - Minimum required Docker engine version `17.04` for development (see [Performance tuning for volume mounts](https://docs.docker.com/docker-for-mac/osxfs-caching/))
  71. - The default configuration uses a host-volume in your home directory `.docker-composer` for composer caches
  72. CONFIGURATION
  73. -------------
  74. ### Database
  75. Edit the file `config/db.php` with real data, for example:
  76. ```php
  77. return [
  78. 'class' => 'yii\db\Connection',
  79. 'dsn' => 'mysql:host=localhost;dbname=yii2basic',
  80. 'username' => 'root',
  81. 'password' => '1234',
  82. 'charset' => 'utf8',
  83. ];
  84. ```
  85. **NOTES:**
  86. - Yii won't create the database for you, this has to be done manually before you can access it.
  87. - Check and edit the other files in the `config/` directory to customize your application as required.
  88. - Refer to the README in the `tests` directory for information specific to basic application tests.
  89. TESTING
  90. -------
  91. Tests are located in `tests` directory. They are developed with [Codeception PHP Testing Framework](https://codeception.com/).
  92. By default, there are 3 test suites:
  93. - `unit`
  94. - `functional`
  95. - `acceptance`
  96. Tests can be executed by running
  97. ```
  98. vendor/bin/codecept run
  99. ```
  100. The command above will execute unit and functional tests. Unit tests are testing the system components, while functional
  101. tests are for testing user interaction. Acceptance tests are disabled by default as they require additional setup since
  102. they perform testing in real browser.
  103. ### Running acceptance tests
  104. To execute acceptance tests do the following:
  105. 1. Rename `tests/acceptance.suite.yml.example` to `tests/acceptance.suite.yml` to enable suite configuration
  106. 2. Replace `codeception/base` package in `composer.json` with `codeception/codeception` to install full-featured
  107. version of Codeception
  108. 3. Update dependencies with Composer
  109. ```
  110. composer update
  111. ```
  112. 4. Download [Selenium Server](https://www.seleniumhq.org/download/) and launch it:
  113. ```
  114. java -jar ~/selenium-server-standalone-x.xx.x.jar
  115. ```
  116. 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:
  117. ```
  118. # for Firefox
  119. java -jar -Dwebdriver.gecko.driver=~/geckodriver ~/selenium-server-standalone-3.xx.x.jar
  120. # for Google Chrome
  121. java -jar -Dwebdriver.chrome.driver=~/chromedriver ~/selenium-server-standalone-3.xx.x.jar
  122. ```
  123. As an alternative way you can use already configured Docker container with older versions of Selenium and Firefox:
  124. ```
  125. docker run --net=host selenium/standalone-firefox:2.53.0
  126. ```
  127. 5. (Optional) Create `yii2basic_test` database and update it by applying migrations if you have them.
  128. ```
  129. tests/bin/yii migrate
  130. ```
  131. The database configuration can be found at `config/test_db.php`.
  132. 6. Start web server:
  133. ```
  134. tests/bin/yii serve
  135. ```
  136. 7. Now you can run all available tests
  137. ```
  138. # run all available tests
  139. vendor/bin/codecept run
  140. # run acceptance tests
  141. vendor/bin/codecept run acceptance
  142. # run only unit and functional tests
  143. vendor/bin/codecept run unit,functional
  144. ```
  145. ### Code coverage support
  146. By default, code coverage is disabled in `codeception.yml` configuration file, you should uncomment needed rows to be able
  147. to collect code coverage. You can run your tests and collect coverage with the following command:
  148. ```
  149. #collect coverage for all tests
  150. vendor/bin/codecept run --coverage --coverage-html --coverage-xml
  151. #collect coverage only for unit tests
  152. vendor/bin/codecept run unit --coverage --coverage-html --coverage-xml
  153. #collect coverage for unit and functional tests
  154. vendor/bin/codecept run functional,unit --coverage --coverage-html --coverage-xml
  155. ```
  156. You can see code coverage output under the `tests/_output` directory.