Answer the question
In order to leave comments, you need to log in
How to test a class that uses a Silex object?
Hello.
Faced the problem of writing unit tests for classes that use the Silex framework object. I can't figure out how to write a mock for it.
I have a class:
class ProjectHelper
{
private $app;
function __construct ( Application $app )
{
$this -> app = $app;
}
public function GetProjectList ()
{
...
$row = $this -> app['db'] -> fetchAll ( $query );
...
}
}
$appMock = $this -> getMockBuilder ( 'Silex\Application' )
-> disableOriginalConstructor ()
-> getMock ();
$appMock -> expects ( $this -> once () )
-> method ( 'fetchAll' )
-> will ( $this -> returnValue ( 1 ) );
Trying to configure method "fetchAll" which cannot be configured because it does not exist, has not been specified, is final, or is static
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question