From b71675583d1f6577181edd13a1f01a4910062723 Mon Sep 17 00:00:00 2001 From: Maxim Smakouz Date: Wed, 31 Jan 2024 16:17:50 +0200 Subject: [PATCH] Fixed installation without template engine and translator (#144) * Fix plain php template, tests * Improve template * Fix StyleCI config --- .styleci.yml | 1 - .../Feature/Controller/HomeControllerTest.php | 26 ++++--- .../PlainPHP/resources/views/home.php | 9 ++- .../Tests/Feature/Application/WebTest.php | 73 +++++++++++++++++++ 4 files changed, 96 insertions(+), 13 deletions(-) diff --git a/.styleci.yml b/.styleci.yml index 1278d08..9d2c5f3 100644 --- a/.styleci.yml +++ b/.styleci.yml @@ -8,7 +8,6 @@ enabled: - linebreak_after_opening_tag - single_quote - no_blank_lines_after_phpdoc - - unary_operator_spaces - no_useless_else - no_useless_return - trailing_comma_in_multiline_array diff --git a/installer/Application/Web/resources/skeleton/tests/Feature/Controller/HomeControllerTest.php b/installer/Application/Web/resources/skeleton/tests/Feature/Controller/HomeControllerTest.php index 7b55566..294ecf1 100644 --- a/installer/Application/Web/resources/skeleton/tests/Feature/Controller/HomeControllerTest.php +++ b/installer/Application/Web/resources/skeleton/tests/Feature/Controller/HomeControllerTest.php @@ -4,6 +4,7 @@ namespace Tests\Feature\Controller; +use Spiral\Bootloader\I18nBootloader; use Tests\TestCase; use Spiral\Testing\Http\FakeHttp; @@ -20,19 +21,26 @@ protected function setUp(): void public function testDefaultActionWorks(): void { - $this->http - ->get('/') - ->assertOk() - ->assertBodyContains('The PHP Framework for future Innovators'); + $response = $this->http->get('/')->assertOk(); + + $this->assertStringContainsString( + 'The PHP Framework for future Innovators', + \strip_tags((string) $response->getOriginalResponse()->getBody()) + ); } public function testDefaultActionWithRuLocale(): void { - $this->http - ->withHeader('accept-language', 'ru') - ->get('/') - ->assertOk() - ->assertBodyContains('PHP Framework для будущих инноваторов'); + if (!\in_array(I18nBootloader::class, $this->getRegisteredBootloaders())) { + $this->markTestSkipped('Component `spiral/translator` is not installed.'); + } + + $response = $this->http->withHeader('accept-language', 'ru')->get('/')->assertOk(); + + $this->assertStringContainsString( + 'PHP Framework для будущих инноваторов', + \strip_tags((string) $response->getOriginalResponse()->getBody()) + ); } public function testInteractWithConsole(): void diff --git a/installer/Module/TemplateEngines/PlainPHP/resources/views/home.php b/installer/Module/TemplateEngines/PlainPHP/resources/views/home.php index a4f4cc5..b878ed0 100644 --- a/installer/Module/TemplateEngines/PlainPHP/resources/views/home.php +++ b/installer/Module/TemplateEngines/PlainPHP/resources/views/home.php @@ -1,8 +1,11 @@ -container->get(\Spiral\Translator\TranslatorInterface::class); ?> +container->has(\Spiral\Translator\TranslatorInterface::class) + ? $this->container->get(\Spiral\Translator\TranslatorInterface::class) + : null; +?> - + - <?=$translator->trans('The PHP Framework for future Innovators')?> + <?=$translator?->trans('The PHP Framework for future Innovators') ?? 'The PHP Framework for future Innovators'?> diff --git a/installer/Tests/Feature/Application/WebTest.php b/installer/Tests/Feature/Application/WebTest.php index 3403c7d..c643217 100644 --- a/installer/Tests/Feature/Application/WebTest.php +++ b/installer/Tests/Feature/Application/WebTest.php @@ -107,6 +107,7 @@ public function testStemplerTemplateEngine(): void { $result = $this ->install(Application::class) + ->withSkeleton() ->addAnswer(Module\TemplateEngines\Question::class, 1) ->addModule(new TestModule\Console()) ->addModule(new TestModule\RoadRunnerBridge()) @@ -128,6 +129,7 @@ public function testTwigTemplateEngine(): void { $result = $this ->install(Application::class) + ->withSkeleton() ->addAnswer(Module\TemplateEngines\Question::class, 2) ->addModule(new TestModule\Console()) ->addModule(new TestModule\RoadRunnerBridge()) @@ -149,7 +151,78 @@ public function testPlainPHPTemplateEngine(): void { $result = $this ->install(Application::class) + ->withSkeleton() + ->addAnswer(Module\TemplateEngines\Question::class, 3) + ->addModule(new TestModule\Console()) + ->addModule(new TestModule\RoadRunnerBridge()) + ->addModule(new TestModule\RoadRunnerCli()) + ->addModule(new TestModule\YiiErrorHandler()) + ->addModule(new TestModule\NyholmPsr7()) + ->addModule(new TestModule\Dumper()) + ->addModule(new TestModule\ExtSockets()) + ->addModule(new TestModule\ExtMbString()) + ->addModule(new TestModule\Exception()) + ->addModule(new TestModule\TemplateEngines\PlainPHP()) + ->addModule(new TestModule\Http()) + ->run(); + + $result->storeLog(); + } + + public function testWithoutTranslatorStempler(): void + { + $result = $this + ->install(Application::class) + ->withSkeleton() + ->addAnswer(Module\TemplateEngines\Question::class, 1) + ->addAnswer(Module\Translator\Question::class, false) + ->addModule(new TestModule\Console()) + ->addModule(new TestModule\RoadRunnerBridge()) + ->addModule(new TestModule\RoadRunnerCli()) + ->addModule(new TestModule\YiiErrorHandler()) + ->addModule(new TestModule\NyholmPsr7()) + ->addModule(new TestModule\Dumper()) + ->addModule(new TestModule\ExtSockets()) + ->addModule(new TestModule\ExtMbString()) + ->addModule(new TestModule\Exception()) + ->addModule(new TestModule\TemplateEngines\Stempler()) + ->addModule(new TestModule\Http()) + ->run(); + + $result->storeLog(); + } + + public function testWithoutTranslatorTwig(): void + { + $result = $this + ->install(Application::class) + ->withSkeleton() + ->addAnswer(Module\TemplateEngines\Question::class, 2) + ->addAnswer(Module\Translator\Question::class, false) + ->addAnswer(Module\Translator\Question::class, false) + ->addModule(new TestModule\Console()) + ->addModule(new TestModule\RoadRunnerBridge()) + ->addModule(new TestModule\RoadRunnerCli()) + ->addModule(new TestModule\YiiErrorHandler()) + ->addModule(new TestModule\NyholmPsr7()) + ->addModule(new TestModule\Dumper()) + ->addModule(new TestModule\ExtSockets()) + ->addModule(new TestModule\ExtMbString()) + ->addModule(new TestModule\Exception()) + ->addModule(new TestModule\TemplateEngines\Twig()) + ->addModule(new TestModule\Http()) + ->run(); + + $result->storeLog(); + } + + public function testWithoutTranslatorPlainPhp(): void + { + $result = $this + ->install(Application::class) + ->withSkeleton() ->addAnswer(Module\TemplateEngines\Question::class, 3) + ->addAnswer(Module\Translator\Question::class, false) ->addModule(new TestModule\Console()) ->addModule(new TestModule\RoadRunnerBridge()) ->addModule(new TestModule\RoadRunnerCli())