From 6b9ff393c21ae37d73eee41115b35b93c4bcf6af Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Juan=20Jos=C3=A9=20Llorens?= Date: Thu, 26 Sep 2024 13:04:25 +0200 Subject: [PATCH] Add github workflows --- .github/workflows/analyse.yml | 36 ++++++++++ .github/workflows/tests.yml | 72 +++++++++++++++++++ .../NotificationManagerTest.php | 6 +- 3 files changed, 111 insertions(+), 3 deletions(-) create mode 100644 .github/workflows/analyse.yml create mode 100644 .github/workflows/tests.yml diff --git a/.github/workflows/analyse.yml b/.github/workflows/analyse.yml new file mode 100644 index 0000000..9de01e6 --- /dev/null +++ b/.github/workflows/analyse.yml @@ -0,0 +1,36 @@ +name: Analyse + +on: + push: + branches: [master] + pull_request: + branches: [master] + +jobs: + phpstan: + runs-on: ubuntu-latest + + steps: + - name: Checkout code + uses: actions/checkout@v4 + + - name: Setup PHP + uses: shivammathur/setup-php@v2 + with: + php-version: 8.0 + + - name: Cache Composer packages + id: composer-cache + uses: actions/cache@v4 + with: + path: vendor + key: ${{ runner.os }}-php-8.0-${{ hashFiles('**/composer.json') }} + restore-keys: | + ${{ runner.os }}-php-8.0- + + - name: Install dependencies + run: | + composer install --no-interaction --no-progress + + - name: Run analyse phpstan + run: vendor/bin/phpstan analyse src tests --error-format github diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml new file mode 100644 index 0000000..781bef0 --- /dev/null +++ b/.github/workflows/tests.yml @@ -0,0 +1,72 @@ +name: Tests + +on: + push: + branches: [master] + pull_request: + branches: [master] + +jobs: + phpunit: + runs-on: ubuntu-latest + + strategy: + fail-fast: true + matrix: + php: [8.1, 8.2, 8.3] + laravel: [8.*, 9.*, 10.*, 11.*] + include: + - laravel: 8.* + testbench: 6.* + - laravel: 9.* + testbench: 7.* + - laravel: 10.* + testbench: 8.* + - laravel: 11.* + testbench: 9.* + exclude: + - laravel: 8.* + php: 8.2 + - laravel: 8.* + php: 8.3 + - laravel: 9.* + php: 8.3 + - laravel: 11.* + php: 8.1 + + steps: + - name: Checkout code + uses: actions/checkout@v4 + + - name: Setup PHP + uses: shivammathur/setup-php@v2 + with: + php-version: ${{ matrix.php }} + extensions: curl, pdo, sqlite, pdo_sqlite + + - name: Install SQLite 3 + run: | + sudo apt-get update + sudo apt-get install sqlite3 + + - name: Validate composer.json + run: composer validate + + - name: Cache Composer packages + id: composer-cache + uses: actions/cache@v4 + with: + path: vendor + key: ${{ runner.os }}-php-${{ matrix.php }}-laravel-${{ matrix.laravel }}-${{ hashFiles('**/composer.lock') }} + restore-keys: | + ${{ runner.os }}-php-${{ matrix.php }}-laravel-${{ matrix.laravel }}- + + + - name: Install dependencies + if: steps.composer-cache.outputs.cache-hit != 'true' + run: | + composer require "laravel/framework:${{ matrix.laravel }}" "orchestra/testbench:${{ matrix.testbench }}" --no-interaction --no-update + composer update --prefer-stable --prefer-dist --no-interaction + + - name: Run test phpunit + run: vendor/bin/phpunit --stop-on-error --stop-on-failure diff --git a/tests/Services/NotificationManager/NotificationManagerTest.php b/tests/Services/NotificationManager/NotificationManagerTest.php index aec69e0..38288f6 100644 --- a/tests/Services/NotificationManager/NotificationManagerTest.php +++ b/tests/Services/NotificationManager/NotificationManagerTest.php @@ -21,7 +21,7 @@ public function testLoggedEmail() // Simula la respuesta HTTP Http::fake([ - config('descom_lib.notification_manager.url') => Http::sequence()->push($responseExpected) + '*' => Http::response($responseExpected, 200) ]); $notificationManager = new NotificationManager; @@ -39,7 +39,7 @@ public function testLoggedEmailPermanentException() // Simula la respuesta HTTP con un código 404 Http::fake([ - config('descom_lib.notification_manager.url') => Http::response(null, 404) + '*' => Http::response([], 404) ]); $notificationManager = new NotificationManager; @@ -59,7 +59,7 @@ public function testLoggedEmailTemporaryException() // Simula la respuesta HTTP con un código 503 Http::fake([ - config('descom_lib.notification_manager.url') => Http::response(null, 503) + '*' => Http::response([], 503) ]); $notificationManager = new NotificationManager;