donpool / yii2-base
Yii 2 基础
Requires
- php: >=5.4.0
- yiisoft/yii2: ~2.0.5
- yiisoft/yii2-bootstrap: ~2.0.0
Requires (Dev)
- codeception/base: ^2.2.3
- codeception/specify: ~0.4.3
- codeception/verify: ~0.3.1
- yiisoft/yii2-debug: ~2.0.0
- yiisoft/yii2-faker: ~2.0.0
- yiisoft/yii2-gii: ~2.0.0
This package is not auto-updated.
Last update: 2024-09-29 02:27:23 UTC
README
Yii 2 Base 项目模板是一个最佳快速从头开始创建小型应用的框架。
模板包含基础功能,包括用户登录/注销和联系页面。它包含所有常用配置,让您能专注于添加应用的新功能。
目录结构
assets/ contains assets definition
commands/ contains console commands (controllers)
config/ contains application configurations
controllers/ contains Web controller classes
mail/ contains view files for e-mails
models/ contains model classes
runtime/ contains files generated during runtime
tests/ contains various tests for the base application
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 create-project --prefer-dist --stability=dev donpool/yii2-base base
现在您应该可以通过以下URL访问应用程序,假设base
是Web根目录下的直接目录。
https:///base/web/
从存档文件安装
将从paulbernal.com下载的存档文件提取到Web根目录下的名为base
的目录。
在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:///base/web/
配置
数据库
使用真实数据编辑config/db.php
文件,例如
return [ 'class' => 'yii\db\Connection', 'dsn' => 'mysql:host=localhost;dbname=yii2base', 'username' => 'root', 'password' => '1234', 'charset' => 'utf8', ];
备注
- Yii不会为您创建数据库,这必须在您能够访问它之前手动完成。
- 检查和编辑
config/
目录中的其他文件,以根据需要自定义您的应用程序。 - 有关基础应用程序测试的特定信息,请参阅
tests
目录中的README。
测试
测试位于tests
目录中。它们是用Codeception PHP 测试框架开发的。默认情况下,有三个测试套件
单元测试
功能测试
验收测试
可以通过运行以下命令执行测试:
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浏览器,您必须下载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_base_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
目录下查看代码覆盖率输出。