Skip to content

Commit

Permalink
add PHPUnit test for RelaySet
Browse files Browse the repository at this point in the history
  • Loading branch information
Sebastix committed Jun 19, 2024
1 parent 1f09ef9 commit 703ff6a
Showing 1 changed file with 44 additions and 0 deletions.
44 changes: 44 additions & 0 deletions tests/RelaySetTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
<?php

declare(strict_types=1);

use PHPUnit\Framework\TestCase;
use swentel\nostr\Event\Event;
use swentel\nostr\Key\Key;
use swentel\nostr\Relay\Relay;
use swentel\nostr\Relay\RelaySet;
use swentel\nostr\Relay\CommandResult;
use swentel\nostr\Sign\Sign;

class RelaySetTest extends TestCase
{
/**
* Tests sending a note to a set of relays.
*/
public function testSendNoteToRelaySet()
{
$keys = new Key();
$private_key = $keys->generatePrivateKey();

$note = new Event();
$note->setContent('Hello world');

$signer = new Sign();
$signer->signEvent($note, $private_key);

$relay1 = new Relay('wss://example1.com');
$relay2 = new Relay('wss://example2.com');
$relay3 = new Relay('wss://example3.com');

$relaySet = $this->createMock(RelaySet::class);
$relaySet->setRelays([$relay1, $relay2, $relay3]);
$relaySet->expects($this->once())
->method('send')
->willReturn(new CommandResult(['OK', $note->getId(), true, '']));

$response = $relaySet->send();
$this->assertTrue(
$response->isSuccess(),
);
}
}

0 comments on commit 703ff6a

Please sign in to comment.