2017 © Pedro Peláez
 

library db-test-case

Base class for testing database

image

koine/db-test-case

Base class for testing database

  • Friday, August 28, 2015
  • by mjacobus
  • Repository
  • 1 Watchers
  • 0 Stars
  • 80 Installations
  • PHP
  • 1 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 3 Versions
  • 0 % Grown

The README.md

Koine DbTestCase

Base class for testing database with PDO. Tested only against MySql., (*1)

Work in progress, (*2)

Code information:, (*3)

Build Status Coverage Status Code Climate Scrutinizer Code Quality, (*4)

Package information:, (*5)

Latest Stable Version Total Downloads Latest Unstable Version License Dependency Status, (*6)

Usage

Db Test Case

In your bootstrap file set up the connection, (*7)

// 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., (*8)

Setting up, (*9)

$tableName = 'blog_post';

$tableHelper = new \Koine\DbTestCase\TableHelper\TableHelper(
  $pdo,
  $tableName,
  'id'
);

Finding records by conditions, (*10)

$posts = $tableHelper->findAllBy(array(
  'categoryId' => $categoryId,
));

Finding record by id, (*11)

$post = $tableHelper->find(10);

Crating records, (*12)

$tableHelper->insert(array(
  'title' => 'First blog',
  'body'  => 'Post body',
));

Updating, (*13)

$tableHelper->update(10, array(
  'title' => 'new title',
));

Deleting, (*14)

$tableHelper->delete(10);

Counting, (*15)

$tableHelper->getNumberOfRows();

Installing

Installing Via Composer

Append the lib to your requirements key in your composer.json., (*16)

{
    // composer.json
    // [..]
    require: {
        // append this line to your requirements
        "koine/db-test-case": "*"
    }
}

Alternative install

Issues/Features proposals

Here is the issue tracker., (*17)

Contributing

Please refer to the contribuiting guide., (*18)

Lincense

MIT, (*19)

Authors

The Versions

28/08 2015

dev-master

9999999-dev

Base class for testing database

  Sources   Download

MIT

The Requires

  • php >=5.3.3

 

The Development Requires

by Marcelo Jacobus

08/06 2015

1.0.1

1.0.1.0

Base class for testing database

  Sources   Download

MIT

The Requires

  • php >=5.3.3

 

The Development Requires

by Marcelo Jacobus

05/06 2015

1.0

1.0.0.0

Base class for testing database

  Sources   Download

MIT

The Requires

  • php >=5.3.3

 

The Development Requires

by Marcelo Jacobus