AdapterInterface does not define query as a method
Opened this issue · 1 comments
dfelton commented
- I was not able to find an open or closed issue matching what I'm seeing.
- This is not a question. (Questions should be asked on slack (Signup for Slack here) or our forums.)
Description of what I am trying to accomplish:
- Given the recommendation here to fall back to manual sql using the adapter in order to accomplish
FOR UPDATE
statements in MariaDb / MySQL environments, one should still be able to inject an interface into their class objects. - The
\Zend\Db\Adapter\Adapter
implements no such interface which defines aquery
method
Code to reproduce the issue
class FooBar
{
/**
* @var \Zend\Db\Adapter\AdapterInterface
*/
private $adapter;
public function __construct(
\Zend\Db\Adapter\AdapterInterface $adapter
) {
$this->adapter = $adapter
}
public function getRecordById(int $id): \ArrayObject
{
/**
* @var \Zend\Db\ResultSet\ResultSet $resultSet
*/
$resultSet = $this->adapter->query('SELECT * FROM foo_bar WHERE id = :id FOR UPDATE', ['id' => $id]);
return $resultSet->current();
}
}
Expected results
- AdapterInterface should have
query
defined so that it is a known accessible method. This will:- Allow for DI replacement in applications that may require such things
- Allow for mocking of the Interface in order to accomplish unit testing of the class
Actual results
Since (in my application) \Zend\Db\Adapter\Adapter
is the concrete class that is injected at run time, the method still works. However this leads to:
- IDE shows an error as it is not a known method of the interface
- Inability to properly unit test the class since I cannot call
->query
on a mocked instance of\Zend\Db\Adapter\AdapterInterface
weierophinney commented
This repository has been closed and moved to laminas/laminas-db; a new issue has been opened at laminas/laminas-db#1.