koine/db-test-case
Composer 安装命令:
composer require koine/db-test-case
包简介
Base class for testing database
README 文档
README
Base class for testing database with PDO. Tested only against MySql.
Work in progress
Code information:
Package information:
Usage
Db Test Case
In your bootstrap file set up the connection
// tests/bootstrap.php // [...] \Koine\PHPUnit\DbTestCase::setConnection($pdoConnection);
namespace MyAppTest; use Koine\PHPUnit\DbTestCase; use MyApp\BlogService; /** * @author Marcelo Jacobus <marcelo.jacobus@gmail.com> */ class DbTestCaseTest extends DbTestCase { public function setUp() { parent::setUp(); // enclose everything in a transaction } public function tearDown() { parent::tearDown(); // rollback the transaction } /** * @test */ public function canCreatePost() { $service = new BlogService($this->getConnection()); $service->create(array( 'title' => 'some title', 'body' => 'some body', )); $this->assertTableCount(1, 'blog_post'); } /** * @test */ public function canFindByCategory() { $helper = $this->createTableHelper('blog_post'); $helper->insert(array( 'title' => 'foo', 'body' => 'bar', 'categoryId' => 1, )); $helper->insert(array( 'title' => 'foo', 'body' => 'bar', 'categoryId' => 2, )); $service = new BlogService($this->getConnection()); $records = $service->findByCategoryId(1); $this->assertEquals(1, count($records)); } }
Table Helper
Table helper is a very simple ORM for creating records for test, updating and querying a single table.
Setting up
$tableName = 'blog_post'; $tableHelper = new \Koine\DbTestCase\TableHelper\TableHelper( $pdo, $tableName, 'id' );
Finding records by conditions
$posts = $tableHelper->findAllBy(array( 'categoryId' => $categoryId, ));
Finding record by id
$post = $tableHelper->find(10);
Crating records
$tableHelper->insert(array( 'title' => 'First blog', 'body' => 'Post body', ));
Updating
$tableHelper->update(10, array( 'title' => 'new title', ));
Deleting
$tableHelper->delete(10);
Counting
$tableHelper->getNumberOfRows();
Installing
Installing Via Composer
Append the lib to your requirements key in your composer.json.
{ // composer.json // [..] require: { // append this line to your requirements "koine/db-test-case": "*" } }
Alternative install
- Learn composer. You should not be looking for an alternative install. It is worth the time. Trust me ;-)
- Follow this set of instructions
Issues/Features proposals
Here is the issue tracker.
Contributing
Please refer to the contribuiting guide.
Lincense
Authors
koine/db-test-case 适用场景与选型建议
koine/db-test-case 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 91 次下载、GitHub Stars 达 0, 最近一次更新时间为 2015 年 06 月 05 日, 在 PHP 生态内属于活跃度较高的组件。
我们在过去多个企业项目中使用过 koine/db-test-case 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 koine/db-test-case 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
统计信息
- 总下载量: 91
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 18
- 依赖项目数: 1
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2015-06-05