Skip to content

Commit

Permalink
Add tests that should fail on {$enum} in templates
Browse files Browse the repository at this point in the history
Because enum "could not be converted to string".
  • Loading branch information
spaze committed Feb 18, 2024
1 parent 59701ae commit b358780
Show file tree
Hide file tree
Showing 4 changed files with 62 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<?php

declare(strict_types=1);

namespace Efabrica\PHPStanLatte\Tests\Rule\LatteTemplatesRule\EngineBootstrap\Fixtures;

enum EnumSomething: string
{

case Foo = 'FOO';

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<?php

declare(strict_types=1);

namespace Efabrica\PHPStanLatte\Tests\Rule\LatteTemplatesRule\EngineBootstrap\Fixtures;

use Nette\Application\UI\Presenter;


final class EnumsPresenter extends Presenter
{
public function actionDefault(): void
{
$this->template->enum = EnumSomething::Foo();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{$enum}
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
<?php

declare(strict_types=1);

namespace Efabrica\PHPStanLatte\Tests\Rule\LatteTemplatesRule\EngineBootstrap;

use Efabrica\PHPStanLatte\Tests\Rule\LatteTemplatesRule\LatteTemplatesRuleTest;

/**
* @requires PHP > 8.1
*/
final class LatteTemplatesRuleForEngineBootstrapEnumsTest extends LatteTemplatesRuleTest
{
protected static function additionalConfigFiles(): array
{
return [
__DIR__ . '/../../../../rules.neon',
__DIR__ . '/../../../config.neon',
__DIR__ . '/config.neon',
];
}

public function testFilters(): void
{
$this->analyse([__DIR__ . '/Fixtures/EnumsPresenter.php'], [
[
'Object of class Efabrica\PHPStanLatte\Tests\Rule\LatteTemplatesRule\EngineBootstrap\Fixtures\EnumSomething could not be converted to string',
1,
'default.latte',
],
]);
}
}

0 comments on commit b358780

Please sign in to comment.