jeudi 2 novembre 2017

Mock Laravel's Config facade to return a value only for a certain key

I would like to mock Config::get('specific_key') to return a 'specific_value' in my test. So I wrote the following code:

Config::shouldReceive('get')
    ->with('specific_key')
    ->andReturn('specific_value');
Config::makePartial();

This will work: if I add dd(Config::get('specific_key')) I will receive 'specific_value'.

However, if I do dd(Config::get('another_key')), I don't receive any value (I guess because the mock doesn't expect this key as an argument).

So my question is: Is there a way to mock Config's get() method to return a specific value only for an specific key (and return normal value from the configuration file for any other key)?

Aucun commentaire:

Enregistrer un commentaire