Skip to content
This repository has been archived by the owner on Jan 29, 2020. It is now read-only.

AdapterInterface does not define query as a method #398

Open
2 tasks done
dfelton opened this issue Oct 24, 2019 · 1 comment
Open
2 tasks done

AdapterInterface does not define query as a method #398

dfelton opened this issue Oct 24, 2019 · 1 comment

Comments

@dfelton
Copy link

dfelton commented Oct 24, 2019

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 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
@weierophinney
Copy link
Member

This repository has been closed and moved to laminas/laminas-db; a new issue has been opened at laminas/laminas-db#1.

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

No branches or pull requests

2 participants