From 37f08320eaa94bc4dd393692d7387cdc3d2eb50c Mon Sep 17 00:00:00 2001 From: Wim Reckman Date: Wed, 4 Aug 2021 11:22:48 +0200 Subject: [PATCH] Make tests pass on Windows (#1205) * Make all tests pass cross platform * Add job to run tests on Windows * Merge test jobs with conditional Windows step for line endings * Prefix job name with OS * Update git lf step if statement * Exclude all tests for Windows except PHP 8.0 * composer fix-style Co-authored-by: Barry vd. Heuvel Co-authored-by: laravel-ide-helper --- .github/workflows/run-tests.yml | 22 +++++++++++++---- src/Console/ModelsCommand.php | 2 +- tests/Console/EloquentCommandTest.php | 5 +++- .../ModelsCommand/DynamicRelations/Test.php | 24 ++++++++++--------- .../ModelsCommand/Variadic/Models/Simple.php | 1 - 5 files changed, 35 insertions(+), 19 deletions(-) diff --git a/.github/workflows/run-tests.yml b/.github/workflows/run-tests.yml index f5d65af..cc32341 100644 --- a/.github/workflows/run-tests.yml +++ b/.github/workflows/run-tests.yml @@ -12,19 +12,31 @@ on: jobs: php-tests: - runs-on: ubuntu-20.04 + runs-on: ${{ matrix.os }} timeout-minutes: 15 env: COMPOSER_NO_INTERACTION: 1 strategy: matrix: + os: [ubuntu-20.04, windows-2019] php: [8.0, 7.4, 7.3] laravel: [8.*] - - name: P${{ matrix.php }} - L${{ matrix.laravel }} - + dependency-version: [prefer-lowest, prefer-stable] + exclude: + - php: 8.0 + dependency-version: prefer-lowest + - os: windows-2019 + php: 7.4 + - os: windows-2019 + php: 7.3 steps: + - name: Set git to use LF + if: ${{ matrix.os == 'windows-2019' }} + run: | + git config --global core.autocrlf false + git config --global core.eol lf + - name: Checkout code uses: actions/checkout@v2 @@ -33,7 +45,7 @@ jobs: with: php-version: ${{ matrix.php }} coverage: none - extensions: pdo_sqlite + extensions: pdo_sqlite, fileinfo - name: Install dependencies run: | diff --git a/src/Console/ModelsCommand.php b/src/Console/ModelsCommand.php index 4a40ca8..c6fe186 100644 --- a/src/Console/ModelsCommand.php +++ b/src/Console/ModelsCommand.php @@ -431,7 +431,7 @@ class ModelsCommand extends Command $customTypes = $this->laravel['config']->get("ide-helper.custom_db_types.{$platformName}", []); foreach ($customTypes as $yourTypeName => $doctrineTypeName) { try { - if(!Type::hasType($yourTypeName)) { + if (!Type::hasType($yourTypeName)) { Type::addType($yourTypeName, get_class(Type::getType($doctrineTypeName))); } } catch (DBALException $exception) { diff --git a/tests/Console/EloquentCommandTest.php b/tests/Console/EloquentCommandTest.php index cf32c27..322cbcd 100644 --- a/tests/Console/EloquentCommandTest.php +++ b/tests/Console/EloquentCommandTest.php @@ -49,8 +49,11 @@ class EloquentCommandTest extends TestCase ';Unexpected no document on Illuminate\\\Database\\\Eloquent\\\Model;', $display ); + $modelClassFilePath = preg_quote( + str_replace('/', DIRECTORY_SEPARATOR, '/vendor/laravel/framework/src/Illuminate/Database/Eloquent/Model.php') + ); $this->assertRegExp( - ';Wrote expected docblock to .*/vendor/laravel/framework/src/Illuminate/Database/Eloquent/Model.php;', + ';Wrote expected docblock to .*' . $modelClassFilePath . ';', $display ); } diff --git a/tests/Console/ModelsCommand/DynamicRelations/Test.php b/tests/Console/ModelsCommand/DynamicRelations/Test.php index a36f8f0..dedfb22 100644 --- a/tests/Console/ModelsCommand/DynamicRelations/Test.php +++ b/tests/Console/ModelsCommand/DynamicRelations/Test.php @@ -18,22 +18,24 @@ class Test extends AbstractModelsCommand ]); if (PHP_VERSION_ID >= 80000) { - $errors = <<assertSame(0, $tester->getStatusCode()); $this->assertStringContainsString('Written new phpDocBlock to', $tester->getDisplay()); - $this->assertStringContainsString($errors, $tester->getDisplay()); + foreach ($errors as $error) { + $this->assertStringContainsString($error, $tester->getDisplay()); + } $this->assertMatchesMockedSnapshot(); } } diff --git a/tests/Console/ModelsCommand/Variadic/Models/Simple.php b/tests/Console/ModelsCommand/Variadic/Models/Simple.php index 7932295..067f066 100644 --- a/tests/Console/ModelsCommand/Variadic/Models/Simple.php +++ b/tests/Console/ModelsCommand/Variadic/Models/Simple.php @@ -4,7 +4,6 @@ declare(strict_types=1); namespace Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\Variadic\Models; -use DateTime; use Illuminate\Database\Eloquent\Builder; use Illuminate\Database\Eloquent\Model;