robote13 / yii2-webapp-basic
Requires
- php: >=5.4.0
- dektrium/yii2-rbac: ^1.0.0
- dektrium/yii2-user: ^0.9.12
- robote13/yii2-seotags-manager: dev-master
- yiisoft/yii2: ~2.0.14@stable
- yiisoft/yii2-bootstrap: ~2.1
- yiisoft/yii2-swiftmailer: ~2.0.0
Requires (Dev)
- codeception/base: ^2.2.3
- codeception/specify: ~0.4.3
- codeception/verify: ~0.3.1
- robote13/yii2-advanced-gii: dev-master
- yiisoft/yii2-debug: ~2.0.0
- yiisoft/yii2-faker: ~2.0.0
- yiisoft/yii2-gii: ~2.0.0
This package is auto-updated.
Last update: 2020-08-14 10:20:59 UTC
README
Yii 2 基础项目模板是一个适用于快速创建小型项目的Yii 2应用程序骨架。
该模板包含基本功能,包括用户登录/注销和联系页面。它包含所有常用的配置,使您能够专注于添加应用程序的新功能。
目录结构
assets/ contains assets definition
commands/ contains console commands (controllers)
config/ contains application configurations
controllers/ contains Web controller classes
enviroments/
mail/ contains view files for e-mails
models/ contains model classes
node_modules/
runtime/ contains files generated during runtime
tests/ contains various tests for the basic application
themes/
vendor/ contains dependent 3rd-party packages
views/ contains view files for the Web application
web/ contains the entry script and Web resources
需求
本项目模板对Web服务器的最低要求是支持PHP 5.4.0。
安装
通过Composer安装
如果您没有Composer,可以按照getcomposer.org上的说明进行安装。
然后,您可以使用以下命令安装此项目模板
php composer.phar global require "fxp/composer-asset-plugin:^1.2.0"
php composer.phar create-project --prefer-dist --stability=dev robote13/yii2-webapp-basic webapp
现在,您应该可以通过以下URL访问应用程序,假设basic
是Web根目录下的直接目录。
https:///webapp/web/
从存档文件安装
将从yiiframework.com下载的存档文件提取到Web根目录下名为basic
的目录中。
在config/web.php
文件中将cookie验证密钥设置为某个随机字符串
'request' => [
// !!! insert a secret key in the following (if it is empty) - this is required by cookie validation
'cookieValidationKey' => '<secret random string goes here>',
],
然后,您可以通过以下URL访问应用程序
https:///basic/web/
配置
数据库
使用真实数据编辑文件config/db.php
,例如
return [
'class' => 'yii\db\Connection',
'dsn' => 'mysql:host=localhost;dbname=yii2basic',
'username' => 'root',
'password' => '1234',
'charset' => 'utf8',
];
注意
- Yii不会为您创建数据库,您必须手动创建它才能访问。
- 检查并编辑
config/
目录中的其他文件,以根据需要自定义应用程序。 - 有关基本应用程序测试的特定信息,请参阅
tests
目录中的README。
迁移
php yii migrate -p=@dektrium/user/migrations
php yii migrate -p=@yii/rbac/migrations
php yii migrate -p=@robote13/SEOTags/migrations
php yii migrate
测试
测试位于tests
目录中。它们使用Codeception PHP 测试框架开发。默认情况下,有3个测试套件
单元
功能
接受
可以通过运行以下命令执行测试
vendor/bin/codecept run
上面的命令将执行单元和功能测试。单元测试用于测试系统组件,而功能测试用于测试用户交互。默认情况下,接受测试是禁用的,因为它们需要额外的设置,因为它们在真实浏览器中执行测试。
运行接受测试
要执行接受测试,请执行以下操作
将
tests/acceptance.suite.yml.example
重命名为tests/acceptance.suite.yml
以启用套件配置将
composer.json
中的codeception/base
包替换为codeception/codeception
以安装完整的Codeception版本使用Composer更新依赖项
composer update
下载Selenium Server并启动它
java -jar ~/selenium-server-standalone-x.xx.x.jar
如果您正在使用从v48开始的Firefox浏览器或从v53开始的Google Chrome浏览器,并且使用Selenium Server 3.0,则必须下载GeckoDriver或ChromeDriver,并用它启动Selenium
# for Firefox java -jar -Dwebdriver.gecko.driver=~/geckodriver ~/selenium-server-standalone-3.xx.x.jar # for Google Chrome java -jar -Dwebdriver.chrome.driver=~/chromedriver ~/selenium-server-standalone-3.xx.x.jar
作为另一种方法,您可以使用已经配置好的包含较旧版本Selenium和Firefox的Docker容器
docker run --net=host selenium/standalone-firefox:2.53.0
(可选) 创建
yii2_basic_tests
数据库,并在有迁移的情况下更新它。tests/bin/yii migrate
数据库配置文件位于
config/test_db.php
。
启动 Web 服务器
tests/bin/yii serve
现在您可以运行所有可用的测试
# run all available tests vendor/bin/codecept run # run acceptance tests vendor/bin/codecept run acceptance # run only unit and functional tests vendor/bin/codecept run unit,functional
代码覆盖率支持
默认情况下,在 codeception.yml
配置文件中代码覆盖率是禁用的,您应该取消注释所需的行以能够收集代码覆盖率。您可以使用以下命令运行测试并收集覆盖率:
#collect coverage for all tests
vendor/bin/codecept run -- --coverage-html --coverage-xml
#collect coverage only for unit tests
vendor/bin/codecept run unit -- --coverage-html --coverage-xml
#collect coverage for unit and functional tests
vendor/bin/codecept run functional,unit -- --coverage-html --coverage-xml
您可以在 tests/_output
目录下查看代码覆盖率输出。