I have a my controller class like below
Class UserController {
public function getName(){
return "test_name"
}
public function hello(){
return getName()."!"
}
}
An accompanying unit test as seen below
use PHPUnit\Framework\TestCase;
use App\Http\Controllers\API\User\UserController;
class UserTest extends TestCase{
public function testExample(){
$mockGetName = $this->getMockBuilder(UserController::class)->onlyMethods(['getName'])->getMock();
$mockGetName->method('getName')->willReturn("dummy");
$userController = new $mockGetName();
dump($userController->getName("test name"));
}
}
When mocked getName() returns null
instead of "dummy". Anyone have any idea why the specified return value is not being returned?