Skip to content

Commit

Permalink
prepare release
Browse files Browse the repository at this point in the history
  • Loading branch information
spiralbot committed Jan 22, 2025
1 parent 52f7ec0 commit d2124f5
Show file tree
Hide file tree
Showing 11 changed files with 105 additions and 96 deletions.
6 changes: 3 additions & 3 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,12 +34,12 @@
],
"require": {
"php": ">=8.1",
"spiral/core": "^3.15",
"spiral/files": "^3.15",
"spiral/core": "^3.14.10",
"spiral/files": "^3.14.10",
"psr/event-dispatcher": "^1.0"
},
"require-dev": {
"spiral/boot": "^3.15",
"spiral/boot": "^3.14.10",
"phpunit/phpunit": "^10.1",
"mockery/mockery": "^1.5",
"vimeo/psalm": "^5.9"
Expand Down
2 changes: 1 addition & 1 deletion src/ViewManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ public function addEngine(EngineInterface $engine): void
{
$this->engines[] = $engine->withLoader($this->loader);

\uasort($this->engines, static fn (EngineInterface $a, EngineInterface $b): int => \strcmp(
\uasort($this->engines, static fn (EngineInterface $a, EngineInterface $b) => \strcmp(
$a->getLoader()->getExtension() ?? '',
$b->getLoader()->getExtension() ?? ''
));
Expand Down
34 changes: 17 additions & 17 deletions tests/CacheTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@ public function testSimpleCache(): void
$view = $this->getView($ctx, 'default:view');

$cache->set($ctx, 'default:view', $view);
self::assertTrue($cache->has($ctx, 'default:view'));
self::assertSame($view, $cache->get($ctx, 'default:view'));
$this->assertTrue($cache->has($ctx, 'default:view'));
$this->assertSame($view, $cache->get($ctx, 'default:view'));
}

public function testGet(): void
Expand All @@ -50,13 +50,13 @@ public function testReset(): void
$cache->set($ctx, 'default:view', $view);
$cache->set($ctx2, 'other:view', $view2);

self::assertTrue($cache->has($ctx, 'default:view'));
self::assertTrue($cache->has($ctx2, 'other:view'));
$this->assertTrue($cache->has($ctx, 'default:view'));
$this->assertTrue($cache->has($ctx2, 'other:view'));

$cache->reset($ctx);

self::assertFalse($cache->has($ctx, 'default:view'));
self::assertTrue($cache->has($ctx2, 'other:view'));
$this->assertFalse($cache->has($ctx, 'default:view'));
$this->assertTrue($cache->has($ctx2, 'other:view'));
}

public function testResetAll(): void
Expand All @@ -72,13 +72,13 @@ public function testResetAll(): void
$cache->set($ctx, 'default:view', $view);
$cache->set($ctx2, 'other:view', $view2);

self::assertTrue($cache->has($ctx, 'default:view'));
self::assertTrue($cache->has($ctx2, 'other:view'));
$this->assertTrue($cache->has($ctx, 'default:view'));
$this->assertTrue($cache->has($ctx2, 'other:view'));

$cache->reset();

self::assertFalse($cache->has($ctx, 'default:view'));
self::assertFalse($cache->has($ctx2, 'other:view'));
$this->assertFalse($cache->has($ctx, 'default:view'));
$this->assertFalse($cache->has($ctx2, 'other:view'));
}

public function testResetPath(): void
Expand All @@ -92,13 +92,13 @@ public function testResetPath(): void
$cache->set($ctx, 'default:view', $view);
$cache->set($ctx, 'other:view', $view2);

self::assertTrue($cache->has($ctx, 'default:view'));
self::assertTrue($cache->has($ctx, 'other:view'));
$this->assertTrue($cache->has($ctx, 'default:view'));
$this->assertTrue($cache->has($ctx, 'other:view'));

$cache->resetPath('other:view');

self::assertTrue($cache->has($ctx, 'default:view'));
self::assertFalse($cache->has($ctx, 'other:view'));
$this->assertTrue($cache->has($ctx, 'default:view'));
$this->assertFalse($cache->has($ctx, 'other:view'));
}

public function testContextValue(): void
Expand All @@ -111,13 +111,13 @@ public function testContextValue(): void
$view = $this->getView($ctx, 'default:view');

$cache->set($ctx, 'default:view', $view);
self::assertTrue($cache->has($ctx, 'default:view'));
$this->assertTrue($cache->has($ctx, 'default:view'));

$ctx = $ctx->withDependency(new ValueDependency('test', 'another'));
self::assertFalse($cache->has($ctx, 'default:view'));
$this->assertFalse($cache->has($ctx, 'default:view'));

$ctx = $ctx->withDependency(new ValueDependency('test', 'value'));
self::assertTrue($cache->has($ctx, 'default:view'));
$this->assertTrue($cache->has($ctx, 'default:view'));
}

protected function getView(ContextInterface $context, string $path): ViewInterface
Expand Down
21 changes: 15 additions & 6 deletions tests/ConfigTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ public function testCache(): void
],
]);

self::assertTrue($config->isCacheEnabled());
self::assertSame('/tmp/', $config->getCacheDirectory());
$this->assertTrue($config->isCacheEnabled());
$this->assertSame('/tmp/', $config->getCacheDirectory());
}

public function testNamespace(): void
Expand All @@ -34,7 +34,7 @@ public function testNamespace(): void
],
]);

self::assertSame([
$this->assertSame([
'default' => [__DIR__],
], $config->getNamespaces());
}
Expand All @@ -47,13 +47,19 @@ public function testEngines(): void
'engines' => [new Autowire(NativeEngine::class)],
]);

self::assertInstanceOf(NativeEngine::class, $config->getEngines()[0]->resolve($container));
$this->assertInstanceOf(
NativeEngine::class,
$config->getEngines()[0]->resolve($container)
);

$config = new ViewsConfig([
'engines' => [NativeEngine::class],
]);

self::assertInstanceOf(NativeEngine::class, $config->getEngines()[0]->resolve($container));
$this->assertInstanceOf(
NativeEngine::class,
$config->getEngines()[0]->resolve($container)
);
}

public function testDependencies(): void
Expand All @@ -70,6 +76,9 @@ public function testDependencies(): void
],
]);

self::assertSame($dependency, $config->getDependencies()[0]->resolve($container));
$this->assertSame(
$dependency,
$config->getDependencies()[0]->resolve($container)
);
}
}
12 changes: 6 additions & 6 deletions tests/ContextProcessorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,20 +21,20 @@ public function testProcessContext(): void
{
$this->processors[] = new ContextProcessor();
$source = $this->getSource('other:inject');
self::assertSame("hello @{name}\n", $source->getCode());
$this->assertSame("hello @{name}\n", $source->getCode());
$ctx = new ViewContext();
$source2 = $this->process($source, $ctx->withDependency(new ValueDependency('name', 'Bobby')));
self::assertSame("hello Bobby\n", $source2->getCode());
$this->assertSame("hello Bobby\n", $source2->getCode());
}

public function testProcessContextWithDefaultValue(): void
{
$this->processors[] = new ContextProcessor();
$source = $this->getSource('other:injectWithDefault');
self::assertSame("hello @{name|default}\n", $source->getCode());
$this->assertSame("hello @{name|default}\n", $source->getCode());
$ctx = new ViewContext();
$source2 = $this->process($source, $ctx->withDependency(new ValueDependency('name', 'Bobby')));
self::assertSame("hello Bobby\n", $source2->getCode());
$this->assertSame("hello Bobby\n", $source2->getCode());
}

public function testProcessContextShouldUseDefaultValueIfKeyNotFound(): void
Expand All @@ -43,7 +43,7 @@ public function testProcessContextShouldUseDefaultValueIfKeyNotFound(): void
$source = $this->getSource('other:injectWithDefault');
$ctx = new ViewContext();
$source2 = $this->process($source, $ctx);
self::assertSame("hello default\n", $source2->getCode());
$this->assertSame("hello default\n", $source2->getCode());
}

public function testProcessContextShouldUseDefaultValueIfContextIsNull(): void
Expand All @@ -52,7 +52,7 @@ public function testProcessContextShouldUseDefaultValueIfContextIsNull(): void
$source = $this->getSource('other:injectWithDefault');
$ctx = new ViewContext();
$source2 = $this->process($source, $ctx->withDependency(new ValueDependency('name', null)));
self::assertSame("hello default\n", $source2->getCode());
$this->assertSame("hello default\n", $source2->getCode());
}

public function testProcessContextException(): void
Expand Down
4 changes: 2 additions & 2 deletions tests/ContextTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ public function testResolveValue(): void
$context = new ViewContext();
$context = $context->withDependency(new ValueDependency('test', 'value'));

self::assertSame('value', $context->resolveValue('test'));
$this->assertSame('value', $context->resolveValue('test'));
}

public function testResolveValueException(): void
Expand All @@ -26,6 +26,6 @@ public function testResolveValueException(): void
$context = new ViewContext();
$context = $context->withDependency(new ValueDependency('test', 'value'));

self::assertSame('value', $context->resolveValue('other'));
$this->assertSame('value', $context->resolveValue('other'));
}
}
26 changes: 13 additions & 13 deletions tests/GeneratorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@ public function testRotateSingleValue(): void
$generator = new ContextGenerator($context);
$variants = $generator->generate();

self::assertCount(1, $variants);
self::assertSame($context->getID(), $variants[0]->getID());
self::assertSame('value', $variants[0]->resolveValue('test'));
$this->assertCount(1, $variants);
$this->assertSame($context->getID(), $variants[0]->getID());
$this->assertSame('value', $variants[0]->resolveValue('test'));
}

public function testRotateEmpty(): void
Expand All @@ -31,7 +31,7 @@ public function testRotateEmpty(): void
$generator = new ContextGenerator($context);
$variants = $generator->generate();

self::assertCount(0, $variants);
$this->assertCount(0, $variants);
}

public function testRotateMultiValue(): void
Expand All @@ -42,10 +42,10 @@ public function testRotateMultiValue(): void
$generator = new ContextGenerator($context);
$variants = $generator->generate();

self::assertCount(2, $variants);
self::assertSame($context->getID(), $variants[0]->getID());
self::assertSame('value', $variants[0]->resolveValue('test'));
self::assertSame('another', $variants[1]->resolveValue('test'));
$this->assertCount(2, $variants);
$this->assertSame($context->getID(), $variants[0]->getID());
$this->assertSame('value', $variants[0]->resolveValue('test'));
$this->assertSame('another', $variants[1]->resolveValue('test'));
}

public function testRotateMultiple(): void
Expand All @@ -58,12 +58,12 @@ public function testRotateMultiple(): void
$generator = new ContextGenerator($context);
$variants = $generator->generate();

self::assertCount(8, $variants);
self::assertSame($context->getID(), $variants[0]->getID());
$this->assertCount(8, $variants);
$this->assertSame($context->getID(), $variants[0]->getID());

// ending
self::assertSame('b', $variants[7]->resolveValue('a'));
self::assertSame('e', $variants[7]->resolveValue('b'));
self::assertSame('g', $variants[7]->resolveValue('d'));
$this->assertSame('b', $variants[7]->resolveValue('a'));
$this->assertSame('e', $variants[7]->resolveValue('b'));
$this->assertSame('g', $variants[7]->resolveValue('d'));
}
}
6 changes: 3 additions & 3 deletions tests/GlobalVariablesTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,11 @@ public function testSets(): void
'foo' => 'bar'
]);

self::assertSame('bar', $variables->getAll()['foo']);
self::assertArrayNotHasKey('baf', $variables->getAll());
$this->assertSame('bar', $variables->getAll()['foo']);
$this->assertArrayNotHasKey('baf', $variables->getAll());

$variables->set('baz', 'baf');

self::assertSame('baf', $variables->getAll()['baz']);
$this->assertSame('baf', $variables->getAll()['baz']);
}
}
64 changes: 32 additions & 32 deletions tests/LoaderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,27 +53,27 @@ public function testExists(): void

$loader = $loader->withExtension('php');

