PHPackages                             koine/db-test-case - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Testing &amp; Quality](/categories/testing)
4. /
5. koine/db-test-case

ActiveLibrary[Testing &amp; Quality](/categories/testing)

koine/db-test-case
==================

Base class for testing database

1.0.1(10y ago)0911MITPHPPHP &gt;=5.3.3

Since Jun 5Pushed 10y agoCompare

[ Source](https://github.com/koinephp/DbTestCase)[ Packagist](https://packagist.org/packages/koine/db-test-case)[ RSS](/packages/koine-db-test-case/feed)WikiDiscussions master Synced 1mo ago

READMEChangelogDependencies (2)Versions (3)Used By (1)

Koine DbTestCase
----------------

[](#koine-dbtestcase)

Base class for testing database with PDO. Tested only against MySql.

**Work in progress**

Code information:

[![Build Status](https://camo.githubusercontent.com/f58eafb12e171b8ec80ae5fd475ab00af35e6790dbd1f2b1355c30e0febd6186/68747470733a2f2f7472617669732d63692e6f72672f6b6f696e657068702f446254657374436173652e706e673f6272616e63683d6d6173746572)](https://travis-ci.org/koinephp/DbTestCase)[![Coverage Status](https://camo.githubusercontent.com/c80236d620ac872b181ba44018dadd9a84fbbf8f40b5196d3b862e6bb3265704/68747470733a2f2f636f766572616c6c732e696f2f7265706f732f6b6f696e657068702f446254657374436173652f62616467652e7376673f6272616e63683d6d6173746572)](https://coveralls.io/r/koinephp/DbTestCase?branch=master)[![Code Climate](https://camo.githubusercontent.com/da99e31abee355bfb7b236f48f44bb0109b1a156ae09ebe4f98d4082c16a80fb/68747470733a2f2f636f6465636c696d6174652e636f6d2f6769746875622f6b6f696e657068702f446254657374436173652e706e67)](https://codeclimate.com/github/koinephp/DbTestCase)[![Scrutinizer Code Quality](https://camo.githubusercontent.com/23c257732371797a6782b46975bb795aa7cfe828af16e947b362a49e6bfc51ac/68747470733a2f2f7363727574696e697a65722d63692e636f6d2f672f6b6f696e657068702f446254657374436173652f6261646765732f7175616c6974792d73636f72652e706e673f623d6d6173746572)](https://scrutinizer-ci.com/g/koinephp/DbTestCase/?branch=master)

Package information:

[![Latest Stable Version](https://camo.githubusercontent.com/053f405a776c87d2030589a4675dd84951183165e9ecf71b8e8512e5e9077a59/68747470733a2f2f706f7365722e707567782e6f72672f6b6f696e652f64622d746573742d636173652f762f737461626c652e737667)](https://packagist.org/packages/koine/db-test-case)[![Total Downloads](https://camo.githubusercontent.com/cda73cbc983b6e31194ff812b997f16ebb5bba726783b07f04d4eeed9a84a816/68747470733a2f2f706f7365722e707567782e6f72672f6b6f696e652f64622d746573742d636173652f646f776e6c6f6164732e737667)](https://packagist.org/packages/koine/db-test-case)[![Latest Unstable Version](https://camo.githubusercontent.com/5b8d6ad7d8a51522151c373b147235454bf07c2dfdfe3dafc71dc25a73d126ce/68747470733a2f2f706f7365722e707567782e6f72672f6b6f696e652f64622d746573742d636173652f762f756e737461626c652e737667)](https://packagist.org/packages/koine/db-test-case)[![License](https://camo.githubusercontent.com/cad4b2fa71725cc06b65f21a06a1e0a0facadb2bcbdae6b9031f549096f62bf3/68747470733a2f2f706f7365722e707567782e6f72672f6b6f696e652f64622d746573742d636173652f6c6963656e73652e737667)](https://packagist.org/packages/koine/db-test-case)[![Dependency Status](https://camo.githubusercontent.com/81b05a1fc9ce90da529e6939c746965ce4dd0d3548dc6834f34522f2f849bc8e/68747470733a2f2f67656d6e617369756d2e636f6d2f6b6f696e657068702f446254657374436173652e706e67)](https://gemnasium.com/koinephp/DbTestCase)

### Usage

[](#usage)

#### Db Test Case

[](#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
 */
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)

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)

#### Installing Via Composer

[](#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

[](#alternative-install)

- Learn [composer](https://getcomposer.org). You should not be looking for an alternative install. It is worth the time. Trust me ;-)
- Follow [this set of instructions](#installing-via-composer)

### Issues/Features proposals

[](#issuesfeatures-proposals)

[Here](https://github.com/koinephp/DbTestCase/issues) is the issue tracker.

Contributing
------------

[](#contributing)

Please refer to the [contribuiting guide](https://github.com/koinephp/DbTestCase/blob/master/CONTRIBUTING.md).

### Lincense

[](#lincense)

[MIT](MIT-LICENSE)

### Authors

[](#authors)

- [Marcelo Jacobus](https://github.com/mjacobus)

###  Health Score

27

—

LowBetter than 49% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity9

Limited adoption so far

Community8

Small or concentrated contributor base

Maturity59

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~2 days

Total

2

Last Release

3997d ago

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/226834?v=4)[Marcelo Jacobus](/maintainers/mjacobus)[@mjacobus](https://github.com/mjacobus)

---

Top Contributors

[![mjacobus](https://avatars.githubusercontent.com/u/226834?v=4)](https://github.com/mjacobus "mjacobus (20 commits)")

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/koine-db-test-case/health.svg)

```
[![Health](https://phpackages.com/badges/koine-db-test-case/health.svg)](https://phpackages.com/packages/koine-db-test-case)
```

###  Alternatives

[phpspec/prophecy

Highly opinionated mocking framework for PHP 5.3+

8.5k551.7M682](/packages/phpspec-prophecy)[brianium/paratest

Parallel testing for PHP

2.5k118.8M754](/packages/brianium-paratest)[beberlei/assert

Thin assertion library for input validation in business models.

2.4k96.9M570](/packages/beberlei-assert)[mikey179/vfsstream

Virtual file system to mock the real file system in unit tests.

1.4k108.0M2.7k](/packages/mikey179-vfsstream)[orchestra/testbench

Laravel Testing Helper for Packages Development

2.2k39.1M32.1k](/packages/orchestra-testbench)[phpspec/phpspec

Specification-oriented BDD framework for PHP 7.1+

1.9k36.7M3.1k](/packages/phpspec-phpspec)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
