承接 ecomdev/mysql-test-utils 相关项目开发

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

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

ecomdev/mysql-test-utils

Composer 安装命令:

composer require ecomdev/mysql-test-utils

包简介

Bare minimum MySQL Test utilities for writing automated tests of software that relies on MySQL as data storage.

README 文档

README

Bare minimum MySQL Test utilities for writing automated tests of software that relies on MySQL as data storage.

This package works great with any type of MySQL setup as soon as user for testing can create own databases. Each instance of the database class creates a new unique database on the server that gets dropped upon test case completion.

Configuration

In your PHPUnit xml you need to specify the connection settings for mysql connection and executable for mysql client.

Down below is an example of phpunit xml configuration with docker-compose database setup.

<?xml version="1.0" encoding="UTF-8"?>
<phpunit
   xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
   xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/9.2/phpunit.xsd"
   bootstrap="vendor/autoload.php">
    <testsuite name="MySQL Test Utils Suite">
        <directory suffix="Test.php">tests/</directory>
    </testsuite>
    <php>
        <env name="MYSQL_PASSWORD" value="tests" />
        <env name="MYSQL_USER" value="root" />
        <env name="MYSQL_HOST" value="127.0.0.1" />
        <env name="MYSQL_CLIENT" value="docker-compose exec -T mysql mysql" />
    </php>
</phpunit>
version: "3"
services:
  mysql:
    image: percona/percona-server:5.7
    ports:
      - 3306:3306
    environment:
      MYSQL_ROOT_PASSWORD: tests

Examples

Database gets created on each test

use PHPUnit\Framework\TestCase;
use EcomDev\MySQLTestUtils\DatabaseFactory;

class SomeDatabaseRelatedTest extends TestCase
{
    private $database;
    
    protected function setUp() : void
    {
         $this->database = (new DatabaseFactory())->createDatabase();
         $this->database->loadFixture('some/path/to/schema.sql');
    }
    
    public function testSomethingIsWritten() 
    {
        $this->assertEquals(
            [
                ['value1', 'value2']
            ],
            $this->database->fetchTable('some_table_name', 'column1', 'column2')
        );
    }
}

Database gets created on each test class

use PHPUnit\Framework\TestCase;
use EcomDev\MySQLTestUtils\DatabaseFactory;

class SomeDatabaseRelatedTest extends TestCase
{
    private static $database;
    
    public static function setUpBeforeClass() : void
    {
         self::$database = (new DatabaseFactory())->createDatabase();
         self::$database->loadFixture('some/path/to/schema.sql');
    }
    
    public static function tearDownAfterClass() : void
    {
         self::$database = null;
    }

    public function testSomethingIsWritten() 
    {
        $this->assertEquals(
            [
                ['value1', 'value2']
            ],
            self::$database->fetchTable('some_table_name', 'column1', 'column2')
        );
    }
}

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2020-06-09

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固