Mocking Phalcon Classes

Are there any tools that can mock phalcon classes? I use codeception/aspectMock, but unless the method in question exists in my class (UserModels extends \Phalcon\Mvc\Model). So for example, I can't mock find, save, etc... because those typically arent in my extended classes.

I've seen a compiled extension in the past that looked capable of redifining ANY method calls... but cant remember the name.



5.8k

you should depend on abstraction than specific implementation, it should be easier for you to swap object during testing.



10.1k

Could you expound on this?



5.8k

for example creat interface for your models

<?php

interface MyModelInterface {
    public function save(MyModelInterface $model);
}

and implement it in your model

<?php

class MyModel extends Model Implement ModelInterface {
    public function save(MyModelInterface $model) {
        ...
    }
}

note: only use public method that defined in interface, this will allow you to create mock / double object based on interface