Something went wrong. Try again.
A barebones implementation of an atproto PDS in PHP and Slim Framework 4.
pds php atproto
Something went wrong. Try again.
3.3 kB · 97 lines
PHP
at main
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798<?php
declare(strict_types=1);
namespace Tests\Infrastructure\Persistence\OAuth;
use App\Domain\OAuth\AccountDevice;use App\Domain\OAuth\AccountDeviceNotFoundException;use App\Infrastructure\Database\Database;use App\Infrastructure\Database\Schema\AccountSchema;use App\Infrastructure\Persistence\OAuth\SqliteAccountDeviceRepository;use DateTimeImmutable;use Tests\TestCase;
class SqliteAccountDeviceRepositoryTest extends TestCase{ private function newRepo(): SqliteAccountDeviceRepository { $db = new Database(':memory:'); AccountSchema::apply($db);
return new SqliteAccountDeviceRepository($db); }
private function makeEntry(string $did = 'did:plc:alice', string $deviceId = 'dev-1'): AccountDevice { return new AccountDevice( did: $did, deviceId: $deviceId, createdAt: new DateTimeImmutable('2026-01-01T00:00:00Z'), updatedAt: new DateTimeImmutable('2026-01-01T00:00:00Z'), ); }
public function testFindByDidAndDeviceId(): void { $repo = $this->newRepo(); $repo->save($this->makeEntry());
$found = $repo->findByDidAndDeviceId('did:plc:alice', 'dev-1'); $this->assertSame('dev-1', $found->getDeviceId()); }
public function testFindByDidAndDeviceIdThrowsWhenMissing(): void { $repo = $this->newRepo();
$this->expectException(AccountDeviceNotFoundException::class); $repo->findByDidAndDeviceId('did:plc:alice', 'dev-1'); }
public function testFindAllForDid(): void { $repo = $this->newRepo(); $repo->save($this->makeEntry('did:plc:alice', 'dev-1')); $repo->save($this->makeEntry('did:plc:alice', 'dev-2')); $repo->save($this->makeEntry('did:plc:bob', 'dev-3'));
$this->assertCount(2, $repo->findAllForDid('did:plc:alice')); $this->assertCount(1, $repo->findAllForDid('did:plc:bob')); $this->assertCount(0, $repo->findAllForDid('did:plc:carol')); }
public function testSaveInsertsNewAndUpdatesExisting(): void { $repo = $this->newRepo(); $repo->save($this->makeEntry()); $this->assertCount(1, $repo->findAllForDid('did:plc:alice'));
$updated = new AccountDevice( did: 'did:plc:alice', deviceId: 'dev-1', createdAt: new DateTimeImmutable('2026-01-01T00:00:00Z'), updatedAt: new DateTimeImmutable('2026-02-01T00:00:00Z'), ); $repo->save($updated);
$this->assertCount(1, $repo->findAllForDid('did:plc:alice')); $this->assertEquals( new DateTimeImmutable('2026-02-01T00:00:00Z'), $repo->findByDidAndDeviceId('did:plc:alice', 'dev-1')->getUpdatedAt(), ); }
public function testDeleteByDidAndDeviceId(): void { $repo = $this->newRepo(); $repo->save($this->makeEntry('did:plc:alice', 'dev-1')); $repo->save($this->makeEntry('did:plc:alice', 'dev-2'));
$repo->deleteByDidAndDeviceId('did:plc:alice', 'dev-1');
$this->assertCount(1, $repo->findAllForDid('did:plc:alice')); $this->expectException(AccountDeviceNotFoundException::class); $repo->findByDidAndDeviceId('did:plc:alice', 'dev-1'); }}