nkostadinov / yii2-vue-basic
Yii 2 基础项目模板
Requires
- php: >=7.0.0
- nkostadinov/yii2-taxonomy: dev-master
- nkostadinov/yii2-user: dev-master
- vlucas/phpdotenv: ^4.1.4
- yiisoft/yii2: ~2.0.14
- 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
- dev-master
- dev-dependabot/npm_and_yarn/frontend/json5-and-json5-and-vue/cli-service-2.2.3
- dev-dependabot/npm_and_yarn/frontend/json5-and-vue/cli-plugin-babel-and-vue/cli-plugin-eslint-and-vue/cli-plugin-pwa-and-vue/cli-service-and-sass-loader-2.2.2
- dev-dependabot/npm_and_yarn/frontend/express-4.18.2
- dev-dependabot/npm_and_yarn/frontend/qs-6.5.3
- dev-dependabot/npm_and_yarn/frontend/decode-uri-component-0.2.2
- dev-dependabot/npm_and_yarn/frontend/shell-quote-1.7.3
- dev-dependabot/npm_and_yarn/frontend/eventsource-1.1.1
- dev-dependabot/npm_and_yarn/frontend/async-2.6.4
- dev-dependabot/composer/guzzlehttp/psr7-1.8.5
- dev-dependabot/npm_and_yarn/frontend/url-parse-1.5.10
- dev-dependabot/npm_and_yarn/frontend/node-sass-7.0.0
- dev-dependabot/npm_and_yarn/frontend/path-parse-1.0.7
- dev-dependabot/npm_and_yarn/frontend/postcss-7.0.36
- dev-dependabot/npm_and_yarn/frontend/dns-packet-1.3.4
- dev-dependabot/npm_and_yarn/frontend/hosted-git-info-2.8.9
- dev-dependabot/npm_and_yarn/frontend/lodash-4.17.21
- dev-dependabot/npm_and_yarn/frontend/ssri-6.0.2
- dev-dependabot/npm_and_yarn/frontend/y18n-3.2.2
- dev-dependabot/npm_and_yarn/frontend/elliptic-6.5.4
- dev-dependabot/npm_and_yarn/frontend/axios-0.21.1
- dev-dependabot/npm_and_yarn/frontend/http-proxy-1.18.1
- dev-dependabot/npm_and_yarn/frontend/websocket-extensions-0.1.4
This package is auto-updated.
Last update: 2024-09-04 14:34:20 UTC
README
Yii 2 基础项目模板
Yii 2 Basic Project Template 是一个骨架 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 5.4.0。
安装
通过 Composer 安装
如果您没有 Composer,您可以按照 getcomposer.org 上的说明进行安装。
然后,您可以使用以下命令安装此项目模板
php composer.phar create-project --prefer-dist --stability=dev nkostadinov/yii2-vue-basic basic
现在您应该可以通过以下 URL 访问应用程序,假设 basic 是 Web 根目录下的目录。
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 个测试套件
单元测试功能测试验收测试
可以通过运行以下命令执行测试
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作为另一种方式,您可以使用已配置的 Docker 容器,其中包含较旧版本的 Selenium 和 Firefox
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 目录下看到代码覆盖率输出。