Download the PHP package mbarquin/datapool without Composer

On this page you can find all versions of the php package mbarquin/datapool. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.

FAQ

After the download, you have to make one include require_once('vendor/autoload.php');. After that you have to import the classes with use statements.

Example:
If you use only one package a project is not needed. But if you use more then one package, without a project it is not possible to import the classes with use statements.

In general, it is recommended to use always a project to download your libraries. In an application normally there is more than one library needed.
Some PHP packages are not free to download and because of that hosted in private repositories. In this case some credentials are needed to access such packages. Please use the auth.json textarea to insert credentials, if a package is coming from a private repository. You can look here for more information.

  • Some hosting areas are not accessible by a terminal or SSH. Then it is not possible to use Composer.
  • To use Composer is sometimes complicated. Especially for beginners.
  • Composer needs much resources. Sometimes they are not available on a simple webspace.
  • If you are using private repositories you don't need to share your credentials. You can set up everything on our site and then you provide a simple download link to your team member.
  • Simplify your Composer build process. Use our own command line tool to download the vendor folder as binary. This makes your build process faster and you don't need to expose your credentials for private repositories.
Please rate this library. Is it a good library?

Informations about the package datapool

DataPool

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.

Installation

You can install the component in the following ways:

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:

    /**
     * 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.


All versions of datapool with dependencies

PHP Build Version
Package Version
Requires php Version >=5.3
Composer command for our command line client (download client) This client runs in each environment. You don't need a specific PHP version etc. The first 20 API calls are free. Standard composer command

The package mbarquin/datapool contains the following files

Loading the files please wait ....