Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
koriym committed Nov 23, 2024
1 parent 6be15f3 commit d107fae
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 6 deletions.
11 changes: 11 additions & 0 deletions src/TemplateFinder.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,14 @@

namespace Madapaja\TwigModule;

use LogicException;

use function assert;
use function is_int;
use function str_replace;
use function strpos;
use function substr;
use function var_dump;

class TemplateFinder implements TemplateFinderInterface
{
Expand All @@ -18,6 +21,14 @@ class TemplateFinder implements TemplateFinderInterface
public function __invoke(string $name): string
{
$pos = strpos($name, '/Resource/');
if (! is_int($pos)) {
var_dump($pos);

Check failure on line 25 in src/TemplateFinder.php

View workflow job for this annotation

GitHub Actions / sa / Psalm

ForbiddenCode: Unsafe var_dump

Check failure on line 25 in src/TemplateFinder.php

View workflow job for this annotation

GitHub Actions / sa / Psalm

ForbiddenCode: Unsafe var_dump
var_dump($name);

Check failure on line 26 in src/TemplateFinder.php

View workflow job for this annotation

GitHub Actions / sa / Psalm

ForbiddenCode: Unsafe var_dump

Check failure on line 26 in src/TemplateFinder.php

View workflow job for this annotation

GitHub Actions / sa / Psalm

ForbiddenCode: Unsafe var_dump
if (! is_int($pos)) {

Check failure on line 27 in src/TemplateFinder.php

View workflow job for this annotation

GitHub Actions / sa / PHPStan

Call to function is_int() with false will always evaluate to false.

Check failure on line 27 in src/TemplateFinder.php

View workflow job for this annotation

GitHub Actions / sa / PHPStan

Call to function is_int() with false will always evaluate to false.
throw new LogicException('Resource not found in ' . $name);
}
}

assert(is_int($pos));

Check failure on line 32 in src/TemplateFinder.php

View workflow job for this annotation

GitHub Actions / sa / PHPStan

Call to function assert() with true will always evaluate to true.

Check failure on line 32 in src/TemplateFinder.php

View workflow job for this annotation

GitHub Actions / sa / PHPStan

Call to function is_int() with int<0, max> will always evaluate to true.

Check failure on line 32 in src/TemplateFinder.php

View workflow job for this annotation

GitHub Actions / sa / PHPStan

Call to function assert() with true will always evaluate to true.

Check failure on line 32 in src/TemplateFinder.php

View workflow job for this annotation

GitHub Actions / sa / PHPStan

Call to function is_int() with int<0, max> will always evaluate to true.
$relativePath = substr($name, $pos + 10);

Expand Down
6 changes: 5 additions & 1 deletion tests/ExtensionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,20 @@
use PHPUnit\Framework\TestCase;
use Ray\Di\Injector;

use function str_replace;
use function str_rot13;
use function trim;

use const DIRECTORY_SEPARATOR;

class ExtensionTest extends TestCase
{
private Injector $injector;

public function setUp(): void
{
$this->injector = new Injector(new TwigExtensionTestModule([__DIR__ . '/Fake/src/Resource/']));
$path = str_replace('/', DIRECTORY_SEPARATOR, __DIR__ . '/Fake/src/Resource/');
$this->injector = new Injector(new TwigExtensionTestModule([$path]));
}

public function testTwigFilter(): void
Expand Down
15 changes: 11 additions & 4 deletions tests/FileLoaderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,18 @@
use ReflectionClass;

use function assert;
use function str_replace;
use function trim;

use const DIRECTORY_SEPARATOR;

class FileLoaderTest extends TestCase
{
public function getInjector(): Injector
{
return new Injector(new TwigFileLoaderTestModule([__DIR__ . '/Fake/src/Resource']));
$path = str_replace('/', DIRECTORY_SEPARATOR, __DIR__ . '/Fake/src/Resource/');

return new Injector(new TwigFileLoaderTestModule([$path]));
}

public function testRenderer(): void
Expand All @@ -38,11 +43,12 @@ public function testRenderer(): void
public function testTwigOptions(): void
{
/** @var TwigRenderer $renderer */
$renderer = (new Injector(new TwigFileLoaderTestModule([__DIR__ . '/Fake/src/Resource'], ['debug' => true])))->getInstance(TwigRenderer::class);
$path = str_replace('/', DIRECTORY_SEPARATOR, __DIR__ . '/Fake/src/Resource/');

Check failure on line 46 in tests/FileLoaderTest.php

View workflow job for this annotation

GitHub Actions / sa / PHPStan

Variable $renderer in PHPDoc tag @var does not match assigned variable $path.

Check failure on line 46 in tests/FileLoaderTest.php

View workflow job for this annotation

GitHub Actions / sa / PHPStan

Variable $renderer in PHPDoc tag @var does not match assigned variable $path.
$renderer = (new Injector(new TwigFileLoaderTestModule([$path], ['debug' => true])))->getInstance(TwigRenderer::class);
$this->assertTrue($renderer->twig->isDebug());

/** @var TwigRenderer $renderer */
$renderer = (new Injector(new TwigFileLoaderTestModule([__DIR__ . '/Fake/src/Resource'], ['debug' => false])))->getInstance(TwigRenderer::class);
$renderer = (new Injector(new TwigFileLoaderTestModule([$path], ['debug' => false])))->getInstance(TwigRenderer::class);
$this->assertFalse($renderer->twig->isDebug());
}

Expand Down Expand Up @@ -155,7 +161,8 @@ public function testRedirectOnPost(): void

public function testRedirectOnPostNoRedirectTemplate(): void
{
$injector = new Injector(new TwigFileLoaderTestModule([__DIR__ . '/Fake/src/ResourceNoTemplate']));
$path = str_replace('/', DIRECTORY_SEPARATOR, __DIR__ . '/Fake/src/ResourceNoTemplate/');
$injector = new Injector(new TwigFileLoaderTestModule([$path]));
$ro = $injector->getInstance(RedirectNoTemplate::class);
$ro->onPost();
$view = (string) $ro;
Expand Down
6 changes: 5 additions & 1 deletion tests/WeavedResourceTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,19 @@
use Ray\Di\Injector;
use ReflectionClass;

use function str_replace;
use function trim;

use const DIRECTORY_SEPARATOR;

class WeavedResourceTest extends TestCase
{
private Injector $injector;

public function setUp(): void
{
$this->injector = new Injector(new TwigWeavedResourceTestModule([__DIR__ . '/Fake/src/Resource']));
$path = str_replace('/', DIRECTORY_SEPARATOR, __DIR__ . '/Fake/src/Resource/');
$this->injector = new Injector(new TwigWeavedResourceTestModule([$path]));
}

public function testRenderer(): void
Expand Down

0 comments on commit d107fae

Please sign in to comment.