Skip to content

Commit

Permalink
Update stempler tests
Browse files Browse the repository at this point in the history
  • Loading branch information
roxblnfk committed Sep 11, 2024
1 parent 3c889dd commit 3ebf8ff
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 43 deletions.
63 changes: 20 additions & 43 deletions src/Bridge/Stempler/tests/BaseTestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

namespace Spiral\Tests\Stempler;

use PHPUnit\Framework\TestCase;
use Spiral\Boot\BootloadManager\StrategyBasedBootloadManager;
use Spiral\Boot\BootloadManager\DefaultInvokerStrategy;
use Spiral\Boot\BootloadManager\Initializer;
Expand All @@ -22,60 +21,38 @@
use Spiral\Stempler\Bootloader\PrettyPrintBootloader;
use Spiral\Stempler\Bootloader\StemplerBootloader;
use Spiral\Stempler\StemplerEngine;
use Spiral\Testing\TestCase;
use Spiral\Views\ViewManager;
use Spiral\Views\ViewsInterface;

abstract class BaseTestCase extends TestCase
{
public const BOOTLOADERS = [
StemplerBootloader::class,
PrettyPrintBootloader::class
];

protected Container $container;
protected StrategyBasedBootloadManager $app;

public function setUp(): void
public function defineBootloaders(): array
{
$this->container = $this->container ?? new Container();
$this->container->bind(EnvironmentInterface::class, new Environment());
$this->container->bind(
DirectoriesInterface::class,
new Directories(
[
'app' => __DIR__ . '/fixtures',
'cache' => __DIR__ . '/cache'
]
)
);

$this->container->bind(ConfigsInterface::class, ConfiguratorInterface::class);
$this->container->bind(
ConfiguratorInterface::class,
new ConfigManager(
new DirectoryLoader(__DIR__ . '/config/', [
'php' => $this->container->get(PhpLoader::class),
'json' => $this->container->get(JsonLoader::class),
]),
true
)
);

$this->container->bind(ViewsInterface::class, ViewManager::class);

$initializer = new Initializer($this->container, $this->container);
$this->app = new StrategyBasedBootloadManager(
new DefaultInvokerStrategy($initializer, $this->container, $this->container),
$this->container,
$initializer
);
return [
StemplerBootloader::class,
PrettyPrintBootloader::class
];
}

$this->app->bootload(static::BOOTLOADERS);
public function defineDirectories(string $root): array
{
return [
'app' => __DIR__ . '/fixtures',
'cache' => __DIR__ . '/cache',
'config' => __DIR__ . '/config',
] + parent::defineDirectories($root);
}

protected function getViews(): ViewManager
public function setUp(): void
{
return $this->container->get(ViewsInterface::class);
parent::setUp();

$this->container = $this->getContainer();
// $this->container->bind(EnvironmentInterface::class, new Environment());
// $this->container->bind(ViewsInterface::class, ViewManager::class);
}

protected function getStempler(): StemplerEngine
Expand Down
3 changes: 3 additions & 0 deletions src/Bridge/Stempler/tests/CacheTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,10 @@
namespace Spiral\Tests\Stempler;

use Spiral\Config\ConfiguratorInterface;
use Spiral\Core\Internal\Introspector;
use Spiral\Files\Files;
use Spiral\Files\FilesInterface;
use Spiral\Testing\Attribute\TestScope;
use Spiral\Views\ViewContext;

class CacheTest extends BaseTestCase
Expand All @@ -25,6 +27,7 @@ public function setUp(): void
$configurator->modify('views', new EnableCachePatch());
}

#[TestScope("http")]
public function testCache(): void
{
$this->assertCount(0, $this->files->getFiles(__DIR__ . '/cache/', '*.php'));
Expand Down
3 changes: 3 additions & 0 deletions src/Bridge/Stempler/tests/DirectiveTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

namespace Spiral\Tests\Stempler;

use Spiral\Testing\Attribute\TestScope;
use Spiral\Views\Exception\CompileException;
use Spiral\Views\Exception\RenderException;
use Spiral\Views\ViewContext;
Expand All @@ -21,6 +22,7 @@ public function testRenderDirectiveEx(): void
;
}

#[TestScope("http")]
public function testRenderDirective(): void
{
$s = $this->getStempler();
Expand All @@ -29,6 +31,7 @@ public function testRenderDirective(): void
$this->assertSame('abc', $s->get('directive', new ViewContext())->render());
}

#[TestScope("http")]
public function testRenderDirectiveAsArray(): void
{
$s = $this->getStempler();
Expand Down
2 changes: 2 additions & 0 deletions src/Bridge/Stempler/tests/EngineTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,13 @@

namespace Spiral\Tests\Stempler;

use Spiral\Testing\Attribute\TestScope;
use Spiral\Views\Context\ValueDependency;
use Spiral\Views\Exception\CompileException;
use Spiral\Views\Exception\RenderException;
use Spiral\Views\ViewContext;

#[TestScope("http")]
class EngineTest extends BaseTestCase
{
public function testList(): void
Expand Down

0 comments on commit 3ebf8ff

Please sign in to comment.