Weave Code
Code Weaver
Helps Laravel developers discover, compare, and choose open-source packages. See popularity, security, maintainers, and scores at a glance to make better decisions.
Feedback
Share your thoughts, report bugs, or suggest improvements.
Subject
Message

Fixtures Bundle Laravel Package

davidbadura/fixtures-bundle

View on GitHub
Deep Wiki
Context7

Getting Started

Minimal Steps

  1. Installation Add the bundle to composer.json (despite being archived, it may still work for legacy projects):

    composer require davidbadura/fixtures-bundle
    

    Register the bundle in config/bundles.php:

    return [
        // ...
        DavidBadura\FixturesBundle\DavidBaduraFixturesBundle::class => ['all' => true],
    ];
    
  2. Basic Fixture File Create a YAML fixture (e.g., config/fixtures/users.yml):

    App\Entity\User:
      - { name: 'John Doe', email: 'john@example.com' }
    
  3. Load Fixtures Use the fixture:load command:

    php bin/console fixture:load
    
  4. Verify Check the database for the inserted records.


First Use Case

Populate a test database with seed data.

  • Define fixtures in YAML/JSON/TOML.
  • Load them via CLI or programmatically:
    $this->get('fixture.manager')->load('path/to/fixtures');
    

Implementation Patterns

Workflows

  1. Development Workflow

    • Store fixtures in config/fixtures/ (e.g., users.yml, posts.yml).
    • Use tags to group fixtures (e.g., tags: [users]), then load selectively:
      php bin/console fixture:load --tag=users
      
  2. Dependency Resolution Fixtures can reference each other (e.g., a Post fixture referencing a User):

    App\Entity\Post:
      - { title: 'Hello', author: '@user1' }  # Resolves to a User fixture
    
  3. Custom Converters Extend DavidBadura\FixturesBundle\Converter\ConverterInterface to handle custom logic (e.g., for setCreatedAt methods):

    class CustomDateConverter implements ConverterInterface {
        public function convert($value, $method, $object) {
            return new \DateTime($value);
        }
    }
    

    Register it in config/packages/david_badura_fixtures.yaml:

    david_badura_fixtures:
        converters:
            - App\Converter\CustomDateConverter
    
  4. Programmatic Loading Load fixtures in tests or migrations:

    $fixtureManager = $this->get('fixture.manager');
    $fixtureManager->load('path/to/fixtures');
    

Integration Tips

  • Faker Integration Use DavidBaduraFakerBundle for dynamic data:

    App\Entity\User:
      - { name: '<name>', email: '<email>' }
    
  • MongoDB Support Configure the bundle for MongoDB entities in config/packages/david_badura_fixtures.yaml:

    david_badura_fixtures:
        orm: false  # Disable Doctrine ORM
        odm: true    # Enable Doctrine ODM
    
  • Validation Enable validation in config to ensure fixtures meet entity constraints:

    david_badura_fixtures:
        validate: true
    

Gotchas and Tips

Pitfalls

  1. Archived Status The bundle is no longer maintained. Use Nelmio/Alice for new projects.

  2. Doctrine DBAL Dependency If using MongoDB, ensure david_badura_fixtures.orm is set to false to avoid conflicts.

  3. Bidirectional References Circular references (e.g., UserPost) may fail silently. Debug with:

    php bin/console debug:fixtures
    
  4. FakerBundle Dependency DavidBaduraFakerBundle is required for Faker placeholders (<name>, <email>). Install it separately:

    composer require davidbadura/faker-bundle
    

Debugging

  1. Dry Run Test fixtures without loading:

    php bin/console fixture:load --dry-run
    
  2. Verbose Output Enable debug mode for detailed logs:

    php bin/console fixture:load -vvv
    
  3. Event Listeners Override fixture loading via events (e.g., OnFixturesLoaded). Register in config/services.yaml:

    services:
        App\EventListener\FixturesListener:
            tags:
                - { name: kernel.event_listener, event: david_badura.fixtures.on_load, method: onFixturesLoad }
    

Extension Points

  1. Custom Fixture Formats Extend the bundle to support XML or CSV by implementing DavidBadura\FixturesBundle\Loader\LoaderInterface.

  2. Pre/Post-Load Hooks Use events to run logic before/after loading:

    // src/EventListener/FixturesListener.php
    public function onFixturesLoad(OnFixturesLoadEvent $event) {
        $fixtures = $event->getFixtures();
        // Modify fixtures dynamically
    }
    
  3. Override Default Converter Replace the default converter in config:

    david_badura_fixtures:
        default_converter: App\Converter\CustomConverter
    

Config Quirks

  1. Case-Sensitive Tags Fixture tags are case-sensitive. Use consistent casing (e.g., users, not Users).

  2. MongoDB Collection Names Ensure odm: true is set and collection names match your fixtures.

  3. Security Encoder For password hashing, configure the encoder in david_badura_fixtures.security.encoder. Example:

    david_badura_fixtures:
        security:
            encoder: App\Security\UserPasswordEncoder
    
Weaver

How can I help you explore Laravel packages today?

Conversation history is not saved when not logged in.
Prompt
Add packages to context
No packages found.
emuniq/filament-browser-notifications
syriable/filament-translator
hungnm28/livewire-form
wenprise/eloquent
crudly/encrypted
fadion/bouncy
cuci/prototurk-sdk
gos/pubsub-router-bundle
cuci/prototurk-sdk-symfony
clementtalleu/easyadmin-markdown-bundle
codeflextech/permission-manager
karnoweb/livewire-datepicker
sayedenam/sayed-dashboard
milito/query-filter
apiboxsym/user-bundle
apiboxsym/health-check-bundle
jayeshmepani/jpl-moshier-ephemeris-php
elnasnato/laraliveui
labrodev/rest-sdk
sampaui/sampaui