zwei/base

The Zwei Base package.

v1.0.0 2018-03-30 02:50 UTC

This package is auto-updated.

Last update: 2024-04-06 12:23:34 UTC


README

doctrine2 数据操作 读取配置

1 安装(Install)

  1. 通过Composer安装
  2. 创建composer.json文件,并写入以下内容:
{
  "require": {
    "zwei/base": "dev-develop"
  }
}
  1. 执行composer install
  1. 在项目目录创建config/bao-loan.yml文件,添加一下内容
BASE_TEST_CONFIG: "base_test_config" # 本包测试键(单元测试用)

# 数据库配置
DB_HOST: "localhost" # 主机
DB_PORT: 3306 # 端口
DB_USER: "root" # 用户名
DB_PASS: "root" # 密码
DB_NAME: "demo" # 数据库名
DB_TABLE_PREFIX: "" # 表前缀
DB_CHARSET: "utf8" # 设置字符编码,空字符串不设置
DB_SQLLOG: false # 是否启用sql调试

使用示例(use)

  1. 例如项目目录在"E:\web\php7\test"
  2. 创建index.php,并加入以下内容
<?php
use \Zwei\Base\Config;
// 读取默认配置"config\bao-loan.yml"
Config::get("配置键名");

// 读取配置文件"config/test-new-prefix.conf.yml"中的"test-new-prefix-key"
Config::get('test-new-prefix-key', 'test-new-prefix', 'test-new-prefix.conf.yml');

# 获取doctrine数据库连接
// 返回\Doctrine\DBAL\Connection类,请查看doctrine 官网文档
$dbConnection = DB::getInstance()->getConnection();

单元测试使用

--bootstrap 在测试前先运行一个 "bootstrap" PHP 文件

  • --bootstrap引导测试: phpunit --bootstrap tests/TestInit.php tests/

D:\phpStudy\php\php-7.1.13-nts\php.exe D:\phpStudy\php\php-5.6.27-nts\composer.phar update

D:\phpStudy\php\php-7.1.13-nts\php.exe vendor\phpunit\phpunit\phpunit --bootstrap tests/TestInit.php tests/