Skip to content

Conversation

@dereuromark
Copy link
Contributor

Summary

  • Add setConnection(string $connectionName) method to BaseFactory and EventCollector to allow factories to use a different database connection
  • This enables testing scenarios where entities need to be persisted to specific connections
  • Replace unset($this->table) with $this->table = null for consistency (as suggested in review)

Changes

  • Add connectionName property to EventCollector
  • Add setConnection() method to EventCollector and BaseFactory with fluent interface
  • Update getTable() to use custom connection when specified via ConnectionManager::get()
  • Add test_dummy connection config in bootstrap for testing
  • Add tests for setConnection functionality

Usage

// Set a custom connection for the factory
ArticleFactory::make()
    ->setConnection('other_database')
    ->persist();

// Works with chaining
ArticleFactory::make()
    ->setConnection('other_database')
    ->listeningToBehaviors('Sluggable')
    ->persist();

Test plan

  • Added tests for setConnection() method
  • Added tests for method chaining with setConnection()
  • All 437 existing tests pass
  • PHPStan passes
  • Code style passes

Based on PR #257 with review feedback addressed (using = null instead of unset()).

🤖 Generated with Claude Code

dereuromark and others added 12 commits November 6, 2025 00:46
FactoryTransactionStrategy to reset without $fixtures.
Clarified the description of generator type guessing.
Add setConnection() method to BaseFactory and EventCollector to allow
factories to use a different database connection. This enables testing
scenarios where entities need to be persisted to specific connections.

Changes:
- Add connectionName property to EventCollector
- Add setConnection() method to EventCollector and BaseFactory
- Update getTable() to use custom connection when specified
- Replace unset($this->table) with $this->table = null for consistency
- Add test_dummy connection config for testing
- Add tests for setConnection functionality

Based on PR vierge-noire#257 with review
feedback addressed (using = null instead of unset()).

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <[email protected]>
@codecov-commenter
Copy link

Welcome to Codecov 🎉

Once you merge this PR into your default branch, you're all set! Codecov will compare coverage reports and display results in all future pull requests.

Thanks for integrating Codecov - We've got you covered ☂️

@dereuromark
Copy link
Contributor Author

Oops, my bad: dereuromark#11

@dereuromark dereuromark deleted the feat/set-connection-name branch November 26, 2025 16:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants