Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement Test with FirebaseFactory. #53

Closed
mahdiaslami opened this issue Aug 26, 2020 · 3 comments
Closed

Implement Test with FirebaseFactory. #53

mahdiaslami opened this issue Aug 26, 2020 · 3 comments

Comments

@mahdiaslami
Copy link

mahdiaslami commented Aug 26, 2020

I Searched in kreait\firebase-php package i found it use Kreait\Firebase\Factory in IntegerationTestCase class and used it to test. (For example test subscriteToTopic method in FirebaseMessaging class).

Is it possible to adding fake method to FirebaseMessaging facade and other facades for mocking and used it in test like MailFake class in laravel.

Example change in FirebaseMessaging facade:

/**
 * @see \Kreait\Firebase\Messaging
 */
final class FirebaseMessaging extends Facade
{
    /**
     * Replace the bound instance with a fake.
     *
     * @return \Illuminate\Support\Testing\Fakes\MailFake
     */
    public static function fake()
    {
        static::swap($fake = (new FirebaseFactory())->createMessaging());

        return $fake;
    }

    protected static function getFacadeAccessor()
    {
        return 'firebase.messaging';
    }
}

Example test for an API:

/** @test */
public function subscribe_temp_topic()
{
    FirebaseMessaging::fake();

    $body = [
        'topic' => 'temp',
        'fcmToken' => 'token'
    ];

    $this->post('/subscribe', $body, $this->defaultHeaders)
        ->seeStatusCode(200)
        ->seeJsonContains([
            "results" => [[]]
        ]);
}

I test and it work prefect. Is it good way for creating test??

@github-actions
Copy link
Contributor

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

@github-actions
Copy link
Contributor

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

@github-actions github-actions bot added the Stale label Dec 26, 2020
@github-actions github-actions bot closed this as completed Jan 2, 2021
@jeromegamez jeromegamez removed the Stale label Jan 2, 2021
@jeromegamez jeromegamez reopened this Jan 2, 2021
@jeromegamez
Copy link
Member

Hey, and sorry for the late reply! I haven't really worked with Laravel's fakes in the past, so I understand the principle, but could you please explain a little more in detail how $fake = (new FirebaseFactory())->createMessaging() is a fake? For me it looks as if this still creates the Messaging component from an uncounfigured Factory (and so would still make "real" requests to the Firebase APIs... 🤔

@jeromegamez jeromegamez closed this as not planned Won't fix, can't repro, duplicate, stale Sep 23, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants