Expects not functioning
Hi,
I am new to BrainMonkey and I am just hitting a problem within my test script. I am using this code below to test WordPress function get_option().
Functions\expect('get_option')->once()->andReturnNull();
Once I run my test, It will show the error:
1) Javagee\OptionTest::test_construct
Mockery\Exception\InvalidCountException: Method get_option(<Any Arguments>) from Mockery_0 should be called
exactly 1 times but called 0 times.
If I used this code, my test script will pass.
Functions\when('get_option')->justReturn(true);
I noticed that method get_option is not being called for Function\expect.
My Setup below:
"require-dev": {
"phpunit/phpunit": "7.2.*",
"spatie/phpunit-snapshot-assertions": "2.0.*",
"antecedent/patchwork": "^2.0"
},
"require": {
"php": ">=5.6",
"brain/monkey": "2.4.0",
"composer/installers": "~1.0",
"mmamedov/page-cache": "^2.0"
},
Any advise or to point me in the right direction will very much appreciated.
Thanks in advanced.
Gerard
@javagee In case of the when function usage, it let you pass the test because there's no expectation, so even if the get_option is not called it does not matter.
Could you paste your test and the code which represent the subject under test?
@javagee What Guido said.
when only enforces that when the function is called, it will return true. But if it is not called... nothing happens.
Using expect, you're instead saying that you want to test that executing the code that exists after the expectation, get_option is called exactly once. But I'm guessing that does not happen, so the test fail as it is supposed to fail.