2017 © Pedro Peláez
 

library dbunit-fixture-arrays

PHPUnit DbUnit Native Array-based Fixtures

image

mrkrstphr/dbunit-fixture-arrays

PHPUnit DbUnit Native Array-based Fixtures

  • Friday, August 15, 2014
  • by mrkrstphr
  • Repository
  • 1 Watchers
  • 4 Stars
  • 579 Installations
  • PHP
  • 2 Dependents
  • 0 Suggesters
  • 2 Forks
  • 1 Open issues
  • 2 Versions
  • 2 % Grown

The README.md

dbunit-fixture-arrays

A native PHP array-based fixture provider for PHPUnit's DbUnit, (*1)

build status, (*2)

dbunit-fixture-arrays provides the capability to provide fixtures (data sets) to PHPUnit's DbUnit as native PHP arrays, as opposed to the many other drivers currently supported by DbUnit, such as Yaml, XML, CSV, etc., (*3)

How?

Simply install with composer:, (*4)

composer require mrkrstphr/dbunit-fixture-arrays:@stable

Then plug into DbUnit as you would with any other data set format:, (*5)

public function getDataSet() {
    return new ArrayDataSet([
        '/path_to_file.php',
        '/path_to_other_file.php'
    ]);
}

Where the files look something like:, (*6)

return [
    'table_name' => [
        ['id' => 1, 'name' => 'Row Data 1'],
        ['id' => 2, 'name' => 'Row Data 2'],
    ],
    'other_table_name' => [
        ['id' => 99, 'color' => 'Red'],
        ['id' => 88, 'color' => 'Blue'],
    ],
];

Why?

Sometimes it's nice to be able to slip a little logic into the fixtures files. Say for instance that you need some test data that contains a date in the future, but not more than 1 year away. Without continually updating your fixture data, there's no way to reliably do this., (*7)

With dbunit-fixture-arrays, you can:, (*8)

return [
    'table_name' => [
        ['id' => 1, 'date' => (new DateTime('+1 year'))->format('Y-m-d')],
        ['id' => 2, 'date' => '2014-05-01'
    ]
];

Other benefits include slightly, but probably not very noticably, faster tests with less memory footprint due to not needing to parse Yaml or XML - your results may vary., (*9)

Contributing

Suggestions or bugs? Submit an issue or open a pull request!, (*10)

The Versions

15/08 2014

dev-master

9999999-dev http://github.com/mrkrstphr/dbunit-fixture-arrays

PHPUnit DbUnit Native Array-based Fixtures

  Sources   Download

MIT

The Requires

 

The Development Requires

phpunit dbunit

15/08 2014

v1.0.0

1.0.0.0 http://github.com/mrkrstphr/dbunit-fixture-arrays

PHPUnit DbUnit Native Array-based Fixtures

  Sources   Download

MIT

The Requires

 

The Development Requires

phpunit dbunit