Cannot mock final class for phpunit tests as it's return type is other final class
hitrov opened this issue · comments
Alexander Hitrov commented
Describe the bug
there's a final class
Auth implements Kreait\Firebase\Contract\Auth
which you cannot mock.
interface is used to create an instance upon dependency injection,
and there's no problem to create Mock class which also implements it and use during testing.
problem is that some of the methods have return type of class (not interface!) which is also final, like
public function getUserByEmail(Stringable|string $email): UserRecord;
so that you're getting
Class "Kreait\Firebase\Auth\UserRecord" is declared "final" and cannot be doubled
Installed packages
kreait/laravel-firebase 5.6.0
phpunit/phpunit 9.6.16
PHP version and extensions
8.2
Steps to reproduce the issue.
$this->createMock(Kreait\Firebase\Contract\Auth::class);
Error message/Stack trace
Class "Kreait\Firebase\Auth\UserRecord" is declared "final" and cannot be doubled
Additional information
No response
Jérôme Gamez commented