From 0e4a0f4b3c8e11f3cabffc7ed87ace6c559e6ae4 Mon Sep 17 00:00:00 2001 From: spiralbot Date: Tue, 7 Jan 2025 13:34:12 +0000 Subject: [PATCH] prepare release --- composer.json | 6 ++-- src/ViewManager.php | 2 +- tests/CacheTest.php | 34 +++++++++--------- tests/ConfigTest.php | 21 +++++++---- tests/ContextProcessorTest.php | 12 +++---- tests/ContextTest.php | 4 +-- tests/GeneratorTest.php | 26 +++++++------- tests/GlobalVariablesTest.php | 6 ++-- tests/LoaderTest.php | 64 +++++++++++++++++----------------- tests/ManagerTest.php | 18 +++++----- tests/NativeTest.php | 6 ++-- 11 files changed, 104 insertions(+), 95 deletions(-) diff --git a/composer.json b/composer.json index 7eb0bc03..58f2827e 100644 --- a/composer.json +++ b/composer.json @@ -34,12 +34,12 @@ ], "require": { "php": ">=8.1", - "spiral/core": "^3.15", - "spiral/files": "^3.15", + "spiral/core": "^3.14.9", + "spiral/files": "^3.14.9", "psr/event-dispatcher": "^1.0" }, "require-dev": { - "spiral/boot": "^3.15", + "spiral/boot": "^3.14.9", "phpunit/phpunit": "^10.1", "mockery/mockery": "^1.5", "vimeo/psalm": "^5.9" diff --git a/src/ViewManager.php b/src/ViewManager.php index 7f310331..3ec28752 100644 --- a/src/ViewManager.php +++ b/src/ViewManager.php @@ -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() ?? '' )); diff --git a/tests/CacheTest.php b/tests/CacheTest.php index 13c3f223..f967c204 100644 --- a/tests/CacheTest.php +++ b/tests/CacheTest.php @@ -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 @@ -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 @@ -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 @@ -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 @@ -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 diff --git a/tests/ConfigTest.php b/tests/ConfigTest.php index 9fdf2cb7..7c3c21f3 100644 --- a/tests/ConfigTest.php +++ b/tests/ConfigTest.php @@ -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 @@ -34,7 +34,7 @@ public function testNamespace(): void ], ]); - self::assertSame([ + $this->assertSame([ 'default' => [__DIR__], ], $config->getNamespaces()); } @@ -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 @@ -70,6 +76,9 @@ public function testDependencies(): void ], ]); - self::assertSame($dependency, $config->getDependencies()[0]->resolve($container)); + $this->assertSame( + $dependency, + $config->getDependencies()[0]->resolve($container) + ); } } diff --git a/tests/ContextProcessorTest.php b/tests/ContextProcessorTest.php index 63308f79..df549090 100644 --- a/tests/ContextProcessorTest.php +++ b/tests/ContextProcessorTest.php @@ -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 @@ -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 @@ -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 diff --git a/tests/ContextTest.php b/tests/ContextTest.php index 8aea5a46..b5ad75a1 100644 --- a/tests/ContextTest.php +++ b/tests/ContextTest.php @@ -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 @@ -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')); } } diff --git a/tests/GeneratorTest.php b/tests/GeneratorTest.php index cb87fcb5..244aa39a 100644 --- a/tests/GeneratorTest.php +++ b/tests/GeneratorTest.php @@ -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 @@ -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 @@ -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 @@ -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')); } } diff --git a/tests/GlobalVariablesTest.php b/tests/GlobalVariablesTest.php index b51efa01..9ac19c82 100644 --- a/tests/GlobalVariablesTest.php +++ b/tests/GlobalVariablesTest.php @@ -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']); } } diff --git a/tests/LoaderTest.php b/tests/LoaderTest.php index cec83a09..3c541133 100644 --- a/tests/LoaderTest.php +++ b/tests/LoaderTest.php @@ -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 @@ -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 @@ -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 @@ -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); } } diff --git a/tests/ManagerTest.php b/tests/ManagerTest.php index de092489..2a71ee0e 100644 --- a/tests/ManagerTest.php +++ b/tests/ManagerTest.php @@ -37,7 +37,7 @@ public function testMultipleEngines(): void $ext[] = $e->getLoader()->getExtension(); } - self::assertSame(['dark.php', 'php'], $ext); + $this->assertSame(['dark.php', 'php'], $ext); } public function testRender(): void @@ -45,7 +45,7 @@ public function testRender(): void $manager = $this->makeManager(); $manager->addDependency(new ValueDependency('name', 'hello')); - self::assertSame('hello', $manager->render('other:var', ['value' => 'hello'])); + $this->assertSame('hello', $manager->render('other:var', ['value' => 'hello'])); } public function testGet(): void @@ -54,10 +54,10 @@ public function testGet(): void $manager->addDependency(new ValueDependency('name', 'hello')); $view = $manager->get('other:var'); - self::assertSame($view, $manager->get('other:var')); + $this->assertSame($view, $manager->get('other:var')); $manager->reset('other:var'); - self::assertNotSame($view, $manager->get('other:var')); + $this->assertNotSame($view, $manager->get('other:var')); } public function testCompile(): void @@ -72,10 +72,10 @@ public function testCompile(): void $manager->addDependency(new ValueDependency('name', 'hello')); $manager->render('other:var', ['value' => 'hello']); - self::assertTrue($cache->has($manager->getContext(), 'other:var')); + $this->assertTrue($cache->has($manager->getContext(), 'other:var')); $manager->compile('other:var'); - self::assertFalse($cache->has($manager->getContext(), 'other:var')); + $this->assertFalse($cache->has($manager->getContext(), 'other:var')); } public function testReset(): void @@ -91,16 +91,16 @@ public function testReset(): void $manager->addDependency(new ValueDependency('name', 'hello')); $manager->render('other:var', ['value' => 'hello']); - self::assertTrue($cache->has($manager->getContext(), 'other:var')); + $this->assertTrue($cache->has($manager->getContext(), 'other:var')); $manager->reset('other:var'); - self::assertFalse($cache->has($manager->getContext(), 'other:var')); + $this->assertFalse($cache->has($manager->getContext(), 'other:var')); } public function testEngines(): void { $manager = $this->makeManager(); - self::assertInstanceOf(NativeEngine::class, $manager->getEngines()[0]); + $this->assertInstanceOf(NativeEngine::class, $manager->getEngines()[0]); } public function testNotFound(): void diff --git a/tests/NativeTest.php b/tests/NativeTest.php index cf8bfc48..da8ea8f0 100644 --- a/tests/NativeTest.php +++ b/tests/NativeTest.php @@ -30,7 +30,7 @@ public function testGet(): void $engine->compile('other:view', new ViewContext()); $view = $engine->get('other:view', $ctx = new ViewContext()); - self::assertSame('other world', $view->render([])); + $this->assertSame('other world', $view->render([])); } public function testGetNoLoader(): void @@ -55,7 +55,7 @@ public function testRenderWithValue(): void $engine = $engine->withLoader($loader); $view = $engine->get('other:var', $ctx = new ViewContext()); - self::assertSame('hello', $view->render(['value' => 'hello'])); + $this->assertSame('hello', $view->render(['value' => 'hello'])); } public function testRenderException(): void @@ -92,7 +92,7 @@ public function testRenderBufferWithValue(): void $engine = $engine->withLoader($loader); $view = $engine->get('other:buf', $ctx = new ViewContext()); - self::assertSame('', $view->render(['value' => 'hello'])); + $this->assertSame('', $view->render(['value' => 'hello'])); } public function testRenderBufferException(): void