Skip to content

Commit e5dd1f5

Browse files
committed
test(api): drop deprecated shims from coverage; test the null-query path
The deprecated global function shims are guarded by function_exists() checks that execute during Composer's files autoload -- before PHPUnit starts collecting coverage -- so those lines can never be covered. Wrap the back-compat block in @codeCoverageIgnore; the shim bodies are still exercised by PublicApiTest. Also add a test for get_page_id_for_custom_post_type() called with no post type outside a PFCPT query (the query-var fallthrough). functions.php goes 78% -> 93%.
1 parent 3a8c8a9 commit e5dd1f5

2 files changed

Lines changed: 13 additions & 0 deletions

File tree

src/functions.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,10 @@ function get_page_url_for_custom_post_type(?string $postType = null): ?string
7373
}
7474

7575
namespace {
76+
// Deprecated back-compat shims. The function_exists() guards run during
77+
// Composer's files autoload, before coverage starts, so they cannot be
78+
// covered; the function bodies are exercised by PublicApiTest.
79+
// @codeCoverageIgnoreStart
7680
if (!\function_exists('is_page_for_custom_post_type')) {
7781
/**
7882
* @deprecated 1.0.0 Use \n5s\PageForCustomPostType\is_page_for_custom_post_type() instead.
@@ -124,4 +128,5 @@ function get_page_url_for_custom_post_type(?string $postType = null): ?string
124128
return \n5s\PageForCustomPostType\get_page_url_for_custom_post_type($postType);
125129
}
126130
}
131+
// @codeCoverageIgnoreEnd
127132
}

tests/Integration/PublicApiTest.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,14 @@ public function testGetPageIdForCustomPostTypeUsesCurrentQueryWhenNull(): void
9797
);
9898
}
9999

100+
public function testGetPageIdForCustomPostTypeReturnsNullOnRegularPage(): void
101+
{
102+
$this->setExpectedDeprecated('get_page_id_for_custom_post_type');
103+
$this->get(get_permalink($this->staticFrontPageId));
104+
105+
$this->assertNull(get_page_id_for_custom_post_type());
106+
}
107+
100108
public function testGetPageUrlForCustomPostTypeReturnsUrl(): void
101109
{
102110
$this->setExpectedDeprecated('get_page_url_for_custom_post_type');

0 commit comments

Comments
 (0)