Welcome Guest, Not a member yet? Register   Sign In
Mock models / controller methods in tests
#1

Hey!

I switched a while back from CI3 to CI4 but wasn't able to migrate my tests as I can't find a way to mock my models or even QueryBuilder like I did on CI3 with kenjis/ci-phpunit-test.
Is there any way to do something like that on CI4?

PHP Code:
$mock $this->getDouble(
    'PreferenceModel',
    ['getPreference' => new Preference([])]
);

$this->request->setCallable(
    function ($CI) use ($mock) {
        $CI->PreferenceModel $mock;
    }
); 
This code would mock $this->PreferenceModel in the controller.

Plus, is there any way to mock controller methods?
Reply
#2

I'm still looking for a solution
Reply
#3

In what context are you using it? Inside a controller? You can use PHPUnit's mock methods.
Reply




Theme © iAndrew 2016 - Forum software by © MyBB