tbqapp / yii2basic
Yii 2 Basic 项目模板
Requires
- php: >=7.4.0
- yiisoft/yii2: ~2.0.45
- yiisoft/yii2-bootstrap5: ~2.0.2
- yiisoft/yii2-symfonymailer: ~2.0.3
Requires (Dev)
- codeception/codeception: ^5.0.0 || ^4.0
- codeception/lib-innerbrowser: ^4.0 || ^3.0 || ^1.1
- codeception/module-asserts: ^3.0 || ^1.1
- codeception/module-filesystem: ^3.0 || ^2.0 || ^1.1
- codeception/module-yii2: ^1.1
- codeception/verify: ^3.0 || ^2.2
- symfony/browser-kit: ^6.0 || >=2.7 <=4.2.4
- yiisoft/yii2-debug: ~2.1.0
- yiisoft/yii2-faker: ~2.0.0
- yiisoft/yii2-gii: ~2.2.0
- dev-master
- 2.0.50
- 2.0.49
- 2.0.48
- 2.0.47
- 2.0.46
- 2.0.45
- 2.0.44
- 2.0.43
- 2.0.42
- 2.0.41
- 2.0.40
- 2.0.39
- 2.0.38
- 2.0.37
- 2.0.36
- 2.0.35
- 2.0.34
- 2.0.33
- 2.0.32
- 2.0.31
- 2.0.26
- 2.0.22
- 2.0.19
- 2.0.18
- 2.0.17
- 2.0.16
- 2.0.14
- 2.0.13
- 2.0.12
- 2.0.11
- 2.0.10
- 2.0.9
- 2.0.8
- 2.0.7
- 2.0.6
- 2.0.4
- 2.0.3
- 2.0.2
- 2.0.1
- 2.0.0
- 2.0.0-rc
- 2.0.0-beta
- 2.0.0-alpha
- dev-tbq-2.0.41-admin
- dev-tbq-2.0.49
- dev-tbq-2.0.49-user
This package is not auto-updated.
Last update: 2024-10-03 00:37:01 UTC
README
Yii 2 Basic 项目模板
Yii 2 Basic 项目模板是一个适用于快速创建小型项目的 Yii 2 应用程序框架。
该模板包含基本功能,包括用户登录/注销和联系页面。它包含了所有常用的配置,以便您可以专注于添加新功能到您的应用程序中。
目录结构
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 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 7.4。
安装
通过 Composer 安装
如果您没有 Composer,您可以按照 getcomposer.org 上的说明进行安装。
然后,您可以使用以下命令安装此项目模板:
composer create-project --prefer-dist yiisoft/yii2-app-basic basic
现在,假设 basic
是 Web 根目录下的目录,您应该可以通过以下 URL 访问应用程序:
https:///basic/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/
使用 Docker 安装
更新您的供应商包
docker-compose run --rm php composer update --prefer-dist
运行安装触发器(创建 cookie 验证代码)
docker-compose run --rm php composer install
启动容器
docker-compose up -d
然后,您可以通过以下 URL 访问应用程序:
http://127.0.0.1:8000
注意
- 最低要求 Docker 引擎版本
17.04
用于开发(请参阅 卷挂载性能调整) - 默认配置使用您主目录中的主机卷
.docker-composer
作为 composer 缓存
配置
数据库
使用真实数据编辑 config/db.php
文件,例如
return [
'class' => 'yii\db\Connection',
'dsn' => 'mysql:host=localhost;dbname=yii2basic',
'username' => 'root',
'password' => '1234',
'charset' => 'utf8',
];
注意
- 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
(可选) 创建
yii2basic_test
数据库,并应用迁移更新它(如果有的话)。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 --coverage-html --coverage-xml
#collect coverage only for unit tests
vendor/bin/codecept run unit --coverage --coverage-html --coverage-xml
#collect coverage for unit and functional tests
vendor/bin/codecept run functional,unit --coverage --coverage-html --coverage-xml
您可以在tests/_output
目录下看到代码覆盖率输出。