Skip to content
forked from zenstruck/foundry

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

License

Notifications You must be signed in to change notification settings

GrinWay/foundry

This branch is 1 commit ahead of, 54 commits behind zenstruck/foundry:2.x.

Folders and files

NameName
Last commit message
Last commit date

Latest commit

80b2506 Â· Dec 17, 2024
Dec 14, 2024
Dec 14, 2024
Oct 23, 2024
Dec 17, 2024
Jun 7, 2024
Dec 14, 2024
Dec 14, 2024
Dec 16, 2024
Oct 22, 2024
Jun 25, 2021
Aug 20, 2021
Dec 11, 2024
Mar 25, 2024
Dec 11, 2024
Nov 7, 2023
Jun 7, 2024
Dec 12, 2024
Jan 16, 2024
Dec 11, 2024
Nov 5, 2024
Dec 12, 2024
Jun 6, 2024
Dec 14, 2024
Dec 14, 2024
Dec 11, 2024
Dec 14, 2024
Dec 11, 2024
Oct 22, 2024

Repository files navigation

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 Upgrade guide to v2

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 main testsuite (with "schema" reset database strategy)
$ composer test-schema
# or
$ ./phpunit

# run "migrate" testsuite (with "migrate" reset database strategy)
$ composer test-migrate
# or
$ ./phpunit --testsuite migrate --bootstrap tests/bootstrap-migrate.php

Overriding the default configuration

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

# .env.local

# change the database to postgreSQL...
DATABASE_URL="postgresql://zenstruck:zenstruck@127.0.0.1:5433/zenstruck_foundry?serverVersion=15"
# ...or to SQLite
DATABASE_URL="sqlite:///%kernel.project_dir%/var/data.db"

MONGO_URL="" # disables Mongo
USE_DAMA_DOCTRINE_TEST_BUNDLE="1" # enables dama/doctrine-test-bundle
PHPUNIT_VERSION="11" # possible values: 9, 10, 11, 11.4

# test reset database with configuration migration, 
# only relevant for "migrate" testsuite
WITH_MIGRATION_CONFIGURATION_FILE="tests/Fixture/MigrationTests/configs/migration-configuration.php" 

# 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:1234@127.0.0.1:3308/foundry_test?serverVersion=5.7.42"

Running the documentation linter locally

This section provides guidance on how to run the documentation linter, contained within a Docker image, locally on your machine. This linter is designed to verify and ensure that the document syntax adheres to the required standards.

The following command runs the linter in the local directory:

docker run --rm -it -e DOCS_DIR='/docs' -v ${PWD}/docs:/docs  oskarstark/doctor-rst:latest

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.

About

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

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • PHP 99.5%
  • Shell 0.5%