jimchen/yii2-app-basic

Yii 2 基础项目模板

资助包维护!
Open Collective
Tidelift

安装: 1

依赖: 0

建议: 0

安全性: 0

星标: 0

关注者: 1

分支: 788

类型:项目

2.0.38.1 2020-10-10 08:22 UTC

README

Yii 2 基础项目模板


Yii 2 基础项目模板是一个用于快速创建小型项目的骨架Yii 2应用程序。

该模板包含基本功能,包括用户登录/注销和联系页面。它包含所有常用配置,使您能够专注于添加新功能到您的应用程序。

Latest Stable Version Total Downloads ci-linux ci-windows

目录结构

  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.6.0。

安装

通过Composer安装

如果您没有Composer,您可以按照getcomposer.org上的说明进行安装。

然后,您可以使用以下命令安装此项目模板

composer create-project --prefer-dist yiisoft/yii2-app-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

上面的命令将执行单元和功能测试。单元测试是测试系统组件,而功能测试是测试用户交互。接受测试默认禁用,因为它们需要额外的设置,因为它们在真实浏览器中进行测试。

运行接受测试

要执行接受测试,请执行以下操作

  1. tests/acceptance.suite.yml.example重命名为tests/acceptance.suite.yml以启用套件配置

  2. composer.json中将codeception/base包替换为codeception/codeception以安装功能齐全的Codeception版本

  3. 使用Composer更新依赖关系

    composer update  
    
  4. 下载Selenium Server并启动它

    java -jar ~/selenium-server-standalone-x.xx.x.jar
    

    如果使用自48版本以来的Firefox浏览器或自53版本以来的Google Chrome浏览器与Selenium Server 3.0配合使用,您必须下载GeckoDriverChromeDriver,并使用它启动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
    
  5. (可选) 创建yii2basic_test数据库,并根据需要应用迁移来更新它。

    tests/bin/yii migrate
    

    数据库配置文件位于config/test_db.php

  6. 启动Web服务器

    tests/bin/yii serve
    
  7. 现在您可以运行所有可用的测试

    # 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目录下查看代码覆盖率输出。