Skip to content

Commit

Permalink
Ensure $view is an instance of Stringable
Browse files Browse the repository at this point in the history
Add an assertion to verify that $view implements the Stringable interface before casting it to a string. This enhances type safety and prevents potential runtime errors.
  • Loading branch information
koriym committed Nov 20, 2024
1 parent 6a9cbbe commit 805de3f
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion tests/IntegrateTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
use PHPUnit\Framework\TestCase;
use Ray\Di\Injector;

Check failure on line 14 in tests/IntegrateTest.php

View workflow job for this annotation

GitHub Actions / cs / Coding Standards

Header blocks must not contain blank lines

Check failure on line 14 in tests/IntegrateTest.php

View workflow job for this annotation

GitHub Actions / cs / Coding Standards

Header blocks must not contain blank lines

use Stringable;

Check failure on line 16 in tests/IntegrateTest.php

View workflow job for this annotation

GitHub Actions / cs / Coding Standards

Expected 0 lines between same types of use statement, found 1.

Check failure on line 16 in tests/IntegrateTest.php

View workflow job for this annotation

GitHub Actions / cs / Coding Standards

Header blocks must be separated by a single blank line

Check failure on line 16 in tests/IntegrateTest.php

View workflow job for this annotation

GitHub Actions / cs / Coding Standards

Expected 0 lines between same types of use statement, found 1.

Check failure on line 16 in tests/IntegrateTest.php

View workflow job for this annotation

GitHub Actions / cs / Coding Standards

Header blocks must be separated by a single blank line
use function assert;

Check failure on line 17 in tests/IntegrateTest.php

View workflow job for this annotation

GitHub Actions / cs / Coding Standards

Expected 1 line between different types of use statement, found 0.

Check failure on line 17 in tests/IntegrateTest.php

View workflow job for this annotation

GitHub Actions / cs / Coding Standards

Expected 1 line between different types of use statement, found 0.
use function method_exists;
use function ob_get_clean;
Expand Down Expand Up @@ -78,7 +79,8 @@ public function testRender(string $uri, string $expected): void
$ro->setRenderer($this->renderer);
assert(method_exists($ro, 'onGet'));
$view = $ro->onGet();
$stream = $this->streamer->getStream((string) $view); // @phpstan-ignore-line
assert($view instanceof Stringable);
$stream = $this->streamer->getStream((string) $view);
rewind($stream);
$view = stream_get_contents($stream);
$this->assertSame($expected, $view);
Expand Down

0 comments on commit 805de3f

Please sign in to comment.