Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add public getDsn method to adapters for unit testing constructed DSN strings #2095

Open
MasterOdin opened this issue May 21, 2022 · 0 comments
Labels

Comments

@MasterOdin
Copy link
Member

MasterOdin commented May 21, 2022

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:

public function testConnectionWithoutPort()
{
$options = $this->adapter->getOptions();
unset($options['port']);
$this->adapter->setOptions($options);
$this->assertInstanceOf('PDO', $this->adapter->getConnection());
}

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant