kreait / laravel-firebase

A Laravel package for the Firebase PHP Admin SDK

Home Page:https://github.com/kreait/firebase-php

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Cannot mock final class for phpunit tests as it's return type is other final class

hitrov opened this issue · comments

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