You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository has been archived by the owner on Jan 29, 2020. It is now read-only.
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 a query 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
The text was updated successfully, but these errors were encountered:
Description of what I am trying to accomplish:
FOR UPDATE
statements in MariaDb / MySQL environments, one should still be able to inject an interface into their class objects.\Zend\Db\Adapter\Adapter
implements no such interface which defines aquery
methodCode to reproduce the issue
Expected results
query
defined so that it is a known accessible method. This will: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:->query
on a mocked instance of\Zend\Db\Adapter\AdapterInterface
The text was updated successfully, but these errors were encountered: