Skip to content

Instantly share code, notes, and snippets.

@h4cc
Last active May 5, 2017 23:05
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save h4cc/6595865 to your computer and use it in GitHub Desktop.
Save h4cc/6595865 to your computer and use it in GitHub Desktop.
If you get this message from PHPUnit: 'Class "Doctrine\ORM\Query" is declared "final"' Check out the following code:
<?php
// Use the Abstract query, which has nearly all needed Methods as the Query.
$this->queryMock = $this->getMockBuilder('\Doctrine\ORM\AbstractQuery')
->setMethods(array('setParameter', 'getResult'))
->disableOriginalConstructor()
->getMockForAbstractClass();
@samsonasik
Copy link

you save my life, thank you very much for the share ;)

@KonovalovMaxim
Copy link

It will not work with Doctrine\ORM\Tools\Pagination\Paginator because of type hinting on the method cloneQuery

@andrewmatthews
Copy link

Unfortunately this will not work if you need to interact with the Query::setFirstResult() or Query::setMaxResults() methods as they do not exist on AbstractQuery.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment