将 Laravel 从 9 升级到 10 和 phpunit 10,之后所有测试用例都失败了

问题描述 投票:0回答:1

正如标题所暗示的:最近,我对 Laravel 从 9 升级到 10 以及 PHPUnit 10。升级后,所有测试用例都失败了。

PHP 致命错误:声明 Illuminate\Database\PDO\Concerns\ConnectsToDatabase::connect(数组 $params、$username = null、$password = null、数组 $driverOptions = []) 必须与 Doctrine\DBAL\Driver::connect(array $params): Doctrine\DBAL\Driver\Connection 在 /vendor/laravel/framework/src/Illuminate/Database/PDO/Concerns/ConnectsToDatabase.php 22号线

尝试降级到以前的版本,所有测试用例都按预期工作。不确定新版本中是否有任何弃用

{
"name": "laravel/laravel",
"type": "project",
"description": "The Laravel Framework.",
"keywords": [
    "framework",
    "laravel"
],
"license": "MIT",
"require": {
    "php": "^8.2",
    "ext-gnupg": "*",
    "awobaz/compoships": "^2.0",
    "doctrine/dbal": "^3.0",
    "elasticsearch/elasticsearch": "^7.16",
    "guzzlehttp/guzzle": "7.7",
    "kevinrob/guzzle-cache-middleware": "^4.1",
    "laminas/laminas-stdlib": "^3.3",
    "laravel/framework": "^10.0",
    "laravel/horizon": "^5.19",
    "laravel/sanctum": "^3.2",
    "laravel/tinker": "^2.8",
    "launchdarkly/server-sdk": "^5.1",
    "league/flysystem-aws-s3-v3": "^3.15",
    "league/flysystem-sftp-v3": "^3.15",
    "mnapoli/dbal-schema": "^1.3",
    "ratchet/pawl": "^0.4.1",
    "staudenmeir/eloquent-has-many-deep": "^1.18",
    "textalk/websocket": "^1.6"
},
"require-dev": {
    "barryvdh/laravel-debugbar": "^3.5",
    "fakerphp/faker": "^1.9.1",
    "laravel/pint": "0.1.5",
    "laravel/telescope": "^4.4",
    "mockery/mockery": "^1.3.1",
    "nunomaduro/collision": "^6.0",
    "phpunit/phpunit": "^10.0",
    "spatie/laravel-ignition": "^2.0",
    "orchestra/testbench-core":"^6.0"
},
"config": {
    "optimize-autoloader": true,
    "preferred-install": "dist",
    "sort-packages": true
},
"extra": {
    "laravel": {
        "dont-discover": [
            "laravel/telescope"
        ]
    }
},
"autoload": {
    "psr-4": {
        "App\\": "app/",
        "Database\\Factories\\": "database/factories/",
        "Database\\Seeders\\": "database/seeders/"
    }
},
"autoload-dev": {
    "psr-4": {
        "Tests\\": "tests/"
    }
},
"minimum-stability": "dev",
"prefer-stable": true,
"scripts": {
    "post-autoload-dump": [
        "Illuminate\\Foundation\\ComposerScripts::postAutoloadDump",
        "@php artisan package:discover --ansi"
    ],
    "post-root-package-install": [
        "@php -r \"file_exists('.env') || copy('.env.example', '.env');\""
    ],
    "post-create-project-cmd": [
        "@php artisan key:generate --ansi"
    ]
}
}
php laravel phpunit
1个回答
0
投票

使用以下命令运行数据库迁移时遇到此问题:

  • PHP 8.1.29
  • laravel/framework
    ^9.0
  • doctrine/dbal
    4.2.1

由于与

doctrine/dbal
 冲突,我无法降级/升级我的 
carbon-doctrine-types
版本(来自
laravel/framework
需要
nesbot/carbon
需要
carbonphp/carbon-doctrine-types
)。

显然,

