承接 dbx12/yii2-mock-database 相关项目开发

从需求分析到上线部署,全程专人跟进,保证项目质量与交付效率

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

dbx12/yii2-mock-database

Composer 安装命令:

composer require dbx12/yii2-mock-database

包简介

Mock connection for the Yii2 database connection. This connection can be configured to fail operations for testing purposes.

README 文档

README

This library provides adapted connections and command classes for Yii2 database connections. With it, you can force database failures in your tests to check how your application behaves when the database is not reachable for example.

Setup and usage

  1. Install with composer require --dev dbx12/yii2-mock-database
  2. Define the \dbx12\yii2MockDatabase\Connection class as your database connection class.
  3. During the tests, call Yii::$app->db->failAlways() to fail all subsequent commands. Make sure you've loaded your fixtures before doing that.
  4. Return to normal behavior by calling Yii::$app->db->passAlways()
  5. Optionally register the CleanupExtension in your phpunit.xml to get rid of old mockDatabase.dat files (see below)

Other methods

  • failNextCommand($count = 1) allows you to only fail a given number of commands and then return to "normal behavior"
  • passNextCommand($count = 1) allows you to only pass a given number of commands and then return to "always fail"

Cleanup Extension

The cleanup extension deletes all files given to it in the first argument after the last test. You can use it to clean your output directory and prevent old files from affecting future test runs. All paths must be either absolute or relative to the working directory of phpunit. A configuration example is in the code block below, it assumes your working directory is the project root (you call phpunit as vendor/bin/phpunit).

<extension class="dbx12\yii2MockDatabase\CleanupExtension">
   <arguments>
      <array>
         <!-- The three lines below specify that the file tests/_output/mockDatabase.dat is to be deleted after the last test -->
         <element key="0">
            <string>tests/_output/mockDatabase.dat</string>
         </element>
         <!-- You could add another <element> tag like above here to delete additional files -->
      </array>
   </arguments>
</extension>

统计信息

  • 总下载量: 50
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 0
  • 点击次数: 2
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 0
  • Watchers: 1
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2021-09-01