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

Alice Bundle Laravel Package

hautelook/alice-bundle

View on GitHub
Deep Wiki
Context7

Getting Started

Minimal Setup

  1. Install the Bundle

    composer require hautelook/alice-bundle --dev
    

    Register in config/bundles.php (Symfony 4+):

    Hautelook\AliceBundle\HautelookAliceBundle::class => ['dev' => true],
    
  2. Enable Fixtures Add to config/packages/hautelook_alice.yaml:

    hautelook_alice:
        connection: default # Your Doctrine connection
        locale: en_US       # Default locale for Faker
    
  3. First Fixture Create a YAML file (e.g., config/fixtures/users.yml):

    App\Entity\User:
        user{1..10}:
            email: '<email>'
            username: '<userName>'
            roles: ['ROLE_USER']
    

    Load fixtures via CLI:

    php bin/console hautelook:fixtures:load
    
  4. Verify Check database records or use:

    php bin/console hautelook:fixtures:show
    

First Use Case: Local Development

  • Scenario: Populate a posts table with 50 test records for frontend testing.
  • Steps:
    1. Define config/fixtures/posts.yml:
      App\Entity\Post:
          post{1..50}:
              title: '<sentence>'
              content: '<paragraph>'
              publishedAt: '<dateTimeBetween>-1 year'
              author: '@user*' # Reference existing 'user' fixture
      
    2. Load fixtures:
      php bin/console hautelook:fixtures:load --env=dev
      
    3. Test locally without touching production data.

Implementation Patterns

Workflows

1. Fixture Organization

  • Modular Fixtures: Split fixtures by entity/domain (e.g., users.yml, posts.yml, orders.yml).
  • Dependencies: Use @entity syntax to reference other fixtures (e.g., @user* for random users).
  • Example:
    # config/fixtures/ecommerce.yml
    App\Entity\Order:
        order{1..20}:
            user: '@user*'
            items:
                - { product: '@product*', quantity: '<numberBetween(1,5)>', price: '<randomFloat(2,10,50)>' }
    

2. Environment-Specific Fixtures

  • Use --env flag to load different fixtures per environment:
    # Load minimal data for CI
    php bin/console hautelook:fixtures:load --env=test
    
    # Load full data for local dev
    php bin/console hautelook:fixtures:load --env=dev
    
  • Override fixture paths in config/packages/hautelook_alice.yaml:
    hautelook_alice:
        fixtures: ['%kernel.project_dir%/config/fixtures/{env}.yml']
    

3. Dynamic Data with Faker

  • Leverage Faker’s methods for realistic data:
    App\Entity\Product:
        product{1..100}:
            name: '<commerceProductName>'
            price: '<randomFloat(2,10,1000)>'
            sku: '<isbn13>'
            description: '<paragraphs(3, true)>'
    
  • Custom Faker Providers: Extend Faker for domain-specific data:
    // src/Faker/Provider/AppProvider.php
    namespace App\Faker\Provider;
    
    use Faker\Provider\Base;
    
    class AppProvider extends Base {
        public function fakeAppData() {
            return 'custom_' . $this->word;
        }
    }
    
    Register in config/packages/hautelook_alice.yaml:
    hautelook_alice:
        faker:
            providers: ['App\Faker\Provider\AppProvider']
    

4. Seeding Workflow

  • Pre-Deployment: Load fixtures in phpunit.xml for consistent test environments:
    <env name="KERNEL_CLASS" value="App\Kernel"/>
    <env name="APP_ENV" value="test"/>
    <php>
        <env name="SYMFONY_DEPRECATIONS_HELPER" value="weak"/>
        <file>vendor/autoload.php</file>
        <file>config/bootstrap.php</file>
        <include file="config/packages/test/_fixtures.php"/>
        <exec dir="." command="php bin/console hautelook:fixtures:load --env=test --append"/>
    </php>
    

Integration Tips

