PHPackages                             mbarquin/datapool - 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. mbarquin/datapool

ActiveLibrary

mbarquin/datapool
=================

PHP DataPool, data provider object for PHPUnit dataprovider tag

V1.0.0(10y ago)017PHPPHP &gt;=5.3

Since Sep 3Pushed 10y ago1 watchersCompare

[ Source](https://github.com/mbarquin/datapool)[ Packagist](https://packagist.org/packages/mbarquin/datapool)[ RSS](/packages/mbarquin-datapool/feed)WikiDiscussions master Synced today

READMEChangelog (2)Dependencies (3)Versions (1)Used By (0)

DataPool
========

[](#datapool)

Introduction
------------

[](#introduction)

This library is intended to be used with PHPUnit tool. DataPool is an iterable object which can be returned to a standard @dataprovider tagged function or it can be used to get specific datasets from a big datapool.

- It allows keeping low weight indexed array values separated from tests logic.
- It can return specific datasets attending to its dataset index.
- It can encapsulate dataset as an array to avoid large parameters lists.

Installation
------------

[](#installation)

You can install the component in the following ways:

- Use the official Github repository ()
- Use composer : composer require mbarquin/datapool --dev

Usage
-----

[](#usage)

The main use purpose is via heritage, the final class will only contains a definition index and a dataArray, we can instance it into our test case as a dataprovider or as a normal object which vill provide us with predefined test cases.

There are more use cases in the example file /example/tests/src/exampleContactsModelTest.php

### Custom dataPool Example:

[](#custom-datapool-example)

```
    /**
     * Contacts datapool file for Testing purposes
     */
    class ContactsDataPool extends \DataPool\DataPool
    {

        /**
         * @var array Datapoolm fields definition to be merged with data
         */
        protected $definition = array(
            'name',
            'surname',
            'phone',
            'result'
        );

        /**
         * @var array Datasets array to be merged with definition and returned to tests
         */
        public $dataArray = array(
            'Test1'                  => array('Jack', 'Travis', '555999666', true),
            'Test2'                  => array('Mathew', 'Jones', '555888555', true),
            'Test3.NameSurnameEmpty' => array('', '', '555666555', false),
            'TestCase1.PhoneToLong'  => array('Gregor', 'Jones', '5550005518899', false),
            'TestCase2.NoName'       => array('', 'Lock', '555000559', false)
        );

    }// End ContactsDataPool.

```

Protected array $definition is defined to avoid data indexes being duplicated along all defined datasets. Datasets can be returned with this $definition values as indexes, we can set up this behaviour with the function **setReturnIndexes(false|true)**, by default setted to FALSE.

Public array $dataArray will contain an array with all possible tests datasets, it can be classified by index to allow returning smaller portions of this dataArray via getRowsByIndex($index).

\###Tests file example:###

```
namespace Example\tests\src;

class exampleContactsModelTest extends \PHPUnit_Framework_TestCase {

    static private $dataPool = null;

    /**
     * Static instance of ContactsDataPool
     *
     * @return \Example\tests\files\ContactsDataPool
     */
    public function getDataPool() {
        // If not instanciated yet...
        if (is_object(self::$dataPool) === false) {
            self::$dataPool = new \Example\tests\files\ContactsDataPool();
        }
        // Avoid mixing behaviors during tests
        self::$dataPool->setReturnArray(false);
        self::$dataPool->setReturnIndexes(false);

        return self::$dataPool;
    }

```

Function **getDataPool()** is a dataprovider which sets and returns an iterable object. It can be used in any common case as standard @dataprovider function's return, it's configured to avoid any index usage as a usual PHPUnit dataprovider.

We have set:

**setReturnArray(false)** in order to get each dataset value as a different test function parameter.

**setReturnIndexes(false)** to avoid returned dataset indexation with $definition values (array\_combine)

```
    public function getDataPoolAsArray() {
        $dataPool = $this->getDataPool();
        $dataPool->setReturnArray(true);
        $dataPool->setReturnIndexes(true);

        return $dataPool->getRowsByIndex('Case');
    }

```

Function **getDataPoolAsArray()** returns an iterable dataset from previously instanced dataProvider object. We want to get only test cases indexed by "Case" so we must return the result array from **getRowsByIndex('Case')** function.

We have changed:

**setReturnArray(true)** in order to get each dataset fields encapsulated in an array.

**setReturnIndexes(true)** to force the indexation of each returned dataset with $definition values (array\_combine)

```
    /**
     * @dataProvider getDataPoolAsArray
     */
    public function testArrayDataProviderInsert($regData) {
        $contModel = new \Example\src\exampleContactsModel();
        $expected  = $regData['result'];
        unset($regData['result']);

        $result = $contModel->insert($regData);
        if ($result === false) {
            $this->assertEquals($expected, $result);
        } else {
            $this->assertTrue(is_integer($result));
        }
    }

```

As in **testArrayDataProviderInsert**, with data encapsulated as array we can easily perform tests on ORM objects or avoid large parameters lists in tests with many data values.

```
    /**
     * @dataProvider getDataPool
     */
    public function testPureDataProviderInsert($name, $surname, $phone, $expected) {
        $contModel      = new \Example\src\exampleContactsModel();

        $reg['name']    = $name;
        $reg['surname'] = $surname;
        $reg['phone']   = $phone;

        $result = $contModel->insert($reg);
        if ($result === false) {
            $this->assertEquals($expected, $result);
        } else {
            $this->assertTrue(is_integer($result));
        }
    }

}// End exampleContactsModelTest.

```

Function testPureDataProviderInsert makes assertions using ContactsDataPool object as a usual dataprovider array.

###  Health Score

25

—

LowBetter than 39% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity6

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity56

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

Unknown

Total

1

Last Release

3856d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/e374f8ad1775a2991c6662869ca1b6e7b3693b434404b6f77ddce0238a7abea8?d=identicon)[mbarquin](/maintainers/mbarquin)

---

Top Contributors

[![mbarquin](https://avatars.githubusercontent.com/u/6476519?v=4)](https://github.com/mbarquin "mbarquin (35 commits)")

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/mbarquin-datapool/health.svg)

```
[![Health](https://phpackages.com/badges/mbarquin-datapool/health.svg)](https://phpackages.com/packages/mbarquin-datapool)
```

PHPackages © 2026

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