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

Auto Form Fill Bundle Laravel Package

appventus/auto-form-fill-bundle

View on GitHub
Deep Wiki
Context7

Getting Started

Minimal Setup

  1. Installation:

    composer require-dev appventus/auto-form-fill-bundle
    

    Add to AppKernel.php (Symfony 2.x):

    if (in_array($this->getEnvironment(), ['dev'])) {
        $bundles[] = new AppVentus\AutoFormFillBundle\AvAutoFormFillBundle();
    }
    
  2. First Use Case:

    • Navigate to any form in your development environment (e.g., http://your-app.dev/user/new).
    • The bundle will automatically populate fields with fake data (via Faker) for testing.
    • No configuration required—just enable the bundle and test forms in dev mode.

Implementation Patterns

Workflow Integration

  1. Dev-Only Activation:

    • Only enabled in dev environment (via AppKernel). Disable in prod/test to avoid side effects.
  2. Form Field Handling:

    • The bundle dynamically injects fake data into form fields (text, email, dates, etc.).
    • Works with Symfony’s FormType components (e.g., TextType, DateType).
    • Exclude sensitive fields by prefixing them with av_autoformfill_skip (e.g., password, token).
  3. Testing Workflow:

    • Manual Testing: Quickly test form submissions without manual data entry.
    • Automated Tests: Use alongside PHPUnit for form-related tests (e.g., validation, submission flows).
    • Edge Cases: Test required fields, validation rules, and complex forms (e.g., nested collections).
  4. Customization:

    • Override fake data logic by extending the bundle’s FormFiller service (see Gotchas for details).
    • Example: Add custom providers to services.yml:
      services:
          av_autoformfill.form_filler:
              arguments:
                  - ['@custom_faker_provider']
      

Gotchas and Tips

Pitfalls

  1. Environment Leaks:

    • Never enable in production—the bundle is dev-only by design. Use a feature flag or CI checks to prevent accidental activation.
  2. Field Selection Issues:

    • The bundle skips hidden fields by default. If you need to test hidden fields (e.g., CSRF tokens), override the FormFiller class to include them:
      // src/AppVentus/AutoFormFillBundle/DependencyInjection/Compiler/FakerPass.php
      public function process(ContainerBuilder $container) {
          $definition = $container->findDefinition('av_autoformfill.form_filler');
          $definition->replaceArgument(0, ['@faker', '@custom_provider']);
      }
      
  3. Faker Limitations:

    • Default Faker providers may not cover all field types (e.g., custom EntityType fields).
    • Solution: Extend the FormFiller service to handle custom types:
      class CustomFormFiller extends FormFiller {
          protected function getFakeDataForType($type, $options) {
              if ($type === 'custom_entity') {
                  return $this->faker->randomElement(['value1', 'value2']);
              }
              return parent::getFakeDataForType($type, $options);
          }
      }
      
  4. Symfony 3+/4+ Compatibility:

    • The bundle is archived and targets Symfony 2.1. For newer versions:
      • Fork the repo and update dependencies (e.g., symfony/form to ^4.0).
      • Replace AppKernel registration with config/bundles.php:
        if ($_ENV['APP_ENV'] === 'dev') {
            return [AvAutoFormFillBundle::class];
        }
        

Debugging Tips

  1. Verify Activation:

    • Check if the bundle is loaded in dev mode by inspecting the Symfony profiler or logs.
    • Look for AutoFormFillBundle in php bin/console debug:container | grep autoformfill.
  2. Log Fake Data:

    • Enable debug mode (APP_DEBUG=1) to see which fields are being filled:
      // In a controller or event subscriber
      $this->get('av_autoformfill.form_filler')->debugMode(true);
      
  3. Exclude Specific Forms:

    • Skip auto-filling for certain forms by adding a class or attribute:
      #[AutoFormFillSkip]
      class MyFormType extends AbstractType { ... }
      
      (Requires extending the bundle’s compiler pass.)

Extension Points

  1. Custom Faker Providers:

    • Add providers to the FormFiller service:
      # config/services.yaml
      services:
          custom.faker.provider:
              class: App\Service\CustomFakerProvider
              tags:
                  - { name: av_autoformfill.faker_provider }
      
  2. Event Listeners:

    • Hook into form events to modify behavior:
      // src/EventListener/AutoFormFillListener.php
      class AutoFormFillListener {
          public function onFormPreSetData(FormEvent $event) {
              if ($event->getForm()->getConfig()->getType()->getName() === 'app_custom_form') {
                  $event->setData(['custom_field' => 'hardcoded_value']);
              }
          }
      }
      
      Register the listener in services.yaml:
      services:
          App\EventListener\AutoFormFillListener:
              tags:
                  - { name: kernel.event_listener, event: form.PRE_SET_DATA, method: onFormPreSetData }
      
  3. Configuration Overrides:

    • Override default settings via config/packages/av_autoformfill.yaml:
      av_autoformfill:
          skip_fields: ['password', 'token', 'av_autoformfill_skip_*']
          debug: '%kernel.debug%'
      
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.
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
mkwebdesign/filament-watchdog-v5
renatomarinho/laravel-page-speed
zedmagdy/filament-business-hours