Skip to content

Commit

Permalink
Always get a fresh AppInstance instance when testing topic subscriptions
Browse files Browse the repository at this point in the history
  • Loading branch information
jeromegamez committed Nov 15, 2024
1 parent 608887d commit ee21c34
Showing 1 changed file with 19 additions and 8 deletions.
27 changes: 19 additions & 8 deletions tests/Integration/Messaging/AppInstanceTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
}
}

0 comments on commit ee21c34

Please sign in to comment.