self::assertFalse($loader->exists('another'));
self::assertFalse($loader->exists('inner/file.twig'));
self::assertFalse($loader->exists('inner/file'));
$this->assertFalse($loader->exists('another'));
$this->assertFalse($loader->exists('inner/file.twig'));
$this->assertFalse($loader->exists('inner/file'));

self::assertTrue($loader->exists('view'));
self::assertTrue($loader->exists('inner/view'));
self::assertTrue($loader->exists('inner/partial/view'));
$this->assertTrue($loader->exists('view'));
$this->assertTrue($loader->exists('inner/view'));
$this->assertTrue($loader->exists('inner/partial/view'));

self::assertTrue($loader->exists('view.php'));
$this->assertTrue($loader->exists('view.php'));

self::assertTrue($loader->exists('default:view'));
self::assertTrue($loader->exists('default:view.php'));
$this->assertTrue($loader->exists('default:view'));
$this->assertTrue($loader->exists('default:view.php'));

self::assertTrue($loader->exists('@default/view'));
self::assertTrue($loader->exists('@default/view.php'));
$this->assertTrue($loader->exists('@default/view'));
$this->assertTrue($loader->exists('@default/view.php'));

self::assertTrue($loader->exists('default:inner/partial/view'));
self::assertTrue($loader->exists('default:inner/partial/view.php'));
$this->assertTrue($loader->exists('default:inner/partial/view'));
$this->assertTrue($loader->exists('default:inner/partial/view.php'));

self::assertTrue($loader->exists('@default/inner/partial/view'));
self::assertTrue($loader->exists('@default/inner/partial/view.php'));
$this->assertTrue($loader->exists('@default/inner/partial/view'));
$this->assertTrue($loader->exists('@default/inner/partial/view.php'));
}

public function testList(): void
Expand All @@ -85,10 +85,10 @@ public function testList(): void
$loader = $loader->withExtension('php');
$files = $loader->list();

self::assertContains('default:view', $files);
self::assertContains('default:inner/view', $files);
self::assertContains('default:inner/partial/view', $files);
self::assertNotContains('default:inner/file', $files);
$this->assertContains('default:view', $files);
$this->assertContains('default:inner/view', $files);
$this->assertContains('default:inner/partial/view', $files);
$this->assertNotContains('default:inner/file', $files);
}

public function testLoadNotFound(): void
Expand Down Expand Up @@ -145,18 +145,18 @@ public function testLoad(): void
$loader = $loader->withExtension('php');

$source = $loader->load('inner/partial/view');
self::assertNotNull($source);
$this->assertNotNull($source);

self::assertSame('inner/partial/view', $source->getName());
self::assertSame('default', $source->getNamespace());
self::assertFileExists($source->getFilename());
$this->assertSame('inner/partial/view', $source->getName());
$this->assertSame('default', $source->getNamespace());
$this->assertFileExists($source->getFilename());

self::assertSame('hello inner partial world', $source->getCode());
$this->assertSame('hello inner partial world', $source->getCode());

$newSource = $source->withCode('new code');

self::assertSame('new code', $newSource->getCode());
self::assertSame('hello inner partial world', $source->getCode());
$this->assertSame('new code', $newSource->getCode());
$this->assertSame('hello inner partial world', $source->getCode());
}

public function testMultipleNamespaces(): void
Expand All @@ -169,15 +169,15 @@ public function testMultipleNamespaces(): void

$loader = $loader->withExtension('php');

self::assertTrue($loader->exists('other:view'));
self::assertFalse($loader->exists('non-existed:view'));
$this->assertTrue($loader->exists('other:view'));
$this->assertFalse($loader->exists('non-existed:view'));

$files = $loader->list();
self::assertContains('default:view', $files);
self::assertContains('other:view', $files);
$this->assertContains('default:view', $files);
$this->assertContains('other:view', $files);

$files = $loader->list('other');
self::assertCount(5, $files);
self::assertContains('other:view', $files);
$this->assertCount(5, $files);
$this->assertContains('other:view', $files);
}
}
Loading

0 comments on commit d2124f5

Please sign in to comment.