From 77069e553879f1188820b064c667de4e3569fab5 Mon Sep 17 00:00:00 2001 From: Mior Muhammad Zaki Date: Mon, 7 Apr 2025 07:24:47 +0800 Subject: [PATCH] [11.x] Test Improvements Signed-off-by: Mior Muhammad Zaki --- .github/workflows/tests.yml | 31 +++++++++------------------- tests/Integration/View/BladeTest.php | 22 ++++++++++++++------ 2 files changed, 26 insertions(+), 27 deletions(-) diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index 70b4ff968674..ed1199b07aa9 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -40,11 +40,13 @@ jobs: fail-fast: true matrix: php: [8.2, 8.3, 8.4] - phpunit: ['10.5.35', '11.3.2', '12.0.0'] + phpunit: ['10.5.35', '11.3.2', '12.0.0', '12.1.0'] stability: [prefer-lowest, prefer-stable] exclude: - php: 8.2 phpunit: '12.0.0' + - php: 8.2 + phpunit: '12.1.0' name: PHP ${{ matrix.php }} - PHPUnit ${{ matrix.phpunit }} - ${{ matrix.stability }} @@ -76,19 +78,12 @@ jobs: shell: bash if: matrix.php >= 8.4 - - name: Set PHPUnit - uses: nick-fields/retry@v3 - with: - timeout_minutes: 5 - max_attempts: 5 - command: composer require phpunit/phpunit:^${{ matrix.phpunit }} --dev --no-interaction --no-update - - name: Install dependencies uses: nick-fields/retry@v3 with: timeout_minutes: 5 max_attempts: 5 - command: composer update --${{ matrix.stability }} --prefer-dist --no-interaction --no-progress + command: composer update --${{ matrix.stability }} --prefer-dist --no-interaction --no-progress --with="phpunit/phpunit:~${{ matrix.phpunit }}" - name: Execute tests run: vendor/bin/phpunit --display-deprecation ${{ matrix.stability == 'prefer-stable' && '--fail-on-deprecation' || '' }} @@ -115,11 +110,13 @@ jobs: fail-fast: true matrix: php: [8.2, 8.3, 8.4] - phpunit: ['10.5', '11.0.1'] + phpunit: ['10.5.35', '11.3.2', '12.0.0', '12.1.0'] stability: [prefer-lowest, prefer-stable] exclude: - - php: 8.4 - stability: prefer-lowest + - php: 8.2 + phpunit: '12.0.0' + - php: 8.2 + phpunit: '12.1.0' name: PHP ${{ matrix.php }} - PHPUnit ${{ matrix.phpunit }} - ${{ matrix.stability }} - Windows @@ -143,20 +140,12 @@ jobs: - name: Set Framework version run: composer config version "11.x-dev" - - name: Set PHPUnit - uses: nick-fields/retry@v3 - with: - timeout_minutes: 5 - max_attempts: 5 - command: composer require phpunit/phpunit:^${{ matrix.phpunit }} --dev --no-interaction --no-update - shell: bash - - name: Install dependencies uses: nick-fields/retry@v3 with: timeout_minutes: 5 max_attempts: 5 - command: composer update --${{ matrix.stability }} --prefer-dist --no-interaction --no-progress + command: composer update --${{ matrix.stability }} --prefer-dist --no-interaction --no-progress --with="phpunit/phpunit:~${{ matrix.phpunit }}" - name: Execute tests run: vendor/bin/phpunit diff --git a/tests/Integration/View/BladeTest.php b/tests/Integration/View/BladeTest.php index 6495175337c4..1acb38372b86 100644 --- a/tests/Integration/View/BladeTest.php +++ b/tests/Integration/View/BladeTest.php @@ -11,8 +11,20 @@ use Symfony\Component\Finder\Finder; use Symfony\Component\Finder\SplFileInfo; +use function Orchestra\Testbench\artisan; +use function Orchestra\Testbench\phpunit_version_compare; + class BladeTest extends TestCase { + /** {@inheritdoc} */ + #[\Override] + protected function tearDown(): void + { + artisan($this, 'view:clear'); + + parent::tearDown(); + } + public function test_rendering_blade_string() { $this->assertSame('Hello Taylor', Blade::render('Hello {{ $name }}', ['name' => 'Taylor'])); @@ -33,8 +45,8 @@ public function test_rendering_blade_long_maxpathlen_string_with_exact_length() // The PHP_MAXPATHLEN restriction is only active, if // open_basedir is set and active. Otherwise, the check // for the PHP_MAXPATHLEN is not active. - if (ini_get('open_basedir') === '') { - $openBaseDir = windows_os() ? explode('\\', __DIR__)[0].'\\'.';'.sys_get_temp_dir() : '/'; + if (ini_get('open_basedir') === '' && phpunit_version_compare('12.1.0', '<')) { + $openBaseDir = explode(DIRECTORY_SEPARATOR, __DIR__)[0].DIRECTORY_SEPARATOR.PATH_SEPARATOR.sys_get_temp_dir(); $iniSet = ini_set( 'open_basedir', $openBaseDir @@ -197,8 +209,6 @@ public function test_bound_name_attribute_can_be_used_if_using_short_slot_names_ public function testViewCacheCommandHandlesConfiguredBladeExtensions() { - $this->artisan('view:clear'); - View::addExtension('sh', 'blade'); $this->artisan('view:cache'); @@ -206,10 +216,10 @@ public function testViewCacheCommandHandlesConfiguredBladeExtensions() $found = collect($compiledFiles) ->contains(fn (SplFileInfo $file) => str_contains($file->getContents(), 'echo "" > output.log')); $this->assertTrue($found); - - $this->artisan('view:clear'); } + /** {@inheritdoc} */ + #[\Override] protected function defineEnvironment($app) { $app['config']->set('view.paths', [__DIR__.'/templates']);