Doctrine Events

  • Trigger actions after fixture loading (e.g., generate slugs):
    # config/fixtures/posts.yml
    App\Entity\Post:
        post{1..10}:
            title: '<sentence>'
            slug: ~ # Will be set via Doctrine lifecycle
    
    Add a subscriber:
    // src/EventSubscriber/FixtureSubscriber.php
    namespace App\EventSubscriber;
    
    use Doctrine\Common\EventSubscriber;
    use Doctrine\ORM\Event\LifecycleEventArgs;
    use Doctrine\ORM\Events;
    
    class FixtureSubscriber implements EventSubscriber {
        public function getSubscribedEvents() {
            return [Events::postPersist];
        }
    
        public function postPersist(LifecycleEventArgs $args) {
            $entity = $args->getObject();
            if ($entity instanceof \App\Entity\Post && empty($entity->getSlug())) {
                $entity->setSlug(\Ramsey\Uuid\Uuid::uuid4()->toString());
            }
        }
    }
    

Custom Fixture Loaders

  • Extend Alice\Loader\NativeLoader for custom logic:
    // src/Loader/CustomLoader.php
    namespace App\Loader;
    
    use Alice\Loader\NativeLoader;
    use Doctrine\Common\Persistence\ObjectManager;
    
    class CustomLoader extends NativeLoader {
        protected function getObjectManager(): ObjectManager {
            $om = parent::getObjectManager();
            // Custom logic (e.g., set default tenant)
            return $om;
        }
    }
    
    Configure in config/packages/hautelook_alice.yaml:
    hautelook_alice:
        loader: App\Loader\CustomLoader
    

Gotchas and Tips

Pitfalls

  1. Fixture Order Dependencies

    • Issue: Loading posts.yml before users.yml fails if Post references User.
    • Fix: Use --append to load incrementally or define a clear order in config/packages/hautelook_alice.yaml:
      hautelook_alice:
          fixtures_order: ['users.yml', 'posts.yml', 'orders.yml']
      
  2. Faker Locale Mismatch

    • Issue: <address> generates invalid data in non-English locales.
    • Fix: Set the correct locale in hautelook_alice.yaml or override per fixture:
      hautelook_alice:
          locale: fr_FR
      
      Or use Faker’s locale methods:
      App\Entity\User:
          user{1..5}:
              address: '<address>'
              # Override locale for this field
              phone: '<phoneNumber>@fr' # French phone number
      
  3. Circular References

    • Issue: @post* in users.yml and @user* in posts.yml causes infinite loops.
    • Fix: Use * sparingly or limit references with min/max:
      App\Entity\User:
          user{1..10}:
              posts: '@post{1..3}' # Reference 1-3 posts
      
  4. Doctrine Proxy Classes

    • Issue: Fixtures fail if proxies are enabled but lazy-loading triggers.
    • Fix: Disable proxies for fixtures or use ORM\AbstractQuery::HYDRATE_ARRAY:
      // In CustomLoader
      $query->setHydrationMode(\Doctrine\ORM\Query::HYDRATE_ARRAY);
      
  5. Unique Constraints

    • Issue: <email> duplicates violate UNIQUE constraints.
    • Fix: Use Faker’s unique methods or custom providers:
      App\Entity\User:
          user{1..10}:
              email: '<uniqueEmail>'
      

Debugging

  1. Dry Run Mode

    • Preview fixtures without loading:
      php bin/console hautelook:fixtures:load --dry-run
      
  2. Verbose Output

    • Enable debug mode for detailed logs:
      php bin/console hautelook:fixtures:load -vvv
      
  3. Fixture Validation

    • Validate YAML syntax with:
      php bin/console debug:container --parameters
      
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.
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
babelqueue/php-sdk
facebook/capi-param-builder-php
babelqueue/symfony
hamzi/corewatch
minionfactory/raw-hydrator
hexters/coinpayment
rjcodes/rjcms
act-training/laravel-permissions-manager
alimarchal/laravel-chart-of-accounts
babenkoivan/elastic-scout-driver