From ee21c34fbbf278f11172e8a4bbc08c37e3d444f8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=B4me=20Gamez?= Date: Fri, 15 Nov 2024 10:53:05 +0100 Subject: [PATCH] Always get a fresh AppInstance instance when testing topic subscriptions --- .../Integration/Messaging/AppInstanceTest.php | 27 +++++++++++++------ 1 file changed, 19 insertions(+), 8 deletions(-) diff --git a/tests/Integration/Messaging/AppInstanceTest.php b/tests/Integration/Messaging/AppInstanceTest.php index b94ccd87..3b7ea387 100644 --- a/tests/Integration/Messaging/AppInstanceTest.php +++ b/tests/Integration/Messaging/AppInstanceTest.php @@ -5,6 +5,7 @@ namespace Kreait\Firebase\Tests\Integration\Messaging; use Kreait\Firebase\Contract\Messaging; +use Kreait\Firebase\Messaging\AppInstance; use Kreait\Firebase\Messaging\RegistrationToken; use Kreait\Firebase\Tests\IntegrationTestCase; use PHPUnit\Framework\Attributes\Test; @@ -37,18 +38,28 @@ public function itIsSubscribedToTopics(): void $this->messaging->subscribeToTopic($secondTopic, RegistrationToken::fromValue($token)); // Lazy registration token test $this->messaging->subscribeToTopic($thirdTopic, $token); - $instance = $this->messaging->getAppInstance($token); - - $this->assertTrue($instance->isSubscribedToTopic($firstTopic)); - $this->assertTrue($instance->isSubscribedToTopic($secondTopic)); + $this->assertTrue($this->appInstance($token)->isSubscribedToTopic($firstTopic)); + $this->assertTrue($this->appInstance($token)->isSubscribedToTopic($secondTopic)); + $this->assertTrue($this->appInstance($token)->isSubscribedToTopic($thirdTopic)); $this->messaging->unsubscribeFromTopic($firstTopic, $token); + $this->assertFalse($this->appInstance($token)->isSubscribedToTopic($firstTopic)); + $this->assertTrue($this->appInstance($token)->isSubscribedToTopic($secondTopic)); + $this->assertTrue($this->appInstance($token)->isSubscribedToTopic($thirdTopic)); + $this->messaging->unsubscribeFromTopic($secondTopic, $token); - $this->messaging->unsubscribeFromAllTopics($token); + $this->assertFalse($this->appInstance($token)->isSubscribedToTopic($secondTopic)); + $this->assertTrue($this->appInstance($token)->isSubscribedToTopic($thirdTopic)); - $instance = $this->messaging->getAppInstance($token); + $this->messaging->unsubscribeFromAllTopics($token); + $this->assertFalse($this->appInstance($token)->isSubscribedToTopic($thirdTopic)); + } - $this->assertFalse($instance->isSubscribedToTopic($firstTopic)); - $this->assertFalse($instance->isSubscribedToTopic($secondTopic)); + /** + * @param non-empty-string $registrationToken + */ + private function appInstance(string $registrationToken): AppInstance + { + return $this->messaging->getAppInstance($registrationToken); } }