diff --git a/src/QueryTemplate.php b/src/QueryTemplate.php index b6b0884..b3aed69 100644 --- a/src/QueryTemplate.php +++ b/src/QueryTemplate.php @@ -84,7 +84,7 @@ public function findTemplate(?\WP_Query $query = null, bool $filters = true): st $found = ''; while ($types && !$found) { $type = array_shift($types); - $found = $this->finder->findFirst($leaves[$type], $type); + $found = $this->finder->findFirst($leaves[$type], (string) $type); $filters and $found = $this->applyFilter("{$type}_template", $found, $query); } diff --git a/tests/src/Unit/QueryTemplateTest.php b/tests/src/Unit/QueryTemplateTest.php index 0640414..7a0ae00 100644 --- a/tests/src/Unit/QueryTemplateTest.php +++ b/tests/src/Unit/QueryTemplateTest.php @@ -183,6 +183,24 @@ public function find(string $template, string $type): string unset($wp_query, $wp_the_query); } + /** + * @test + */ + public function testFindTemplateWhen404(): void + { + $wpQuery = new \WP_Query([ + 'is_404' => true, + ]); + + $finder = \Mockery::mock(TemplateFinder::class); + $finder->expects('findFirst')->andReturn('foo'); + + $loader = new QueryTemplate($finder); + $loaded = $loader->findTemplate($wpQuery); + + static::assertSame('foo', $loaded); + } + /** * @test */