strongsquirrel / yii2-dotenv-app
Yii 2 基础项目模板
Requires
- php: >=5.4.0
- yiisoft/yii2: ~2.0.5
- yiisoft/yii2-bootstrap: ~2.0.0
- yiisoft/yii2-swiftmailer: ~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-14 19:31:09 UTC
README
Yii 2 基础项目模板
Yii 2 基础项目模板是一个框架,适合快速创建小型项目。
该模板包含基本功能,包括用户登录/登出和联系页面。它包含了所有常用配置,以便您能专注于添加新功能到您的应用中。
目录结构
assets/ contains assets definition
commands/ contains console commands (controllers)
config/ contains application configurations
controllers/ contains Web controller classes
helpers/ contains helper functions
mail/ contains view files for e-mails
models/ contains model classes
runtime/ contains files generated during runtime
tests/ contains various tests for the basic 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 global require "fxp/composer-asset-plugin:~1.4.2" $ git clone git@github.com:StrongSquirrel/yii2-dotenv-app.git project_name $ cd project_name $ php composer.phar install
配置
在.env文件中设置环境变量
$ cd project_name
$ cp .env.example .env
DB_DSN=mysql:host=localhost;dbname=yii2basic
DB_USERNAME=root
DB_PASSWORD=
YII_DEBUG=true
YII_ENV=prod
COOKIE_VALIDATION_KEY=
注意
- Yii不会为您创建数据库,您必须手动创建才能访问。
- 检查并编辑config目录中的其他文件以根据需要自定义您的应用程序。
- 有关基本应用程序测试的详细信息,请参阅tests目录中的README。
测试
测试位于tests目录中。它们是用Codeception PHP测试框架开发的。默认情况下,有3个测试套件
unit
functional
acceptance
可以通过运行以下命令执行测试
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
如果使用Selenium Server 3.0与Firefox浏览器从v48或Google Chrome从v53开始,您必须下载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目录下看到代码覆盖率输出。