Coder Social home page Coder Social logo

vincentchalamon / foundry Goto Github PK

View Code? Open in Web Editor NEW

This project forked from zenstruck/foundry

0.0 0.0 0.0 1.53 MB

A model factory library for creating expressive, auto-completable, on-demand dev/test fixtures with Symfony and Doctrine.

Home Page: https://symfony.com/bundles/ZenstruckFoundryBundle/current/index.html

License: MIT License

Shell 0.03% PHP 99.97%

foundry's Introduction

Foundry

CI Status Code Coverage Latest Version Downloads

Foundry makes creating fixtures data fun again, via an expressive, auto-completable, on-demand fixtures system with Symfony and Doctrine:

$post = PostFactory::new() // Create the factory for Post objects
    ->published()          // Make the post in a "published" state
    ->create([             // create & persist the Post object
        'slug' => 'post-a' // This Post object only requires the slug field - all other fields are random data
    ])
;

The factories can be used inside DoctrineFixturesBundle to load fixtures or inside your tests, where it has even more features.

Foundry supports doctrine/orm (with doctrine/doctrine-bundle), doctrine/mongodb-odm (with doctrine/mongodb-odm-bundle) or a combination of these.

Want to watch a screencast ๐ŸŽฅ about it? Check out https://symfonycasts.com/foundry

Read the Documentation

How to contribute

Running the Test Suite

The test suite of this library needs one or more databases, then it comes with a docker compose configuration.

Note

Docker and PHP installed locally (with mysql, pgsql & mongodb extensions) is required.

You can start the containers and run the test suite:

# start the container
$ docker compose up --detach

# install dependencies
$ composer update

# run test suite with all available permutations
$ composer test

# run only one permutation
$ vendor/bin/phpunit

# run test suite with dama/doctrine-test-bundle
$ vendor/bin/phpunit -c phpunit.dama.xml.dist

# run test suite with postgreSQL instead of MySQL
$ DATABASE_URL="postgresql://zenstruck:[email protected]:5433/zenstruck_foundry?serverVersion=15" vendor/bin/phpunit

Overriding the default configuration

You can override default environment variables by creating a .env.local file, to easily enable permutations:

# .env.local
DATABASE_URL="postgresql://zenstruck:[email protected]:5433/zenstruck_foundry?serverVersion=15"

# run test suite with postgreSQL
$ vendor/bin/phpunit

The .env.local file can also be used to override the port of the database containers, if it does not meet your local requirements. You'll also need to override docker compose configuration:

Here is an example to use MySQL on port 3308:

# docker-compose.override.yml
version: '3.9'

services:
    mysql:
        ports:
            - "3308:3306"
# .env.local
DATABASE_URL="mysql://root:[email protected]:3308/foundry_test?serverVersion=5.7.42"

Credit

The AAA style of testing was first introduced to me by Adam Wathan's excellent Test Driven Laravel Course. The inspiration for this libraries API comes from Laravel factories and christophrumpel/laravel-factories-reloaded.

foundry's People

Contributors

abeal-hottomali avatar benblub avatar bfoks avatar chris53897 avatar dependabot[bot] avatar domagoj-orioly avatar gazzatav avatar gnito-org avatar hypemc avatar jdreesen avatar jmsche avatar jschaedl avatar kbond avatar kdederichs avatar ker0x avatar micheh avatar mpiot avatar mryamous avatar ndench avatar nicolasne avatar nikophil avatar northblue333 avatar nyholm avatar oskarstark avatar pavelmaca avatar seb-jean avatar tavoniievez avatar weaverryan avatar wouterj avatar zairigimad 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.