I want to write an unit test for a method which is using private method getRandNumber()
. In my test getRandNumber()
should always return 1
.
How can I mock this method?
I've tried
$myModel = $this->createPartialMock(MyModel::class, ['getRandNumber']);
$reflector = new \ReflectionClass(MyModel::class);
$m = $reflector->getMethod('getRandNumber');
$m->setAccessible(true);
$myModel->method('getRandNumber')->willReturn(1);
getting error
[PHPUnit\Framework\Warning] Trying to configure method "getRandNumber" which cannot be configured because it does not exist, has not been specified, is final, or is static
Aucun commentaire:
Enregistrer un commentaire