-
Notifications
You must be signed in to change notification settings - Fork 2
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
Make DB connection name configurable #14 #23
Conversation
``connection_name`` is not common among all sensors.
…getSetting() This will prevent the creation of redundant boiler plate code in sensors.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks ❤️, @liviascapin
Please have a look at my changes and add some tests indicated by the @todo
annotations.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe you could help me figure out how to test this method :) If you want, you can write the test yourself and merge the branch. Or we can wait until I'm back.
* @return string The name of the connection to check. | ||
* @todo Cover by a test. | ||
*/ | ||
protected function _getSetting(string $name, $default = null): string |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@ravage84 I'm not sure how to test this.
Maybe it should be public? Or maybe you have an idea on how to test it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No, it doesn't need to. Sure it would make testing easier, but code doesn't need to change just for the sake of testability.
This can be tested by a test dummy. A class that extends Sensor
and then implements a public method which simply calls _getSettings()
and returns it.
This public method can be called in the test case and its return value be assserted. The to-be-asserted value can be put into the configuration, beforehand, naturally.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
On a second thought, we might want to move this method to the Config
class and make it public. This way the code is where it should be AND is easier testable... Let's discuss this tomorow.
@@ -60,6 +73,7 @@ public function testDefaultConfig() | |||
$this->assertEquals(true, $sensorConfig->getEnabled()); | |||
$this->assertEquals(2, $sensorConfig->getSeverity()); | |||
$this->assertEquals(null, $sensorConfig->getClass()); | |||
$this->assertEquals([], $sensorConfig->getSettings()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This test is fine, but I think we should test the individual methods in their own test cases, too.
I'll do that once we merged this.
@ravage84 I tried implementing your suggestion in #14, please take a look 😇
Closes #14