定制 branchonline/yii2-pgsqltester 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

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

branchonline/yii2-pgsqltester

Composer 安装命令:

composer require --dev branchonline/yii2-pgsqltester

包简介

Extends Yii2 framework with a powerful console controller for tests requiring a postgres database.

README 文档

README

Automated setup of empty database and powerful console control of available tests.

Example usage

First set up the environment using the instructions in example setup below.

Run all tests:

./yii_test test/run or ./yii_test test (action run is default)

Run all unit tests using (only when you are not using modules, otherwise you have to specify the module):

./yii_test test -s=unit

Run all unit tests in module admin using:

./yii_test test -m=admin

Run all unit tests in module admin from suite acceptance:

./yii_test test -s=acceptance -m=admin

Run specific test by name:

./yii_test test TestName

Force to remigrate the test database:

./yii_test test/prepare-db true

Example setup

Read carefully and make sure you understand what you're doing before setting anything up!

Databases

This package provides a clean separation of databases so your tests can always run on an empty database that is in the correct state. To see how it works we identify 4 databases:

  • The dev database. This database is not touched by the testing mechanism, but should remain accessible for developing.
  • The template database. This is the database that is migrated to the correct version by the testing system, and may contain all kinds of data that your migrations add by default.
  • The test databse. This is the database that the actual tests run on. It is prepared by the testing mechanism to be a completely empty copy of the template database.
  • The postgres databse. This is the default database provided by postgres, that is used by the tester to automatically setup both template and test database.
Yii setup

You need 2 config files for this setup to work:

  • test.php should contain credentials for the postgres and test database.
  • test-setup.php should overwrite the credentials of test with that of template and make the test controller available through the controller map.

An example for test.php:

<?php
return [
    'id' => 'basic-tests',
    'basePath' => dirname(__DIR__),
    'language' => 'en-US',
    'components' => [
        'config_db' => [
            'class' => 'yii\db\Connection',
            'dsn' => 'pgsql:host=localhost;port=5432;dbname=postgres',
        ],
        'db' => [
            'class' => 'yii\db\Connection',
            'dsn' => 'pgsql:host=localhost;port=5432;dbname=testing',
        ],
    ],
];

An example for test-setup.php"

<?php
return [
    'components' => [
        'db' => [
            'dsn' => 'pgsql:host=localhost;port=5432;dbname=testing_template'
        ],
    ],
    'controllerMap' => [
        'test' => [
            'class' => 'branchonline\pgsqltester\TestController',
        ]
    ],
];

Make sure you have a access point for running the tests, for instance ./yii_test.

yii_test example (adjust to your liking):

<?php

defined('YII_DEBUG') or define('YII_DEBUG', true);
defined('YII_ENV') or define('YII_ENV', 'test');

require(__DIR__ . '/vendor/autoload.php');
require(__DIR__ . '/vendor/yiisoft/yii2/Yii.php');

$config = yii\helpers\ArrayHelper::merge(
    require(__DIR__ . '/path/to/test.php'),
    require(__DIR__ . '/path/to/test-setup.php')
);

$application = new yii\console\Application($config);
$exitCode = $application->run();
exit($exitCode);

Make sure the YII_ENV is initialized to 'test'. Also make sure you include test-setup.php and test.php in that order.

Codeception setup

Codeception is run using the codeception.yml file as configuration, make sure to configure the Yii module and include test.php as the access point.

modules:
    config:
        Yii2:
            configFile: 'path/to/test.php'

branchonline/yii2-pgsqltester 适用场景与选型建议

branchonline/yii2-pgsqltester 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 2.84k 次下载、GitHub Stars 达 1, 最近一次更新时间为 2017 年 01 月 17 日, 在 PHP 生态内属于活跃度较高的组件。

它主要适用于以下技术方向: 「testing」 「test」 「postgresql」 「pgsql」 「postgres」 「codeception」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。

我们在过去多个企业项目中使用过 branchonline/yii2-pgsqltester 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 branchonline/yii2-pgsqltester 我们能提供哪些服务?
定制开发 / 二次开发

基于 branchonline/yii2-pgsqltester 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

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

GitHub 信息

  • Stars: 1
  • Watchers: 3
  • Forks: 2
  • 开发语言: PHP

其他信息

  • 授权协议: BSD-3-Clause
  • 更新时间: 2017-01-17