Skip to content

Commit d5c9ea8

Browse files
JeroenDeDauwalistair3149
authored andcommitted
Fully test getPageIdFromPersistentId
Follow up to #64 @alistair3149 Writing good tests after the fact is more difficult than if you follow the red-green-refactor cycle. You never had the red step for this test, because I could remove the WHERE clause from the query, and it would still pass. To know a test actually does what you want, you need to see it fail first. It's easy to miss testing parts of the production code or to fail to test it altogether due to a mistake in the test.
1 parent eb06ee0 commit d5c9ea8

File tree

1 file changed

+16
-7
lines changed

1 file changed

+16
-7
lines changed

tests/Adapters/DatabasePersistentPageIdentifiersRepoTest.php

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -102,16 +102,25 @@ public function testCanSaveAndRetrieveMultiplePersistentIds(): void {
102102
);
103103
}
104104

105-
public function testGetPageIdFromPersistentId(): void {
106-
$pageId = $this->createPageWithText()->getId();
107-
$persistentId = '00000000-0000-0000-0000-000000000042';
105+
public function testGetPageIdReturnsIdMatchingPersistentId(): void {
106+
$this->repo->savePersistentIds( [
107+
21 => '00000000-0000-0000-0000-000000000021',
108+
42 => '00000000-0000-0000-0000-000000000042',
109+
84 => '00000000-0000-0000-0000-000000000084',
110+
] );
108111

109-
$this->repo->savePersistentIds( [ $pageId => $persistentId ] );
110-
$this->assertSame( $pageId, $this->repo->getPageIdFromPersistentId( $persistentId ) );
112+
$this->assertSame(
113+
42,
114+
$this->repo->getPageIdFromPersistentId( '00000000-0000-0000-0000-000000000042' )
115+
);
111116
}
112117

113-
public function testGetPageIdFromNonExistentPersistentId(): void {
114-
$this->assertNull( $this->repo->getPageIdFromPersistentId( 'non-existent' ) );
118+
public function testGetPageIdReturnsNullForUnknownPersistentId(): void {
119+
$this->repo->savePersistentIds( [
120+
42 => '00000000-0000-0000-0000-000000000042',
121+
] );
122+
123+
$this->assertNull( $this->repo->getPageIdFromPersistentId( '00000000-0000-0000-0000-000000000404' ) );
115124
}
116125

117126
}

0 commit comments

Comments
 (0)