shivammathur / setup-php

GitHub action to set up PHP with extensions, php.ini configuration, coverage drivers, and various tools.
https://setup-php.com
MIT License
2.85k stars 334 forks source link

PDO Exception: could not find driver #854

Closed f-laino closed 1 month ago

f-laino commented 1 month ago

Describe the bug Throws PDO Exception when run phpunit tests on Laravel 5.8 (php 7.4) and external database connection.

Version

Runners

Operating systems Ubuntu 20.04

PHP versions 7.4

To Reproduce

name: Laravel

on:
  push:
    branches: [ "staging" ]
  pull_request:
    branches: [ "staging" ]

jobs:
  laravel-tests:

    runs-on: ubuntu-20.04

    env:
      DB_HOST: ${{ secrets.DB_HOST }}
      DB_DATABASE: ${{ secrets.DB_DATABASE }}
      DB_USERNAME: ${{ secrets.DB_USERNAME }}
      DB_PASSWORD: ${{ secrets.DB_PASSWORD }}

    steps:
    - name: Clear any existing tool cache
      run: |
        rm -rf "${{ runner.tool_cache }}" || true
    - uses: shivammathur/setup-php@verbose
      with:
        php-version: '7.4'
        extensions: dom, curl, intl, gd, exif, mbstring, xml, libxml, ctype, iconv, mysql, pdo, pdo_mysql, pdo_pgsql, pgsql, phar, fileinfo, sqlite3
    - uses: actions/checkout@v4
    - name: Copy .env
      run: php -r "copy('.env.test', '.env');"
    - name: Install Dependencies
      run: composer install -q --no-ansi --no-interaction --no-scripts --no-progress --prefer-dist
    - name: Directory Permissions
      run: mkdir -p storage/framework/cache/data storage/framework/cache/laravel-excel storage/framework/session storage/framework/views && chmod -R 777 storage bootstrap/cache
    - uses: php-actions/phpunit@v3
      name: Install PHPUnit and run test
      with:
        version: 9.5.4
        php_version: 7.4
        configuration: phpunit.xml
    - name: Setup PHPStan Action
      uses: NxtLvLSoftware/setup-phpstan-action@v1.0.2
      env:
          GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
      with:
        install-path: './bin'

Expected behavior Setup stack don't fail. I tried several configurations.

Screenshots/Logs

