Code Monkey home page Code Monkey logo

data-fixtures's Introduction

kununu data-fixtures

At kununu we rely on data fixtures in our tests as well in our development and testing environments. A good definition of what fixtures are is the one from the documentation of DoctrineFixturesBundle in which the design and implementation of this package was heavily based on.

Fixtures are used to load a “fake” set of data into a database that can then be used for testing or to help give you some interesting data while you’re developing your application.

What is kununu/data-fixtures?

This package provides a simple way to manage and execute the loading of data fixtures for any storage mechanism. It's design and implementation was heavily based on the Doctrine data-fixtures package. If you are interested in why we created this package check out Why kununu/data-fixtures?.

Fixtures types

Currently, this package supports the following types of fixtures:

Also check Directory Loader to check how to load fixtures from files in a directory.

If you are interested in knowing more about the concepts of the package, or you need to create a new fixture type check out How to create a new Fixture Type.


Install

1. Add kununu/data-fixtures to your project

Before installing this package be aware:

  • You own the fixtures you load
  • This package should not be used in production mode!
composer require --dev kununu/data-fixtures

2. Enable any fixture type

In order to enable the fixture types that you are interested, check out their documentation:


Append Fixtures

By default, when loading fixtures the data storage is purged. If you want to change this behavior and instead append the fixtures you can pass false as second argument to any executor.

// By default, the data storage is purged
$executor->execute($loader->getFixtures());
// If you want you can `append` the fixtures instead of purging the database
$executor->execute($loader->getFixtures(), true);

Load Fixtures

In order to load fixtures the default Loader provides a couple of options:

  1. loadFromDirectory(string $dir)
  2. loadFromFile(string $fileName)
  3. loadFromClassName(string $className)
  4. addFixture(FixtureInterface $fixture)
$loader = new Kununu\DataFixtures\Loader\ConnectionFixturesLoader();
$loader->loadFromDirectory('/your/directory/');
$loader->loadFromFile('/your/file.php');
$loader->loadFromClassName(MyFixtureSql::class);
$loader->addFixture(new MyFixtureSql());

Initializable Fixtures

If you want your Fixture classes to be initialized you can implement the InitializableFixtureInterface

public function initializeFixture(...$args): void;

Then before loading the fixtures you need to register them in the Loader:

$loader = new Kununu\DataFixtures\Loader\ConnectionFixturesLoader();

$this->loader->registerInitializableFixture(
	YourFixtureClass::class,
	// 1st argument
	1, 
	// 2nd argument
	'This is an argument that will be passed to initializeFixture of YourFixtureClass',
	// 3rd argument
	[
		'field'    => 'field-name',
		'value' => 10,
	],
	// 4th argument
	$anInstanceOfOneOfYourOtherClasses
	// Pass as many arguments as you like...
);

$loader->addFixture(new YourFixtureClass());

Contribute

If you are interested in contributing read our contributing guidelines.


Tests

If not yet, first install composer dependencies:

composer install

Run the tests by doing:

vendor/bin/phpunit

To run tests without coverage report:

composer install
composer test

To run tests with coverage report:

composer install
composer test-coverage

Continuous Integration Quality Gate Status

data-fixtures's People

Contributors

hugo-goncalves-kununu avatar joaoalves-kununu avatar krzysztofsopa avatar samuel-nogueira-kununu avatar thebay0r avatar usmichael avatar

Stargazers

 avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.