::connect
方法签名从 Laravel 8 更改为 Laravel 9,我认为这是导致错误的原因:

  • Laravel 9 API
    connect(array $params, string|null $username = null, string|null $password = null, array $driverOptions = [])
  • Laravel 8 API
    connect(array $params)

完成

composer.json

{
    "name": "laravel/laravel",
    "description": "The Laravel Framework.",
    "keywords": ["framework", "laravel"],
    "license": "MIT",
    "type": "project",
    "require": {
        "24slides/laravel-saml2": "^2.0",
        "barryvdh/laravel-dompdf": "^3.0.0",
        "doctrine/dbal": "4.2.1",
        "fideloper/proxy": "^4.0",
        "laravel/framework": "^9.0",
        "laravel/helpers": "^1.6",
        "laravel/tinker": "^2.0",
        "laravel/ui": "^3.0"
    },
    "require-dev": {
        "filp/whoops": "~2.0",
        "fzaninotto/faker": "~1.4",
        "mockery/mockery": "~1.0",
        "phpunit/phpunit": "^9.0",
        "symfony/thanks": "^1.0"
    },
    "autoload": {
        "classmap": [
            "database/seeders",
            "database/factories"
        ],
        "psr-4": {
            "App\\": "app/",
            "OneLogin\\Saml2\\": "repositories/onelogin/php-saml/src/Saml2/"
        }
    },
    "autoload-dev": {
        "psr-4": {
            "Tests\\": "tests/"
        }
    },
    "extra": {
        "laravel": {
            "dont-discover": [
            ]
        }
    },
    "scripts": {
        "post-root-package-install": [
            "@php -r \"file_exists('.env') || copy('.env.example', '.env');\""
        ],
        "post-create-project-cmd": [
            "@php artisan key:generate"
        ],
        "post-autoload-dump": [
            "Illuminate\\Foundation\\ComposerScripts::postAutoloadDump",
            "@php artisan package:discover"
        ]
    },
    "config": {
        "preferred-install": "dist",
        "sort-packages": true,
        "optimize-autoloader": true,
        "allow-plugins": {
            "kylekatarnls/update-helper": true,
            "symfony/thanks": true
        }
    }
}

运行时完全出错

php artisan migrate
:

   INFO  Running migrations.  

  2024_07_18_110456_delete_some_column PHP Fatal error:  Declaration of Illuminate\Database\PDO\Concerns\ConnectsToDatabase::connect(array $params, $username = null, $password = null, array $driverOptions = []) must be compatible with Doctrine\DBAL\Driver::connect(array $params): Doctrine\DBAL\Driver\Connection in C:\Users\g64882.ZEPRODBUR\Desktop\ykq\vendor\laravel\framework\src\Illuminate\Database\PDO\Concerns\ConnectsToDatabase.php on line 22
