From 5c363c353602745eab0098c77d761265a1d1e9c8 Mon Sep 17 00:00:00 2001 From: RJ Garcia Date: Sat, 2 Nov 2024 10:59:34 -0400 Subject: [PATCH] fix phpunit deprecations --- .github/workflows/php.yml | 3 -- .gitignore | 1 + phpunit.xml.dist | 50 ++++++++++-------------------- tests/Template/ThemeTest.php | 59 ++++++++++++++++++++++-------------- 4 files changed, 53 insertions(+), 60 deletions(-) diff --git a/.github/workflows/php.yml b/.github/workflows/php.yml index 94c905c5..bbfdfbf3 100644 --- a/.github/workflows/php.yml +++ b/.github/workflows/php.yml @@ -8,7 +8,6 @@ jobs: strategy: matrix: php-versions: ["8.2", "8.3", "8.4"] - phpunit-versions: ["11.4"] steps: - name: Checkout uses: actions/checkout@v4 @@ -19,8 +18,6 @@ jobs: php-version: ${{ matrix.php-versions }} extensions: mbstring, intl ini-values: post_max_size=256M, max_execution_time=180 - coverage: xdebug - tools: php-cs-fixer, phpunit:${{ matrix.phpunit-versions }} env: GITHUB_TOKEN: ${{ secrets.GH_ACCESS_TOKEN }} diff --git a/.gitignore b/.gitignore index 280b0554..d41b0552 100644 --- a/.gitignore +++ b/.gitignore @@ -5,3 +5,4 @@ build /doc/.hugo_build.lock .generated .phpunit.result.cache +.phpunit.cache diff --git a/phpunit.xml.dist b/phpunit.xml.dist index 2184ac97..14c25336 100755 --- a/phpunit.xml.dist +++ b/phpunit.xml.dist @@ -1,36 +1,18 @@ - - - - - ./tests - - - - - - src - - - - - - - - - + + + + ./tests + + + + + + + + + + src + + diff --git a/tests/Template/ThemeTest.php b/tests/Template/ThemeTest.php index ef60c7ec..e4b8cc40 100644 --- a/tests/Template/ThemeTest.php +++ b/tests/Template/ThemeTest.php @@ -5,7 +5,7 @@ use League\Plates\Engine; use League\Plates\Template\Theme; use org\bovigo\vfs\vfsStream; -use PHPUnit\Framework\TestCase; +use PHPUnit\Framework\{TestCase, Attributes\Test}; final class ThemeTest extends TestCase { @@ -16,16 +16,18 @@ final class ThemeTest extends TestCase /** @var \Throwable */ private $exception; - /** @test */ - public function engine_renders_with_single_themes() { + #[Test] + public function engine_renders_with_single_themes() + { $this->given_a_directory_structure_is_setup_like('templates', ['main.php' => '']); $this->given_an_engine_is_created_with_theme(Theme::new($this->vfsPath('templates'))); $this->when_the_engine_renders('main'); $this->then_the_rendered_template_matches(''); } - /** @test */ - public function engine_renders_with_theme_hierarchy() { + #[Test] + public function engine_renders_with_theme_hierarchy() + { $this->given_a_directory_structure_is_setup_like('templates', [ 'parent' => [ 'main.php' => 'layout("layout") ?>parent', @@ -43,9 +45,10 @@ public function engine_renders_with_theme_hierarchy() { $this->then_the_rendered_template_matches('child: parent'); } - /** @test */ - public function duplicate_theme_names_in_hierarchies_are_not_allowed() { - $this->when_a_theme_is_created_like(function() { + #[Test] + public function duplicate_theme_names_in_hierarchies_are_not_allowed() + { + $this->when_a_theme_is_created_like(function () { Theme::hierarchy([ Theme::new('templates/a'), Theme::new('templates/b'), @@ -54,9 +57,10 @@ public function duplicate_theme_names_in_hierarchies_are_not_allowed() { $this->then_an_exception_is_thrown_with_message('Duplicate theme names in hierarchies are not allowed. Received theme names: [Default, Default].'); } - /** @test */ - public function nested_hierarchies_are_not_allowed() { - $this->when_a_theme_is_created_like(function() { + #[Test] + public function nested_hierarchies_are_not_allowed() + { + $this->when_a_theme_is_created_like(function () { Theme::hierarchy([ Theme::hierarchy([Theme::new('templates', 'A'), Theme::new('templates', 'B')]) ]); @@ -64,16 +68,18 @@ public function nested_hierarchies_are_not_allowed() { $this->then_an_exception_is_thrown_with_message('Nested theme hierarchies are not allowed, make sure to use Theme::new when creating themes in your hierarchy. Theme B is already in a hierarchy.'); } - /** @test */ - public function empty_hierarchies_are_not_allowed() { - $this->when_a_theme_is_created_like(function() { + #[Test] + public function empty_hierarchies_are_not_allowed() + { + $this->when_a_theme_is_created_like(function () { Theme::hierarchy([]); }); $this->then_an_exception_is_thrown_with_message('Empty theme hierarchies are not allowed.'); } - /** @test */ - public function template_not_found_errors_reference_themes_checked() { + #[Test] + public function template_not_found_errors_reference_themes_checked() + { $this->given_a_directory_structure_is_setup_like('templates', []); $this->given_an_engine_is_created_with_theme(Theme::hierarchy([ Theme::new($this->vfsPath('templates/one'), 'One'), @@ -83,16 +89,19 @@ public function template_not_found_errors_reference_themes_checked() { $this->then_an_exception_is_thrown_with_message('The template "main" was not found in the following themes: Two:vfs://templates/two/main.php, One:vfs://templates/one/main.php'); } - private function given_a_directory_structure_is_setup_like(string $rootDir, array $directoryStructure) { + private function given_a_directory_structure_is_setup_like(string $rootDir, array $directoryStructure) + { vfsStream::setup($rootDir); vfsStream::create($directoryStructure); } - private function given_an_engine_is_created_with_theme(Theme $theme) { + private function given_an_engine_is_created_with_theme(Theme $theme) + { $this->engine = \League\Plates\Engine::fromTheme($theme); } - private function when_a_theme_is_created_like(callable $fn) { + private function when_a_theme_is_created_like(callable $fn) + { try { $fn(); } catch (\Throwable $e) { @@ -100,11 +109,13 @@ private function when_a_theme_is_created_like(callable $fn) { } } - private function vfsPath(string $path): string { + private function vfsPath(string $path): string + { return vfsStream::url($path); } - private function when_the_engine_renders(string $templateName, array $data = []) { + private function when_the_engine_renders(string $templateName, array $data = []) + { try { $this->result = $this->engine->render($templateName, $data); } catch (\Throwable $e) { @@ -112,7 +123,8 @@ private function when_the_engine_renders(string $templateName, array $data = []) } } - private function then_the_rendered_template_matches(string $expected) { + private function then_the_rendered_template_matches(string $expected) + { if ($this->exception) { throw $this->exception; } @@ -120,7 +132,8 @@ private function then_the_rendered_template_matches(string $expected) { $this->assertEquals($expected, $this->result); } - private function then_an_exception_is_thrown_with_message(string $expectedMessage) { + private function then_an_exception_is_thrown_with_message(string $expectedMessage) + { $this->assertNotNull($this->exception, 'Expected an exception to be thrown with message: ' . $expectedMessage); $this->assertEquals($expectedMessage, $this->exception->getMessage(), 'Expected an exception to be thrown with message: ' . $expectedMessage); }