Skip to content

Commit 2e1cfff

Browse files
committed
fix tests
1 parent 60eedc5 commit 2e1cfff

1 file changed

Lines changed: 20 additions & 9 deletions

File tree

tests/RelayListMetadataTest.php

Lines changed: 20 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,6 @@ public function testGetWriteRelays(): void
5454
$this->assertNotContains('wss://relay2.com', $writeRelays);
5555
$this->assertContains('wss://relay3.com', $writeRelays);
5656
$this->assertContains('wss://relay4.com', $writeRelays);
57-
$this->assertNotContains('http://invalid.com', $writeRelays);
5857
}
5958

6059
/**
@@ -75,7 +74,6 @@ public function testGetReadRelays(): void
7574
$this->assertNotContains('wss://relay2.com', $readRelays);
7675
$this->assertContains('wss://relay3.com', $readRelays);
7776
$this->assertContains('wss://relay4.com', $readRelays);
78-
$this->assertNotContains('http://invalid.com', $readRelays);
7977
}
8078

8179
/**
@@ -103,9 +101,8 @@ public function testMalformedRelayUrls(): void
103101
['r', 'wss://valid.com', 'write'],
104102
]);
105103

106-
$this->expectException(\RuntimeException::class);
107-
$relayList->getWriteRelays();
108-
104+
$this->expectException(\InvalidArgumentException::class);
105+
$relayList->getRelays();
109106
}
110107

111108
/**
@@ -153,7 +150,22 @@ public function testGetKnownRelays(): void
153150
}
154151

155152
/**
156-
* Test that empty relays throw exception for all getter methods.
153+
* Test that relays array is empty when using the getRelays method
154+
*/
155+
public function testEmptyRelaysReturnEmptyArray(): void
156+
{
157+
$relayList = new RelayListMetadata(self::TEST_PUBKEY);
158+
$reflection = new \ReflectionClass($relayList);
159+
160+
$relaysProperty = $reflection->getProperty('relays');
161+
$relaysProperty->setAccessible(true);
162+
$relaysProperty->setValue($relayList, []);
163+
164+
$this->assertEmpty($relayList->getRelays());
165+
}
166+
167+
/**
168+
* Test that empty relays throw exception for getWriteRelays and getReadRelays methods.
157169
*/
158170
public function testEmptyRelaysThrowExceptions(): void
159171
{
@@ -167,8 +179,7 @@ public function testEmptyRelaysThrowExceptions(): void
167179
$this->expectException(\RuntimeException::class);
168180
$this->expectExceptionMessage('The relays property is empty of swentel\nostr\Event\List\RelayListMetadata');
169181

170-
$relayList->getRelays();
171-
$relayList->getReadRelays();
172-
$relayList->getWriteRelays();
182+
$this->assertEmpty($relayList->getReadRelays());
183+
$this->assertEmpty($relayList->getWriteRelays());
173184
}
174185
}

0 commit comments

Comments
 (0)