Something went wrong. Try again.
Build Reactive Signals for Bluesky's AT Protocol Firehose in Laravel
Something went wrong. Try again.
3.4 kB · 135 lines
PHP
at dev
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136<?php
namespace SocialDept\AtpSignals\Tests\Unit;
use Orchestra\Testbench\TestCase;use SocialDept\AtpSignals\Events\CommitEvent;use SocialDept\AtpSignals\Events\SignalEvent;use SocialDept\AtpSignals\Services\SignalRegistry;
class SignalRegistryTest extends TestCase{ /** @test */ public function it_matches_exact_collections() { $registry = new SignalRegistry();
$event = new SignalEvent( did: 'did:plc:test', timeUs: time() * 1000000, kind: 'commit', commit: new CommitEvent( rev: 'test', operation: 'create', collection: 'app.bsky.feed.post', rkey: 'test', ), );
$result = $this->invokeMethod( $registry, 'matchesCollection', ['app.bsky.feed.post', ['app.bsky.feed.post']] );
$this->assertTrue($result); }
/** @test */ public function it_matches_wildcard_collections() { $registry = new SignalRegistry();
// Test app.bsky.feed.* $this->assertTrue( $this->invokeMethod( $registry, 'matchesCollection', ['app.bsky.feed.post', ['app.bsky.feed.*']] ) );
$this->assertTrue( $this->invokeMethod( $registry, 'matchesCollection', ['app.bsky.feed.like', ['app.bsky.feed.*']] ) );
$this->assertFalse( $this->invokeMethod( $registry, 'matchesCollection', ['app.bsky.graph.follow', ['app.bsky.feed.*']] ) );
// Test app.bsky.* $this->assertTrue( $this->invokeMethod( $registry, 'matchesCollection', ['app.bsky.feed.post', ['app.bsky.*']] ) );
$this->assertTrue( $this->invokeMethod( $registry, 'matchesCollection', ['app.bsky.graph.follow', ['app.bsky.*']] ) ); }
/** @test */ public function it_matches_multiple_patterns() { $registry = new SignalRegistry();
$patterns = [ 'app.bsky.feed.post', 'app.bsky.graph.*', ];
// Exact match $this->assertTrue( $this->invokeMethod( $registry, 'matchesCollection', ['app.bsky.feed.post', $patterns] ) );
// Wildcard match $this->assertTrue( $this->invokeMethod( $registry, 'matchesCollection', ['app.bsky.graph.follow', $patterns] ) );
// No match $this->assertFalse( $this->invokeMethod( $registry, 'matchesCollection', ['app.bsky.feed.like', $patterns] ) ); }
/** * Call protected/private method of a class. */ protected function invokeMethod(&$object, $methodName, array $parameters = []) { $reflection = new \ReflectionClass(get_class($object)); $method = $reflection->getMethod($methodName); $method->setAccessible(true);
return $method->invokeArgs($object, $parameters); }}