Run shivammathur/setup-php@verbose
  with:
    php-version: 7.4
    extensions: dom, curl, intl, gd, exif, mbstring, xml, libxml, ctype, iconv, mysql, pdo, pdo_mysql, pdo_pgsql, pgsql, phar, fileinfo, sqlite[3](https://github.com/DAICAR/iDeal/pull/292/checks#step:3:3)
    ini-file: production
  env:
    DB_HOST: ***
    DB_DATABASE: ***
    DB_USERNAME: ***
    DB_PASSWORD: ***
/usr/bin/bash /home/runner/work/_actions/shivammathur/setup-php/verbose/src/scripts/run.sh

==> Setup PHP
update-alternatives: using /usr/bin/phar7.[4](https://github.com/DAICAR/iDeal/pull/292/checks#step:3:4) to provide /usr/bin/phar (phar) in manual mode
update-alternatives: using /usr/bin/php-config7.4 to provide /usr/bin/php-config (php-config) in manual mode
update-alternatives: using /usr/bin/phpdbg[7](https://github.com/DAICAR/iDeal/pull/292/checks#step:3:7).4 to provide /usr/bin/phpdbg (phpdbg) in manual mode
update-alternatives: using /usr/bin/phpize7.4 to provide /usr/bin/phpize (phpize) in manual mode
update-alternatives: using /usr/bin/php7.4 to provide /usr/bin/php (php) in manual mode
update-alternatives: using /usr/bin/phar.phar7.4 to provide /usr/bin/phar.phar (phar.phar) in manual mode
update-alternatives: using /usr/lib/cgi-bin/php7.4 to provide /usr/lib/cgi-bin/php (php-cgi-bin) in manual mode
update-alternatives: using /usr/bin/php-cgi7.4 to provide /usr/bin/php-cgi (php-cgi) in manual mode
update-alternatives: error: alternative /run/php/php7.4-fpm.sock for php-fpm.sock not registered; not setting
update-alternatives: error: no alternatives for php-fpm
update-alternatives: using /usr/sbin/php-fpm7.4 to provide /usr/sbin/php-fpm (php-fpm) in auto mode
Reading package lists...
Building dependency tree...
Reading state information...

production
date.timezone=UTC
memory_limit=-1
xdebug.mode=coverage
php-version=7.4.33
cp: target '/opt/hostedtoolcache/' is not a directory
✓ PHP Found PHP 7.4.33

==> Setup Extensions
✓ dom Enabled
✓ curl Enabled
✓ intl Enabled
✓ gd Enabled
✓ exif Enabled
✓ mbstring Enabled
✓ xml Enabled
✓ libxml Enabled
✓ ctype Enabled
✓ iconv Enabled
✓ mysql Enabled
✓ pdo Enabled
✓ pdo_mysql Enabled
✓ pdo_pgsql Enabled
✓ pgsql Enabled
✓ phar Enabled
✓ fileinfo Enabled
✓ sqlite3 Enabled
Run php-actions/phpunit@v3
  with:
    version: 9.5.4
    php_version: 7.4
    configuration: phpunit.xml
    test_suffix: Test.php,.phpt
  env:
    DB_HOST: ***
    DB_DATABASE: ***
    DB_USERNAME: ***
    DB_PASSWORD: ***
    COMPOSER_PROCESS_TIMEOUT: 0
    COMPOSER_NO_INTERACTION: 1
    COMPOSER_NO_AUDIT: 1
Run set -e
  set -e
  bash <(curl -s https://raw.githubusercontent.com/php-actions/php-build/cee5b9fa9fbc4c888e7a6[2](https://github.com/DAICAR/iDeal/pull/292/checks#step:8:2)bbb7b8eade18e[3](https://github.com/DAICAR/iDeal/pull/292/checks#step:8:3)c56b/php-build.bash) phpunit
  /home/runner/work/_actions/php-actions/phpunit/v3/phpunit-action.bash
  shell: /usr/bin/bash --noprofile --norc -e -o pipefail {0}
  env:
    DB_HOST: ***
    DB_DATABASE: ***
    DB_USERNAME: ***
    DB_PASSWORD: ***
    COMPOSER_PROCESS_TIMEOUT: 0
    COMPOSER_NO_INTERACTION: 1
    COMPOSER_NO_AUDIT: 1
    ACTION_TOKEN: ***
    ACTION_VERSION: 9.5.[4](https://github.com/DAICAR/iDeal/pull/292/checks#step:8:4)
    ACTION_PHP_VERSION: 7.4
    ACTION_PHP_EXTENSIONS: 
    ACTION_PHPUNIT_PATH: 
    ACTION_CONFIGURATION: phpunit.xml
    ACTION_LOG_JUNIT: 
    ACTION_TESTDOX_HTML: 
    ACTION_TESTDOX_TEXT: 
    ACTION_BOOTSTRAP: 
    ACTION_FILTER: 
    ACTION_TESTSUITE: 
    ACTION_GROUP: 
    ACTION_EXCLUDE_GROUP: 
    ACTION_TEST_SUFFIX: Test.php,.phpt
    ACTION_WHITELIST: 
    ACTION_MEMORY_LIMIT: 
    ACTION_COVERAGE_CLOVER: 
    ACTION_COVERAGE_COBERTURA: 
    ACTION_COVERAGE_CRAP4J: 
    ACTION_COVERAGE_HTML: 
    ACTION_COVERAGE_PHP: 
    ACTION_COVERAGE_TEXT: 
    ACTION_COVERAGE_XML: 
    ACTION_ARGS: 

PHPUnit 9.5.4 by Sebastian Bergmann and contributors.
........EEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEE  3 / 113 ( 55%)
EEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEE              113 / 113 (100%)
Time: 00:00.855, Memory: 60.50 MB
There were 105 errors:
1) Tests\Unit\FeeTest::testFlatLeader
Doctrine\DBAL\Driver\PDO\Exception: could not find driver
/app/vendor/doctrine/dbal/lib/Doctrine/DBAL/Driver/PDO/Exception.php:18
/app/vendor/doctrine/dbal/lib/Doctrine/DBAL/Driver/PDOConnection.php:42
/app/vendor/laravel/framework/src/Illuminate/Database/Connectors/Connector.php:67
/app/vendor/laravel/framework/src/Illuminate/Database/Connectors/Connector.php:46
/app/vendor/laravel/framework/src/Illuminate/Database/Connectors/MySqlConnector.php:24
/app/vendor/laravel/framework/src/Illuminate/Database/Connectors/ConnectionFactory.php:182
/app/vendor/laravel/framework/src/Illuminate/Database/Connection.php:919
/app/vendor/laravel/framework/src/Illuminate/Database/Concerns/ManagesTransactions.php:109
/app/vendor/laravel/framework/src/Illuminate/Database/Concerns/ManagesTransactions.php:93
/app/vendor/laravel/framework/src/Illuminate/Foundation/Testing/DatabaseTransactions.php:17
/app/vendor/laravel/framework/src/Illuminate/Foundation/Testing/TestCase.php:122
/app/vendor/laravel/framework/src/Illuminate/Foundation/Testing/TestCase.php:81
/app/tests/Unit/FeeTest.php:40
Caused by
PDOException: could not find driver
shivammathur commented 1 month ago

Please do not run setup-php with actions that run in their own containers as they use their own php in the container. Please considering running phpunit directly by installing it as a composer dependency or using the tools input in setup-php action.