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)?
You don't have to mock Config, you can use Config::set()
to set any value in Config. So Config::set('specific_key', 'specific_value');
in the test instead of creating the mock should work
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With