[2024-11-14 10:10:54] ${ENVIRONMENT}.ERROR: Declaration of Illuminate\Database\PDO\Concerns\ConnectsToDatabase::connect(array $params, $username = null, $password = null, array $driverOptions = []) must be compatible with 
Doctrine\DBAL\Driver::connect(array $params): Doctrine\DBAL\Driver\Connection {"exception":"[object] (Symfony\\Component\\ErrorHandler\\Error\\FatalError(code: 0): Declaration of Illuminate\\Database\\PDO\\Concerns\\ConnectsToDatabase::connect(array $params, $username = null, $password = null, array $driverOptions = []) must be compatible with Doctrine\\DBAL\\Driver::connect(array $params): Doctrine\\DBAL\\Driver\\Connection at C:\\Users\\g64882.ZEPRODBUR\\Desktop\\ykq\\vendor\\laravel\\framework\\src\\Illuminate\\Database\\PDO\\Concerns\\ConnectsToDatabase.php:22)
[stacktrace]
#0 {main}
"} 

In ConnectsToDatabase.php line 22:

  Declaration of Illuminate\Database\PDO\Concerns\ConnectsToDatabase::connect(array $params, $username = nul  
  l, $password = null, array $driverOptions = []) must be compatible with Doctrine\DBAL\Driver::connect(arra  
  y $params): Doctrine\DBAL\Driver\Connection

我降级到 Laravel 8,但仍然有错误(而且现在更奇怪的是,具有相同签名的 2 个方法似乎不兼容?)

完成

composer.json

{
    "name": "laravel/laravel",
    "description": "The Laravel Framework.",
    "keywords": ["framework", "laravel"],
    "license": "MIT",
    "type": "project",
    "require": {
        "24slides/laravel-saml2": "^2.0",
        "barryvdh/laravel-dompdf": "^2.2.0",
        "doctrine/dbal": "4.2.1",
        "fideloper/proxy": "^4.0",
        "laravel/framework": "^8.0",
        "laravel/helpers": "^1.6",
        "laravel/tinker": "^2.0",
        "laravel/ui": "^3.0"
    },
    "require-dev": {
        "filp/whoops": "~2.0",
        "fzaninotto/faker": "~1.4",
        "mockery/mockery": "~1.0",
        "phpunit/phpunit": "^9.0",
        "symfony/thanks": "^1.0"
    },
    "autoload": {
        "classmap": [
            "database/seeders",
            "database/factories"
        ],
        "psr-4": {
            "App\\": "app/",
            "OneLogin\\Saml2\\": "repositories/onelogin/php-saml/src/Saml2/"
        }
    },
    "autoload-dev": {
        "psr-4": {
            "Tests\\": "tests/"
        }
    },
    "extra": {
        "laravel": {
            "dont-discover": [
            ]
        }
    },
    "scripts": {
        "post-root-package-install": [
            "@php -r \"file_exists('.env') || copy('.env.example', '.env');\""
        ],
        "post-create-project-cmd": [
            "@php artisan key:generate"
        ],
        "post-autoload-dump": [
            "Illuminate\\Foundation\\ComposerScripts::postAutoloadDump",
            "@php artisan package:discover"
        ]
    },
    "config": {
        "preferred-install": "dist",
        "sort-packages": true,
        "optimize-autoloader": true,
        "allow-plugins": {
            "kylekatarnls/update-helper": true,
            "symfony/thanks": true
        }
    }
}

运行时完全出错

php artisan migrate
:

Migrating: 2024_07_18_110456_delete_some_column
PHP Fatal error:  Declaration of Illuminate\Database\PDO\Concerns\ConnectsToDatabase::connect(array $params) must be compatible with Doctrine\DBAL\Driver::connect(array $params): Doctrine\DBAL\Driver\Connection in C:\Users\g64882.ZEPRODBUR\Desktop\ykq\vendor\laravel\framework\src\Illuminate\Database\PDO\Concerns\ConnectsToDatabase.php on line 19
[2024-11-14 10:28:57] ${ENVIRONMENT}.ERROR: Declaration of Illuminate\Database\PDO\Concerns\ConnectsToDatabase::connect(array $params) must be compatible with Doctrine\DBAL\Driver::connect(array $params): Doctrine\DBAL\Driver\Connection {"exception":"[object] (Symfony\\Component\\ErrorHandler\\Error\\FatalError(code: 0): Declaration of Illuminate\\Database\\PDO\\Concerns\\ConnectsToDatabase::connect(array $params) must be compatible with Doctrine\\DBAL\\Driver::connect(array $params): Doctrine\\DBAL\\Driver\\Connection at C:\\Users\\g64882.ZEPRODBUR\\Desktop\\ykq\\vendor\\laravel\\framework\\src\\Illuminate\\Database\\PDO\\Concerns\\ConnectsToDatabase.php:19)
[stacktrace]
#0 {main}
"} 

In ConnectsToDatabase.php line 19:

  Declaration of Illuminate\Database\PDO\Concerns\ConnectsToDatabase::connect(array $params) must be compati  
  ble with Doctrine\DBAL\Driver::connect(array $params): Doctrine\DBAL\Driver\Connection
© www.soinside.com 2019 - 2024. All rights reserved.