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

Bdf Phpunit Laravel Package

b2pweb/bdf-phpunit

Laravel/PHPUnit helper package for working with BDF/SEPA bank files in tests. Provides utilities and test assertions to validate BDF structures and parsing results, making it easier to write reliable unit tests around banking file imports.

View on GitHub
Deep Wiki
Context7

Getting Started

Minimal Setup

  1. Installation

    composer require --dev b2pweb/bdf-phpunit
    

    Add the trait to your test class:

    use B2PWeb\BDF\PHPUnit\BDFTestCase;
    
    class ExampleTest extends BDFTestCase
    {
        // Your tests
    }
    
  2. First Use Case Use the built-in assertions for BDF (Business Data Framework) validation:

    public function testValidation()
    {
        $this->assertBDFValid($this->createBDFModel(), 'model');
    }
    
  3. Key Files to Explore

    • src/BDFTestCase.php (Core trait with assertions)
    • src/Assertions/BDFAssertions.php (Custom assertions)
    • tests/ (Example test cases in the package)

Implementation Patterns

Common Workflows

  1. Model Validation Testing

    public function testModelValidation()
    {
        $model = $this->createBDFModel(['invalid_field' => 'value']);
        $this->assertBDFInvalid($model, 'model', [
            'invalid_field' => 'The invalid field is required.'
        ]);
    }
    
  2. BDF Rule Testing

    public function testCustomRule()
    {
        $this->assertBDFRuleValid('custom_rule', ['input' => 'value']);
        $this->assertBDFRuleInvalid('custom_rule', ['input' => 'invalid']);
    }
    
  3. Integration with Laravel Use the trait in Laravel’s TestCase:

    use Illuminate\Foundation\Testing\TestCase as BaseTestCase;
    use B2PWeb\BDF\PHPUnit\BDFTestCase;
    
    class BDFTest extends BaseTestCase
    {
        use BDFTestCase;
    }
    
  4. Mocking BDF Services

    public function testServiceInteraction()
    {
        $mock = $this->mockBDFService('MyService');
        $mock->shouldReceive('doSomething')->once();
    
        $this->assertBDFServiceResponse($mock, 'doSomething');
    }
    

Integration Tips

  • Custom Assertions: Extend BDFAssertions to add domain-specific checks.
  • BDF Config: Use config('bdf') in tests if the package relies on BDF’s config.
  • Database Testing: Combine with Laravel’s DatabaseTransactions for BDF-backed models.

Gotchas and Tips

Pitfalls

  1. Assertion Naming Conflicts Avoid naming custom assertions assertBDF* to prevent collisions with the package’s methods.

  2. Missing BDF Context Ensure BDF’s service container is bootstrapped before running tests (e.g., in setUp()):

    public function setUp(): void
    {
        parent::setUp();
        $this->app->make('bdf');
    }
    
  3. Overly Strict Validation The package defaults to strict validation. Use assertBDFValidRelaxed() for partial checks:

    $this->assertBDFValidRelaxed($model, ['field1', 'field2']);
    

Debugging Tips

  • Enable BDF Logging Add to config/logging.php:

    'channels' => [
        'bdf' => [
            'driver' => 'single',
            'path' => storage_path('logs/bdf.log'),
            'level' => 'debug',
        ],
    ],
    

    Then use:

    $this->enableBDFLogging();
    
  • Inspect Validation Rules Dump rules for a model:

    $this->dumpBDFRules($model);
    

Extension Points

  1. Custom Assertions Add to BDFTestCase:

    use B2PWeb\BDF\PHPUnit\Assertions\BDFAssertions;
    
    class CustomBDFTest extends BDFTestCase
    {
        use BDFAssertions;
    
        protected function assertCustomBDFRule($rule, $data, $message = '')
        {
            // Custom logic
        }
    }
    
  2. Override Default Assertions Extend BDFAssertions and bind it in setUp():

    $this->assertions = new CustomBDFAssertions();
    
  3. BDF Event Testing Listen for BDF events in tests:

    $this->assertBDFEventDispatched('bdf.model.validated', function ($event) {
        $this->assertEquals('model_id', $event->model->id);
    });
    
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.
terminal42/code-quality-tools
codifyo/ts-generator-bundle
andydefer/laravel-cluster
testo/fiber
mintobit/jobqueue
a4sex/maintenance-bundle
a4sex/entity-date-update
a4sex/client-identifier
a4sex/base-utilites
a4sex/key-value-storage
a4sex/micro-status
chilldev/dependency-injection-extra
datinglibre/datinglibre-app-api
biberltd/corebundle
bricre/symfony-bundle-test
biberltd/logbundle
dominium/http-adapter-bundle
dominium/google-analytics
a4sex/auto-clean-entity
christhompsontldr/laravel-inky