Add public getDsn method to adapters for unit testing constructed DSN strings
Nobody has claimed this yet.
- Dominant language
- PHP
- Stars
- 4.5k
- Forks
- 884
- PR merge metrics
- No merged PRs in 30d
Description
For each adapter, there's a handful of ways to customize the DSN string we generate that is passed to PDO. However, there's not currently a good way we have to test that said behavior is correct / good and so we have some nonsensical tests like:
Was unsetting the port meaningful? Who knows!
While we could maybe get what we want out of some level of reflection / mocking around the protected createPdoConnection method, that should be avoided if possible.
Instead, having a getDsn method that returns a string instead would more easily solve the problem, and allow for best practices around unit testing these things, and ensure behavior is good and correct. It's possible that said method could also be useful to someone downstream, but I'm not overly concerned at the moment with that.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with the protected createPdoConnection method in src/Phinx/Db/Adapter/PdoAdapter.php and the example in tests/Phinx/Db/Adapter/SqlServerAdapterTest.php. Review how each adapter constructs its DSN, then add focused tests that verify the returned strings for customization options. Done means the adapter behavior is testable without reflection or mocking the PDO connection.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- php
- Domain
- databases, testing
- Issue type
- Feature
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 45/100