Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions src/ViewTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,16 @@
public function withRenderers(array $renderers): static
{
foreach ($renderers as $extension => $renderer) {
if (!is_string($extension)) {

Check failure on line 91 in src/ViewTrait.php

View workflow job for this annotation

GitHub Actions / psalm / PHP 8.3-ubuntu-latest

DocblockTypeContradiction

src/ViewTrait.php:91:18: DocblockTypeContradiction: Docblock-defined type string for $extension is always string (see https://psalm.dev/155)

Check failure on line 91 in src/ViewTrait.php

View workflow job for this annotation

GitHub Actions / psalm / PHP 8.2-ubuntu-latest

DocblockTypeContradiction

src/ViewTrait.php:91:18: DocblockTypeContradiction: Docblock-defined type string for $extension is always string (see https://psalm.dev/155)

Check failure on line 91 in src/ViewTrait.php

View workflow job for this annotation

GitHub Actions / psalm / PHP 8.1-ubuntu-latest

DocblockTypeContradiction

src/ViewTrait.php:91:18: DocblockTypeContradiction: Docblock-defined type string for $extension is always string (see https://psalm.dev/155)
throw new InvalidArgumentException(
sprintf(
'Extension must be a non-empty string, %s provided for %s.',
get_debug_type($extension),
$renderer::class
)
);
}

if ($extension === '') {
throw new InvalidArgumentException(
sprintf(
Expand Down
30 changes: 29 additions & 1 deletion tests/ViewTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -262,6 +262,34 @@ public function testWithRenderersInvalidRendererTypeThrowsException(): void
]);
}

public function testWithRenderersNumericKeyImplicitThrowsException(): void
{
$view = TestHelper::createView();

$this->expectException(InvalidArgumentException::class);
$this->expectExceptionMessage(
'Extension must be a non-empty string, int provided for ' . PhpTemplateRenderer::class . '.'
);

$view->withRenderers([
new PhpTemplateRenderer(),
]);
}

public function testWithRenderersNumericKeyExplicitThrowsException(): void
{
$view = TestHelper::createView();

$this->expectException(InvalidArgumentException::class);
$this->expectExceptionMessage(
'Extension must be a non-empty string, int provided for ' . PhpTemplateRenderer::class . '.'
);

$view->withRenderers([
0 => new PhpTemplateRenderer(),
]);
}

public function testLocalize(): void
{
$view = $this->createViewWithBasePath($this->tempDirectory);
Expand Down Expand Up @@ -628,7 +656,7 @@ public function testImmutability(): void
$view = TestHelper::createView();

$this->assertNotSame($view, $view->withBasePath(''));
$this->assertNotSame($view, $view->withRenderers([new PhpTemplateRenderer()]));
$this->assertNotSame($view, $view->withRenderers(['php' => new PhpTemplateRenderer()]));
$this->assertNotSame($view, $view->withSourceLocale('en'));
$this->assertNotSame($view, $view->withContext($this->createContext($this->tempDirectory)));
$this->assertNotSame($view, $view->withContextPath(__DIR__));
Expand Down
Loading