php-mock-mockery icon indicating copy to clipboard operation
php-mock-mockery copied to clipboard

Mocking json_decode

Open markmontes17 opened this issue 3 years ago • 1 comments

Is it possible to use the mocked json_decode for unit testing SomeClass::someMethod? Where in someMethod() contains json_decode?

Summarized code snippet:

test Method: PHPMockery::mock(NAMESPACE, "json_decode") ->andReturn("test");

$classMock = new SomeClass(); $actual = $classMock->someMethod(); $this->assertEquals("test", $actual);

SomeClass::someMethod: // codes here $var = json_decode($str); // codes here

markmontes17 avatar Apr 29 '22 04:04 markmontes17